Пример #1
0
 public function RunRowFilter(&$row, &$filteropts, &$fetchnext)
 {
     switch ($filteropts["mode"]) {
         case "SHOW DATABASES":
             if ($row !== false) {
                 $row->name = $row->Database;
                 unset($row->Database);
             }
             break;
         case "SHOW TABLES":
             if ($row !== false) {
                 foreach ($row as $key => $val) {
                     if (substr($key, 0, 10) == "Tables_in_") {
                         $row->name = $val;
                         unset($row->{$key});
                     }
                 }
             }
             break;
         case "SHOW CREATE DATABASE":
             if ($row !== false) {
                 $opts = array($row->Database);
                 $str = $row->{"Create Database"};
                 $pos = strpos($str, "/*!40100");
                 if ($pos !== false) {
                     $pos2 = strpos($str, "*/", $pos);
                     if ($pos2 !== false) {
                         $str = " " . trim(substr($str, $pos + 8, $pos2 - $pos - 8)) . " ";
                         $pos = strpos($str, " CHARACTER SET ");
                         if ($pos !== false) {
                             $pos += 15;
                             $pos2 = strpos($str, " ", $pos);
                             if ($pos2 !== false) {
                                 $opts["CHARACTER SET"] = substr($str, $pos, $pos2 - $pos);
                             }
                         }
                         $pos = strpos($str, " COLLATE ");
                         if ($pos !== false) {
                             $pos += 9;
                             $pos2 = strpos($str, " ", $pos);
                             if ($pos2 !== false) {
                                 $opts["COLLATE"] = substr($str, $pos, $pos2 - $pos);
                             }
                         }
                     }
                 }
                 $row->cmd = "CREATE DATABASE";
                 $row->opts = $opts;
             }
             break;
         case "SHOW CREATE TABLE":
             if ($row !== false) {
                 $opts = array($row->Table, array(), array());
                 $str = $row->{"Create Table"};
                 if (strtoupper(substr($str, 0, 23)) == "CREATE TEMPORARY TABLE ") {
                     $opts["TEMPORARY"] = true;
                 }
                 $pos = stripos($str, " TABLE ");
                 if ($pos !== false) {
                     $str = substr($str, $pos + 7);
                     $ident = true;
                     $id = $this->ExtractIdentifier($str, $ident);
                     $str = trim($str);
                     if ($str[0] == "(") {
                         $str = trim(substr($str, 1));
                         // Process columns and keys.
                         $colextras = array("NOT NULL", "NULL", "DEFAULT", "AUTO_INCREMENT", "UNIQUE KEY", "UNIQUE", "PRIMARY KEY", "PRIMARY", "COMMENT", "REFERENCES");
                         $keytypes = array("CONSTRAINT" => true, "INDEX" => true, "KEY" => true, "FULLTEXT" => true, "SPATIAL" => true, "PRIMARY" => true, "UNIQUE" => true, "FOREIGN" => true, "CHECK" => true);
                         $keyextras = array("PRIMARY KEY", "INDEX", "KEY", "UNIQUE INDEX", "UNIQUE KEY", "UNIQUE", "FULLTEXT INDEX", "FULLTEXT KEY", "FULLTEXT", "SPATIAL INDEX", "SPATIAL KEY", "SPATIAL", "FOREIGN KEY", "CHECK");
                         while ($str != "" && $str[0] != ")") {
                             $id = $this->ExtractIdentifier($str, $ident);
                             if ($ident || !isset($keytypes[strtoupper($id)])) {
                                 // Column.  Extract data type and options/values.
                                 $pos = strpos($str, "(");
                                 $pos2 = strpos($str, " ");
                                 if ($pos === false) {
                                     $pos = strlen($str);
                                 }
                                 if ($pos2 === false) {
                                     $pos2 = strlen($str);
                                 }
                                 if ($pos < $pos2) {
                                     $type = substr($str, 0, $pos);
                                     $str = trim(substr($str, $pos + 1));
                                     $typeopts = array();
                                     while ($str != "" && $str[0] != ")") {
                                         $typeopts[] = $this->ExtractAndUnescapeValue($str);
                                         if ($str != "" && $str[0] == ",") {
                                             $str = trim(substr($str, 1));
                                         }
                                     }
                                     $str = trim(substr($str, 1));
                                 } else {
                                     $type = substr($str, 0, $pos2);
                                     $str = trim(substr($str, $pos2 + 1));
                                     $typeopts = array();
                                 }
                                 // Process data type.  Stop processing on an unknown column type.
                                 $extras = array();
                                 switch (strtoupper($type)) {
                                     case "BIT":
                                         $opts2 = array("INTEGER");
                                         if (!count($typeopts) || $typeopts[0] <= 8) {
                                             $opts2[] = 1;
                                         } else {
                                             if ($typeopts[0] <= 16) {
                                                 $opts2[] = 2;
                                             } else {
                                                 if ($typeopts[0] <= 24) {
                                                     $opts2[] = 3;
                                                 } else {
                                                     if ($typeopts[0] <= 32) {
                                                         $opts2[] = 4;
                                                     } else {
                                                         $opts2[] = 8;
                                                     }
                                                 }
                                             }
                                         }
                                         $opts2["UNSIGNED"] = true;
                                         break;
                                     case "TINYINT":
                                         $opts2 = array("INTEGER", 1);
                                         $extras = array("UNSIGNED" => "keep", "ZEROFILL" => "ignore");
                                         break;
                                     case "SMALLINT":
                                         $opts2 = array("INTEGER", 2);
                                         $extras = array("UNSIGNED" => "keep", "ZEROFILL" => "ignore");
                                         break;
                                     case "MEDIUMINT":
                                         $opts2 = array("INTEGER", 3);
                                         $extras = array("UNSIGNED" => "keep", "ZEROFILL" => "ignore");
                                         break;
                                     case "INT":
                                     case "INTEGER":
                                         $opts2 = array("INTEGER", 4);
                                         $extras = array("UNSIGNED" => "keep", "ZEROFILL" => "ignore");
                                         break;
                                     case "BIGINT":
                                         $opts2 = array("INTEGER", 8);
                                         $extras = array("UNSIGNED" => "keep", "ZEROFILL" => "ignore");
                                         break;
                                     case "DOUBLE":
                                     case "REAL":
                                         $opts2 = array("FLOAT", 8);
                                         $extras = array("UNSIGNED" => "ignore", "ZEROFILL" => "ignore");
                                         break;
                                     case "FLOAT":
                                         $opts2 = array("FLOAT", 4);
                                         $extras = array("UNSIGNED" => "ignore", "ZEROFILL" => "ignore");
                                         break;
                                     case "DECIMAL":
                                     case "NUMERIC":
                                         $opts2[] = array("DECIMAL", count($typeopts) ? $typeopts[0] : 10, count($typeopts) > 1 ? $typeopts[1] : 0);
                                         $extras = array("UNSIGNED" => "ignore", "ZEROFILL" => "ignore");
                                         break;
                                     case "DATE":
                                         $opts2 = array("DATE");
                                         break;
                                     case "TIME":
                                         $opts2 = array("TIME");
                                         break;
                                     case "DATETIME":
                                     case "TIMESTAMP":
                                         $opts2 = array("DATETIME");
                                         break;
                                     case "YEAR":
                                         $opts2 = array("INTEGER", 4);
                                         break;
                                     case "CHAR":
                                         $opts2 = array("STRING", 1, count($typeopts) ? $typeopts[0] : 255, "FIXED" => true);
                                         $extras = array("CHARACTER SET" => "ignore_with_opt", "COLLATE" => "ignore_with_opt");
                                         break;
                                     case "VARCHAR":
                                         $opts2 = array("STRING", $typeopts[0] > 255 ? 2 : 1, $typeopts[0]);
                                         $extras = array("CHARACTER SET" => "ignore_with_opt", "COLLATE" => "ignore_with_opt");
                                         break;
                                     case "TINYTEXT":
                                         $opts2 = array("STRING", 1, 255);
                                         $extras = array("BINARY" => "ignore", "CHARACTER SET" => "ignore_with_opt", "COLLATE" => "ignore_with_opt");
                                         break;
                                     case "TEXT":
                                         $opts2 = array("STRING", 2);
                                         $extras = array("BINARY" => "ignore", "CHARACTER SET" => "ignore_with_opt", "COLLATE" => "ignore_with_opt");
                                         break;
                                     case "MEDIUMTEXT":
                                         $opts2 = array("STRING", 3);
                                         $extras = array("BINARY" => "ignore", "CHARACTER SET" => "ignore_with_opt", "COLLATE" => "ignore_with_opt");
                                         break;
                                     case "LONGTEXT":
                                         $opts2 = array("STRING", 4);
                                         $extras = array("BINARY" => "ignore", "CHARACTER SET" => "ignore_with_opt", "COLLATE" => "ignore_with_opt");
                                         break;
                                     case "ENUM":
                                         $opts2 = array("STRING", 1, 255);
                                         $extras = array("CHARACTER SET" => "ignore_with_opt", "COLLATE" => "ignore_with_opt");
                                         break;
                                     case "SET":
                                         $opts2 = array("STRING", 2);
                                         $extras = array("CHARACTER SET" => "ignore_with_opt", "COLLATE" => "ignore_with_opt");
                                         break;
                                     case "BINARY":
                                         $opts2 = array("BINARY", 1, count($typeopts) ? $typeopts[0] : 255, "FIXED" => true);
                                         break;
                                     case "VARBINARY":
                                         $opts2 = array("BINARY", $typeopts[0] > 255 ? 2 : 1, $typeopts[0]);
                                         break;
                                     case "TINYBLOB":
                                         $opts2 = array("BINARY", 1, 255);
                                         break;
                                     case "BLOB":
                                         $opts2 = array("BINARY", 2);
                                         break;
                                     case "MEDIUMBLOB":
                                         $opts2 = array("BINARY", 3);
                                         break;
                                     case "LONGBLOB":
                                         $opts2 = array("BINARY", 4);
                                         break;
                                     default:
                                         return;
                                 }
                                 do {
                                     $found = false;
                                     foreach ($extras as $extra => $rule) {
                                         if (strtoupper(substr($str, 0, strlen($extra))) == $extra) {
                                             $str = trim(substr($str, strlen($extra)));
                                             if ($rule == "keep") {
                                                 $opts2[$extra] = true;
                                             } else {
                                                 if ($rule == "ignore_with_opt") {
                                                     $this->ExtractIdentifier($str, $ident);
                                                 }
                                             }
                                             $found = true;
                                         }
                                     }
                                 } while ($found);
                                 while ($str != "" && $str[0] != "," && $str[0] != ")") {
                                     foreach ($colextras as $extra) {
                                         if (strtoupper(substr($str, 0, strlen($extra))) == $extra) {
                                             $str = trim(substr($str, strlen($extra)));
                                             switch ($extra) {
                                                 case "NOT NULL":
                                                     $opts2["NOT NULL"] = true;
                                                     break;
                                                 case "NULL":
                                                     break;
                                                 case "DEFAULT":
                                                     $opts2["DEFAULT"] = $this->ExtractAndUnescapeValue($str);
                                                     break;
                                                 case "AUTO_INCREMENT":
                                                     $opts2["AUTO INCREMENT"] = true;
                                                     break;
                                                 case "UNIQUE KEY":
                                                 case "UNIQUE":
                                                     $opts2["UNIQUE KEY"] = true;
                                                     break;
                                                 case "PRIMARY KEY":
                                                 case "PRIMARY":
                                                     $opts2["PRIMARY KEY"] = true;
                                                     break;
                                                 case "COMMENT":
                                                     $opts2["COMMENT"] = $this->ExtractAndUnescapeValue($str);
                                                     break;
                                                 case "REFERENCES":
                                                     $opts2["REFERENCES"] = $this->ExtractReferencesInfo($str);
                                                     break;
                                             }
                                         }
                                     }
                                 }
                                 if (isset($filteropts["hints"]) && isset($filteropts["hints"][$id])) {
                                     $opts2 = $filteropts["hints"][$id];
                                 }
                                 $opts[1][$id] = $opts2;
                             } else {
                                 // Key or constraint.
                                 $opts2 = array();
                                 if (strtoupper($id) == "CONSTRAINT") {
                                     $id = $this->ExtractIdentifier($str, $ident);
                                     $id2 = strtoupper($id);
                                     if ($ident || !isset($keytypes[strtoupper($id)])) {
                                         $opts2["CONSTRAINT"] = $id;
                                         $id = $this->ExtractIdentifier($str, $ident);
                                     }
                                 }
                                 $str = $id . " " . $str;
                                 foreach ($keyextras as $extra) {
                                     if (strtoupper(substr($str, 0, strlen($extra))) == $extra) {
                                         $str = trim(substr($str, strlen($extra)));
                                         switch ($extra) {
                                             case "PRIMARY KEY":
                                                 $opts2[] = "PRIMARY";
                                                 while ($str != "" && $str[0] != "(") {
                                                     $id = $this->ExtractIdentifier($str, $ident);
                                                     if (!$ident && strtoupper($id) == "USING") {
                                                         $opts2["USING"] = $this->ExtractIdentifier($str, $ident);
                                                     }
                                                 }
                                                 $opts2[] = $this->ExtractMultipleIdentifiers($str);
                                                 break;
                                             case "INDEX":
                                             case "KEY":
                                                 $opts2[] = "KEY";
                                                 while ($str != "" && $str[0] != "(") {
                                                     $id = $this->ExtractIdentifier($str, $ident);
                                                     if (!$ident && strtoupper($id) == "USING") {
                                                         $opts2["USING"] = $this->ExtractIdentifier($str, $ident);
                                                     } else {
                                                         $opts2["NAME"] = $id;
                                                     }
                                                 }
                                                 $opts2[] = $this->ExtractMultipleIdentifiers($str);
                                                 break;
                                             case "UNIQUE INDEX":
                                             case "UNIQUE KEY":
                                             case "UNIQUE":
                                                 $opts2[] = "UNIQUE";
                                                 while ($str != "" && $str[0] != "(") {
                                                     $id = $this->ExtractIdentifier($str, $ident);
                                                     if (!$ident && strtoupper($id) == "USING") {
                                                         $opts2["USING"] = $this->ExtractIdentifier($str, $ident);
                                                     } else {
                                                         $opts2["NAME"] = $id;
                                                     }
                                                 }
                                                 $opts2[] = $this->ExtractMultipleIdentifiers($str);
                                                 break;
                                             case "FULLTEXT INDEX":
                                             case "FULLTEXT KEY":
                                             case "FULLTEXT":
                                                 $opts2[] = "FULLTEXT";
                                                 while ($str != "" && $str[0] != "(") {
                                                     $opts2["NAME"] = $this->ExtractIdentifier($str, $ident);
                                                 }
                                                 $opts2[] = $this->ExtractMultipleIdentifiers($str);
                                                 break;
                                             case "SPATIAL INDEX":
                                             case "SPATIAL KEY":
                                             case "SPATIAL":
                                                 // GIS is not portable.
                                                 while ($str != "" && $str[0] != "(") {
                                                     $this->ExtractIdentifier($str, $ident);
                                                 }
                                                 $this->ExtractMultipleIdentifiers($str);
                                                 break;
                                             case "FOREIGN KEY":
                                                 $opts2[] = "FOREIGN";
                                                 while ($str != "" && $str[0] != "(") {
                                                     $opts2["NAME"] = $this->ExtractIdentifier($str, $ident);
                                                 }
                                                 $opts2[] = $this->ExtractMultipleIdentifiers($str);
                                                 $opts2[] = $this->ExtractReferencesInfo($str);
                                                 break;
                                             case "CHECK":
                                                 $pos = strpos($str, ")");
                                                 $str = substr($str, $pos + 1);
                                                 break;
                                         }
                                     }
                                 }
                                 while ($str != "" && $str[0] != "," && $str[0] != ")") {
                                     $id = $this->ExtractIdentifier($str, $ident);
                                     if (!$ident && strtoupper($id) == "USING") {
                                         $opts2["USING"] = $this->ExtractIdentifier($str, $ident);
                                     }
                                 }
                                 if (isset($opts2[0])) {
                                     $opts[2][] = $opts2;
                                 }
                             }
                             if ($str != "" && $str[0] == ",") {
                                 $str = trim(substr($str, 1));
                             }
                             $str = trim($str);
                         }
                         // Process the last line.
                         $str = trim(substr($str, 1));
                         $extras = array("ENGINE", "TYPE", "AUTO_INCREMENT", "AVG_ROW_LENGTH", "DEFAULT CHARACTER SET", "CHARACTER SET", "DEFAULT CHARSET", "CHARSET", "CHECKSUM", "DEFAULT COLLATE", "COLLATE", "COMMENT", "CONNECTION", "DATA DIRECTORY", "DELAY_KEY_WRITE", "INDEX DIRECTORY", "INSERT_METHOD", "MAX_ROWS", "MIN_ROWS", "PACK_KEYS", "PASSWORD", "ROW_FORMAT");
                         do {
                             $found = false;
                             foreach ($extras as $extra) {
                                 if (strtoupper(substr($str, 0, strlen($extra))) == $extra) {
                                     $str = trim(substr($str, strlen($extra)));
                                     if ($str[0] == "=") {
                                         $str = trim(substr($str, 1));
                                     }
                                     switch ($extra) {
                                         case "ENGINE":
                                         case "TYPE":
                                             $opts["ENGINE"] = $this->ExtractAndUnescapeValue($str);
                                             break;
                                         case "DEFAULT CHARACTER SET":
                                         case "CHARACTER SET":
                                         case "DEFAULT CHARSET":
                                         case "CHARSET":
                                             $opts["CHARACTER SET"] = $this->ExtractAndUnescapeValue($str);
                                             break;
                                         case "DEFAULT COLLATE":
                                         case "COLLATE":
                                             $opts["COLLATE"] = $this->ExtractAndUnescapeValue($str);
                                             break;
                                         case "AUTO_INCREMENT":
                                         case "AVG_ROW_LENGTH":
                                         case "CHECKSUM":
                                         case "COMMENT":
                                         case "CONNECTION":
                                         case "DATA DIRECTORY":
                                         case "DELAY_KEY_WRITE":
                                         case "INDEX DIRECTORY":
                                         case "INSERT_METHOD":
                                         case "MAX_ROWS":
                                         case "MIN_ROWS":
                                         case "PACK_KEYS":
                                         case "PASSWORD":
                                         case "ROW_FORMAT":
                                             $this->ExtractAndUnescapeValue($str);
                                             break;
                                     }
                                     $found = true;
                                 }
                             }
                         } while ($found);
                     }
                 }
                 $row->cmd = "CREATE TABLE";
                 $row->opts = $opts;
             }
             break;
     }
     parent::RunRowFilter($row, $filteropts, $fetchnext);
 }
Пример #2
0
 public function RunRowFilter(&$row, &$filteropts, &$fetchnext)
 {
     switch ($filteropts["mode"]) {
         case "SHOW DATABASES":
             if ($row !== false) {
                 $name = $row->name;
                 $pos = strpos($name, "__");
                 if ($pos === false) {
                     $name = "";
                 } else {
                     $name = substr($name, 0, $pos);
                 }
                 if (isset($filteropts["names"][$name])) {
                     $fetchnext = true;
                 } else {
                     $filteropts["names"][$name] = true;
                     $row->name = $name;
                 }
             }
             break;
         case "SHOW TABLES":
             if ($row !== false) {
                 $dbprefix = isset($filteropts["queryinfo"]["FROM"]) ? $this->GetDBPrefix($filteropts["queryinfo"]["FROM"]) : $this->dbprefix;
                 $name = $row->name;
                 if ($dbprefix == "" && strpos($name, "__") !== false) {
                     $fetchnext = true;
                 } else {
                     if ($dbprefix != "" && strtolower(substr($name, 0, strlen($dbprefix))) !== strtolower($dbprefix)) {
                         $fetchnext = true;
                     } else {
                         $row->name = substr($name, strlen($dbprefix));
                         $row->tbl_name = $row->name;
                     }
                 }
             }
             break;
         case "SHOW CREATE DATABASE":
             if ($row !== false) {
                 $name = $row->name;
                 $pos = strpos($name, "__");
                 if ($pos === false) {
                     $name = "";
                 } else {
                     $name = substr($name, 0, $pos);
                 }
                 if ($filteropts["output"] || $name == "" || $name !== $filteropts["queryinfo"][0]) {
                     $fetchnext = true;
                 } else {
                     $row->name = $name;
                     $row->cmd = "CREATE DATABASE";
                     $row->opts = array($name);
                     $filteropts["output"] = true;
                 }
             }
             break;
         case "SHOW CREATE TABLE":
             if ($row !== false) {
                 if ($filteropts["output"]) {
                     $fetchnext = true;
                 } else {
                     $dbprefix = $row->tbl_type == "temp" ? "temp." : "";
                     // Process columns according to:  http://sqlite.org/datatype3.html
                     $cols = array();
                     $result2 = $this->Query("PRAGMA", $dbprefix . "table_info(" . $this->QuoteIdentifier($this->dbprefix . $filteropts["queryinfo"][0]) . ")");
                     while ($row2 = $result2->NextRow()) {
                         if (isset($filteropts["hints"]) && isset($filteropts["hints"][$row2->name])) {
                             $col = $filteropts["hints"][$row2->name];
                         } else {
                             if (stripos($row2->type, "INT") !== false) {
                                 $col = array("INTEGER", 8);
                             } else {
                                 if (stripos($row2->type, "CHAR") !== false || stripos($row2->type, "CLOB") !== false || stripos($row2->type, "TEXT") !== false) {
                                     $col = array("STRING", 4);
                                     $pos = strpos($row2->type, "(");
                                     if ($pos !== false) {
                                         $pos2 = strpos($row2->type, ")", $pos);
                                         if ($pos2 !== false) {
                                             $num = (int) substr($row2->type, $pos + 1, $pos2 - $pos - 1);
                                             if ($num > 0 && $num < 256) {
                                                 $col = array("STRING", 1, $num);
                                             }
                                         }
                                     }
                                 } else {
                                     if (stripos($row2->type, "BLOB") !== false || $row2->type === "") {
                                         $col = array("BINARY", 4);
                                     } else {
                                         if (stripos($row2->type, "REAL") !== false || stripos($row2->type, "FLOA") !== false || stripos($row2->type, "DOUB") !== false) {
                                             $col = array("FLOAT", 8);
                                         } else {
                                             $col = array("NUMERIC");
                                             $pos = strpos($row2->type, "(");
                                             if ($pos !== false) {
                                                 $pos2 = strpos($row2->type, ")", $pos);
                                                 if ($pos2 !== false) {
                                                     $nums = explode(",", substr($row2->type, $pos + 1, $pos2 - $pos - 1));
                                                     $num = (int) trim($nums[0]);
                                                     if ($num > 0) {
                                                         $col[] = $num;
                                                     }
                                                     if (count($nums) > 1) {
                                                         $num = (int) trim($nums[1]);
                                                         if ($num > 0) {
                                                             $col[] = $num;
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                             if ($row2->notnull > 0) {
                                 $col["NOT NULL"] = true;
                             }
                             if (isset($row2->dflt_value)) {
                                 $col["DEFAULT"] = $row2->dflt_value;
                             }
                             if ($row2->pk > 0) {
                                 $col["PRIMARY KEY"] = true;
                                 if ($col[0] == "INTEGER") {
                                     $col["AUTO INCREMENT"] = true;
                                 }
                             }
                         }
                         $cols[$row2->name] = $col;
                     }
                     // Process indexes.
                     $keys = array();
                     $result2 = $this->Query("PRAGMA", $dbprefix . "index_list(" . $this->QuoteIdentifier($this->dbprefix . $filteropts["queryinfo"][0]) . ")");
                     while ($row2 = $result2->NextRow()) {
                         $cols2 = array();
                         $result3 = $this->Query("PRAGMA", $dbprefix . "index_info(" . $this->QuoteIdentifier($row2->name) . ")");
                         while ($row3 = $result3->NextRow()) {
                             $cols2[] = $row3->name;
                         }
                         if (substr($row2->name, 0, strlen($this->dbprefix . $filteropts["queryinfo"][0]) + 2) == $this->dbprefix . $filteropts["queryinfo"][0] . "__") {
                             $row2->name = substr($row2->name, strlen($this->dbprefix . $filteropts["queryinfo"][0]) + 2);
                         }
                         $keys[] = array($row2->unique > 0 ? "UNIQUE" : "KEY", $cols2, "NAME" => $row2->name);
                     }
                     // Process foreign keys?  It would be nice to see some output of foreign_key_list().
                     $row->cmd = "CREATE TABLE";
                     $row->opts = array($filteropts["queryinfo"][0], $cols);
                     if (count($keys)) {
                         $row->opts[] = $keys;
                     }
                     if ($row->tbl_type == "temp") {
                         $row->opts["TEMPORARY"] = true;
                     }
                     $row->opts["CHARACTER SET"] = "utf8";
                     $filteropts["output"] = true;
                 }
             }
             break;
     }
     if (!$fetchnext) {
         parent::RunRowFilter($row, $filteropts, $fetchnext);
     }
 }
Пример #3
0
 public function RunRowFilter(&$row, &$filteropts, &$fetchnext)
 {
     switch ($filteropts["mode"]) {
         case "INSERT":
             if ($row !== false) {
                 $key = $filteropts["queryinfo"]["AUTO INCREMENT"];
                 $this->lastid = $row->{$key};
             }
             break;
     }
     if (!$fetchnext) {
         parent::RunRowFilter($row, $filteropts, $fetchnext);
     }
 }
Пример #4
0
 public function RunRowFilter(&$row, &$filteropts, &$fetchnext)
 {
     switch ($filteropts["mode"]) {
         case "INSERT":
             // Use the private function provided above to get the Last Inserted ID
             $this->lastid = $this->GetOracleInsertID($filteropts["queryinfo"][0]);
             break;
     }
     if (!$fetchnext) {
         parent::RunRowFilter($row, $filteropts, $fetchnext);
     }
 }
Пример #5
0
 public function RunRowFilter(&$row, &$filteropts, &$fetchnext)
 {
     switch ($filteropts["mode"]) {
         case "INSERT":
             if ($row !== false) {
                 $key = $filteropts["queryinfo"]["AUTO INCREMENT"];
                 $this->lastid = $row->{$key};
             }
             break;
         case "SHOW CREATE DATABASE":
             if ($row !== false) {
                 $row->cmd = "CREATE DATABASE";
                 $row->opts = array($row->name);
             }
             break;
         case "SHOW CREATE TABLE":
             if ($row !== false) {
                 $cols = array();
                 $result2 = $this->Query("SELECT", array("*", "FROM" => "information_schema.columns", "WHERE" => "table_schema = ? AND table_name = ?", "ORDER BY" => "ordinal_position"), $row->table_schema, $row->table_name);
                 while ($row2 = $result2->NextRow()) {
                     if (isset($filteropts["hints"]) && isset($filteropts["hints"][$row2->column_name])) {
                         $col = $filteropts["hints"][$row2->column_name];
                     } else {
                         $row2->data_type = str_replace(array(" with timezone", "without timezone", "[]"), "", $row2->data_type);
                         switch ($row2->data_type) {
                             case "integer":
                                 $col = array("INTEGER", 4);
                                 break;
                             case "bigint":
                                 $col = array("INTEGER", 8);
                                 break;
                             case "smallint":
                                 $col = array("INTEGER", 2);
                                 break;
                             case "real":
                                 $col = array("FLOAT", 4);
                                 break;
                             case "double precision":
                                 $col = array("FLOAT", 8);
                                 break;
                             case "numeric":
                                 $col = array("DECIMAL", $row2->numeric_precision, $row2->numeric_scale);
                                 break;
                             case "\"char\"":
                                 $col = array("STRING", 1, $row2->character_maximum_length, "FIXED" => true);
                                 break;
                             case "character varying":
                                 $col = array("STRING", 1, $row2->character_maximum_length);
                                 break;
                             case "text":
                                 $col = array("STRING", 4);
                                 break;
                             case "bytea":
                                 $col = array("BINARY", 4);
                                 break;
                             case "date":
                                 $col = array("DATE");
                                 break;
                             case "time":
                                 $col = array("TIME");
                                 break;
                             case "timestamp":
                                 $col = array("DATETIME");
                                 break;
                             case "boolean":
                                 $col = array("BOOLEAN");
                                 break;
                             default:
                                 return;
                         }
                         if ($row2->is_nullable == "NO") {
                             $col["NOT NULL"] = true;
                         }
                         if (isset($row2->column_default)) {
                             if (strtolower(substr($row2->column_default, 0, 8)) == "nextval(" && strtolower(substr($row2->column_default, -11)) == "::regclass)") {
                                 $col["AUTO INCREMENT"] = true;
                             } else {
                                 $col["DEFAULT"] = $row2->column_default;
                             }
                         }
                     }
                     $cols[$row2->column_name] = $col;
                 }
                 // Process indexes.
                 $lastindex = 0;
                 $keys = array();
                 $result2 = $this->Query("SELECT", array("c.oid, c.relname, a.attname, a.attnum, i.indisprimary, i.indisunique", "FROM" => "pg_index AS i, pg_class AS c, pg_attribute AS a", "WHERE" => "i.indexrelid = c.oid AND i.indexrelid = a.attrelid AND i.indrelid = " . $this->Quote($this->QuoteIdentifier($row->table_schema) . "." . $this->QuoteIdentifier($row->table_name)) . "::regclass", "ORDER BY" => "c.oid, a.attnum"));
                 while ($row2 = $result2->NextRow()) {
                     if ($lastindex != $row2->oid) {
                         if ($lastindex > 0) {
                             $keys[] = $key;
                         }
                         // FULLTEXT index extraction is missing.  Feel free to submit a patch.
                         if ($row2->indisprimary) {
                             $type = "PRIMARY";
                         } else {
                             if ($row2->indisunique) {
                                 $type = "UNIQUE";
                             } else {
                                 $type = "KEY";
                             }
                         }
                         $key = array($type, array(), "NAME" => $row2->relname);
                         $lastindex = $row2->oid;
                     }
                     $key[1][] = $row2->attname;
                 }
                 if ($lastindex > 0) {
                     $keys[] = $key;
                 }
                 // Process foreign keys?  It would be nice to see some examples.
                 // Generate the final CREATE TABLE information.
                 $row->cmd = "CREATE TABLE";
                 $row->opts = array($row->table_name, $cols);
                 if (count($keys)) {
                     $row->opts[] = $keys;
                 }
                 if ($row->table_type == "LOCAL TEMPORARY") {
                     $row->opts["TEMPORARY"] = true;
                 }
             }
             break;
     }
     if (!$fetchnext) {
         parent::RunRowFilter($row, $filteropts, $fetchnext);
     }
 }
Пример #6
0
 public function RunRowFilter(&$row, &$filteropts, &$fetchnext)
 {
     switch ($filteropts["mode"]) {
         case "INSERT":
             // Use the private function provided above to get the Last Inserted ID
             $this->lastid = $this->GetOracleInsertID($filteropts["queryinfo"][0]);
             break;
         case "SHOW CREATE DATABASE":
             if ($row !== false) {
                 $row->cmd = "CREATE DATABASE";
                 $row->opts = array($row->name);
             }
             break;
         case "SHOW CREATE TABLE":
             /*
             TODO: Update the column types for Oracle
             if ($row !== false)
             {
             	$cols = array();
             	$result2 = $this->Query("SELECT", array(
             		"*",
             		"FROM" => "all_tab_columns",
             		"WHERE" => " table_name = ?",
             		"ORDER BY" => "column_id"
             	), $row->table_name);
             	while ($row2 = $result2->NextRow())
             	{
             		if (isset($filteropts["hints"]) && isset($filteropts["hints"][$row2->column_name]))  $col = $filteropts["hints"][$row2->column_name];
             		else
             		{
             			$row2->data_type = str_replace(array(" with timezone", "without timezone", "[]"), "", $row2->data_type);
             
             			switch (strtoupper($type))
             			{
             				case "BIT":
             				{
             					$opts2 = array("INTEGER");
             					if (!count($typeopts) || $typeopts[0] <= 8)  $opts2[] = 1;
             					else if ($typeopts[0] <= 16)  $opts2[] = 2;
             					else if ($typeopts[0] <= 24)  $opts2[] = 3;
             					else if ($typeopts[0] <= 32)  $opts2[] = 4;
             					else  $opts2[] = 8;
             
             					break;
             				}
             				case "TINYINT":  $opts2 = array("INTEGER", 1);  $extras = array("UNSIGNED" => "keep", "ZEROFILL" => "ignore");  break;
             				case "SMALLINT":  $opts2 = array("INTEGER", 2);  $extras = array("UNSIGNED" => "keep", "ZEROFILL" => "ignore");  break;
             				case "MEDIUMINT":  $opts2 = array("INTEGER", 3);  $extras = array("UNSIGNED" => "keep", "ZEROFILL" => "ignore");  break;
             				case "INT":  case "INTEGER":  $opts2 = array("INTEGER", 4);  $extras = array("UNSIGNED" => "keep", "ZEROFILL" => "ignore");  break;
             				case "BIGINT":  $opts2 = array("INTEGER", 8);  $extras = array("UNSIGNED" => "keep", "ZEROFILL" => "ignore");  break;
             
             				case "DOUBLE":  case "REAL":  $opts2 = array("FLOAT", 8);  $extras = array("UNSIGNED" => "ignore", "ZEROFILL" => "ignore");  break;
             				case "FLOAT":  $opts2 = array("FLOAT", 4);  $extras = array("UNSIGNED" => "ignore", "ZEROFILL" => "ignore");  break;
             				case "DECIMAL":  case "NUMERIC":  $opts2[] = array("DECIMAL", (count($typeopts) ? $typeopts[0] : 10), (count($typeopts) > 1 ? $typeopts[1] : 0));  $extras = array("UNSIGNED" => "ignore", "ZEROFILL" => "ignore");  break;
             
             				case "DATE":  $opts2 = array("DATE");  break;
             				case "TIME":  $opts2 = array("DATE");  break;
             				case "DATETIME":  case "TIMESTAMP":  $opts2 = array("DATETIME");  break;
             				case "YEAR":  $opts2 = array("INTEGER", 4);  break;
             
             				case "CHAR":  $opts2 = array("STRING", 1, (count($typeopts) ? $typeopts[0] : 255), "FIXED" => true);  $extras = array("CHARACTER SET" => "ignore_with_opt", "COLLATE" => "ignore_with_opt");  break;
             				case "VARCHAR":  $opts2 = array("STRING", ($typeopts[0] > 255 ? 2 : 1), $typeopts[0]);  $extras = array("CHARACTER SET" => "ignore_with_opt", "COLLATE" => "ignore_with_opt");  break;
             				case "TINYTEXT":  $opts2 = array("STRING", 1, 255);  $extras = array("BINARY" => "ignore", "CHARACTER SET" => "ignore_with_opt", "COLLATE" => "ignore_with_opt");  break;
             				case "TEXT":  $opts2 = array("STRING", 2);  $extras = array("BINARY" => "ignore", "CHARACTER SET" => "ignore_with_opt", "COLLATE" => "ignore_with_opt");  break;
             				case "MEDIUMTEXT":  $opts2 = array("STRING", 3);  $extras = array("BINARY" => "ignore", "CHARACTER SET" => "ignore_with_opt", "COLLATE" => "ignore_with_opt");  break;
             				case "LONGTEXT":  $opts2 = array("STRING", 4);  $extras = array("BINARY" => "ignore", "CHARACTER SET" => "ignore_with_opt", "COLLATE" => "ignore_with_opt");  break;
             				case "ENUM":  $opts2 = array("STRING", 1, 255);  $extras = array("CHARACTER SET" => "ignore_with_opt", "COLLATE" => "ignore_with_opt");  break;
             				case "SET":  $opts2 = array("STRING", 2);  $extras = array("CHARACTER SET" => "ignore_with_opt", "COLLATE" => "ignore_with_opt");  break;
             
             				case "BINARY":  $opts2 = array("BINARY", 1, (count($typeopts) ? $typeopts[0] : 255), "FIXED" => true);  break;
             				case "VARBINARY":  $opts2 = array("BINARY", ($typeopts[0] > 255 ? 2 : 1), $typeopts[0]);  break;
             				case "TINYBLOB":  $opts2 = array("BINARY", 1, 255);  break;
             				case "BLOB":  $opts2 = array("BINARY", 2);  break;
             				case "MEDIUMBLOB":  $opts2 = array("BINARY", 3);  break;
             				case "LONGBLOB":  $opts2 = array("BINARY", 4);  break;
             
             				default:  return;
             			}
             
             			if ($row2->is_nullable == "NO")  $col["NOT NULL"] = true;
             			if (isset($row2->column_default))
             			{
             				if (strtolower(substr($row2->column_default, 0, 8)) == "nextval(" && strtolower(substr($row2->column_default, -11)) == "::regclass)")  $col["AUTO INCREMENT"] = true;
             				else  $col["DEFAULT"] = $row2->column_default;
             			}
             		}
             
             		$cols[$row2->column_name] = $col;
             	}
             
             	// Process indexes.
             	$lastindex = 0;
             	$keys = array();
             	$result2 = $this->Query("SELECT", array(
             		"c.oid, c.relname, a.attname, a.attnum, i.indisprimary, i.indisunique",
             		"FROM" => "pg_index AS i, pg_class AS c, pg_attribute AS a",
             		"WHERE" => "i.indexrelid = c.oid AND i.indexrelid = a.attrelid AND i.indrelid = " . $this->Quote($this->QuoteIdentifier($row->table_schema) . "." . $this->QuoteIdentifier($row->table_name)) . "::regclass",
             		"ORDER BY" => "c.oid, a.attnum"
             	));
             	while ($row2 = $result2->NextRow())
             	{
             		if ($lastindex != $row2->oid)
             		{
             			if ($lastindex > 0)  $keys[] = $key;
             
             			// FULLTEXT index extraction is missing.  Feel free to submit a patch.
             			if ($row2->indisprimary)  $type = "PRIMARY";
             			else if ($row2->indisunique)  $type = "UNIQUE";
             			else  $type = "KEY";
             
             			$key = array($type, array(), "NAME" => $row2->relname);
             			$lastindex = $row2->oid;
             		}
             
             		$key[1][] = $row2->attname;
             	}
             	if ($lastindex > 0)  $keys[] = $key;
             
             	// Process foreign keys?  It would be nice to see some examples.
             
             	// Generate the final CREATE TABLE information.
             	$row->cmd = "CREATE TABLE";
             	$row->opts = array($row->table_name, $cols);
             	if (count($keys))  $row->opts[] = $keys;
             	if ($row->table_type == "LOCAL TEMPORARY")  $row->opts["TEMPORARY"] = true;
             }
             
             break;
             */
     }
     if (!$fetchnext) {
         parent::RunRowFilter($row, $filteropts, $fetchnext);
     }
 }