diff --git a/adminer/create.inc.php b/adminer/create.inc.php index 479e5b9b..e219c00e 100644 --- a/adminer/create.inc.php +++ b/adminer/create.inc.php @@ -151,7 +151,7 @@ foreach ($engines as $engine) {

: "> "(" . lang('engine') . ")") + $engines, $row["Engine"]) : ""); ?> - "(" . lang('collation') . ")") + $collations, $row["Collation"]) : ""); ?> + "(" . lang('collation') . ")") + $collations, $row["Collation"]) : ""); ?> diff --git a/adminer/drivers/mssql.inc.php b/adminer/drivers/mssql.inc.php index d14f5d37..78918532 100644 --- a/adminer/drivers/mssql.inc.php +++ b/adminer/drivers/mssql.inc.php @@ -92,7 +92,7 @@ if (isset($_GET["mssql"])) { function Min_Result($result) { $this->_result = $result; - $this->num_rows = sqlsrv_has_rows($result); //! sqlsrv_num_rows($result) + // $this->num_rows = sqlsrv_num_rows($result); // available only in scrollable results } function _convert($row) { diff --git a/adminer/drivers/mysql.inc.php b/adminer/drivers/mysql.inc.php index 1ca1cca3..037440f4 100644 --- a/adminer/drivers/mysql.inc.php +++ b/adminer/drivers/mysql.inc.php @@ -767,6 +767,19 @@ if (!defined("DRIVER")) { return queries("INSERT INTO " . table($table) . " (" . implode(", ", array_keys($set)) . ")\nVALUES (" . implode(", ", $set) . ")"); } + /** Insert or update data in the table + * @param string + * @param array + * @return bool + */ + function insert_update($table, $set) { + foreach ($set as $key => $val) { + $set[$key] = "$key = $val"; + } + $update = implode(", ", $set); + return queries("INSERT INTO " . table($table) . " SET $update ON DUPLICATE KEY UPDATE $update"); + } + /** Get last auto increment ID * @return string */ @@ -822,6 +835,14 @@ if (!defined("DRIVER")) { return $connection->result("SHOW CREATE TABLE " . table($table), 1); } + /** Get SQL command to truncate table + * @param string + * @return string + */ + function truncate_sql($table) { + return "TRUNCATE " . table($table); + } + /** Get SQL command to change database * @param string * @return string diff --git a/adminer/drivers/oracle.inc.php b/adminer/drivers/oracle.inc.php index 3635ef98..b66dfc7d 100644 --- a/adminer/drivers/oracle.inc.php +++ b/adminer/drivers/oracle.inc.php @@ -83,7 +83,6 @@ if (isset($_GET["oracle"])) { function Min_Result($result) { $this->_result = $result; - $this->num_rows = -1; // all results unbuffered } function _convert($row) { diff --git a/adminer/drivers/sqlite.inc.php b/adminer/drivers/sqlite.inc.php index ddc989b6..f6849576 100644 --- a/adminer/drivers/sqlite.inc.php +++ b/adminer/drivers/sqlite.inc.php @@ -39,6 +39,10 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) { return "'" . sqlite_escape_string($string) . "'"; } + function store_result() { + return $this->_result; + } + function result($query, $field = 0) { $result = $this->query($query); if (!is_object($result)) { @@ -118,6 +122,10 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) { return "'" . $this->_link->escapeString($string) . "'"; } + function store_result() { + return $this->_result; + } + function result($query, $field = 0) { $result = $this->query($query); if (!is_object($result)) { @@ -133,7 +141,6 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) { function Min_Result($result) { $this->_result = $result; - $this->num_rows = 1; //! } function fetch_assoc() { @@ -190,10 +197,6 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) { return $this->_result = $this->query($query); } - function store_result() { - return $this->_result; - } - function next_result() { return false; } @@ -238,7 +241,7 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) { } function tables_list() { - return get_key_vals("SELECT name, type FROM sqlite_master WHERE type IN ('table', 'view')", 1); + return get_key_vals("SELECT name, type FROM sqlite_master WHERE type IN ('table', 'view') ORDER BY (name = 'sqlite_sequence'), name", 1); } function count_tables($databases) { @@ -278,14 +281,14 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) { if (is_object($result)) { while ($row = $result->fetch_assoc()) { $type = strtolower($row["type"]); + $default = $row["dflt_value"]; $return[$row["name"]] = array( "field" => $row["name"], "type" => (eregi("int", $type) ? "integer" : (eregi("char|clob|text", $type) ? "text" : (eregi("blob", $type) ? "blob" : (eregi("real|floa|doub", $type) ? "real" : "numeric")))), "full_type" => $type, - "default" => $row["dflt_value"], + "default" => (ereg("'(.*)'", $default, $match) ? str_replace("''", "'", $match[1]) : ($default == "NULL" ? null : $default)), "null" => !$row["notnull"], "auto_increment" => eregi('^integer$', $type) && $row["pk"], //! possible false positive - "collation" => null, //! "privileges" => array("select" => 1, "insert" => 1, "update" => 1), "primary" => $row["pk"], ); @@ -489,6 +492,10 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) { return queries("INSERT INTO " . table($table) . ($set ? " (" . implode(", ", array_keys($set)) . ")\nVALUES (" . implode(", ", $set) . ")" : "DEFAULT VALUES")); } + function insert_update($table, $set) { + return queries("REPLACE INTO " . table($table) . " (" . implode(", ", array_keys($set)) . ") VALUES (" . implode(", ", $set) . ")"); + } + function last_id() { global $connection; return $connection->result("SELECT LAST_INSERT_ROWID()"); @@ -498,6 +505,10 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) { return $connection->query("EXPLAIN $query"); } + function types() { + return array(); + } + function schemas() { return array(); } @@ -515,9 +526,11 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) { return $connection->result("SELECT sql FROM sqlite_master WHERE type = 'table' AND name = " . $connection->quote($table)); } + function truncate_sql($table) { + return "DELETE FROM " . table($table); + } + function use_sql($database) { - global $connection; - return "ATTACH " . $connection->quote($database) . " AS " . idf_escape($database); } function trigger_sql($table, $style) { diff --git a/adminer/dump.inc.php b/adminer/dump.inc.php index 46bd5357..75c094b7 100644 --- a/adminer/dump.inc.php +++ b/adminer/dump.inc.php @@ -157,10 +157,11 @@ page_header(lang('Export'), "", ($_GET["export"] != "" ? array("table" => $_GET[
" . lang('Output') . "" . $adminer->dumpOutput(0, $row["output"]) . "\n"; echo "
" . lang('Format') . "" . $adminer->dumpFormat(0, $row["format"]) . "\n"; -echo "
" . lang('Database') . "" . html_select('db_style', $db_style, $row["db_style"]) +echo ($jush == "sqlite" ? "" : "
" . lang('Database') . "" . html_select('db_style', $db_style, $row["db_style"]) . (support("routine") ? checkbox("routines", 1, $checked, lang('Routines')) : "") . (support("event") ? checkbox("events", 1, $checked, lang('Events')) : "") -; +); echo "
" . lang('Tables') . "" . html_select('table_style', $table_style, $row["table_style"]) . (support("trigger") ? checkbox("triggers", 1, $row["table_style"], lang('Triggers')) : "") ; diff --git a/adminer/include/adminer.inc.php b/adminer/include/adminer.inc.php index d52d4b82..db6028fa 100644 --- a/adminer/include/adminer.inc.php +++ b/adminer/include/adminer.inc.php @@ -304,7 +304,7 @@ document.getElementById('username').focus(); * @return array expressions to join by AND */ function selectSearchProcess($fields, $indexes) { - global $connection; + global $connection, $jush; $return = array(); foreach ($indexes as $i => $index) { if ($index["type"] == "FULLTEXT" && $_GET["fulltext"][$i] != "") { @@ -330,7 +330,7 @@ document.getElementById('username').focus(); foreach ($fields as $name => $field) { if (is_numeric($val["val"]) || !ereg('int|float|double|decimal', $field["type"])) { $name = idf_escape($name); - $cols[] = (ereg('char|text|enum|set', $field["type"]) && !ereg('^utf8', $field["collation"]) ? "CONVERT($name USING utf8)" : $name); + $cols[] = ($jush == "sql" && ereg('char|text|enum|set', $field["type"]) && !ereg('^utf8', $field["collation"]) ? "CONVERT($name USING utf8)" : $name); } } $return[] = ($cols ? "(" . implode("$cond OR ", $cols) . "$cond)" : "0"); diff --git a/adminer/include/editing.inc.php b/adminer/include/editing.inc.php index 1ebdb422..70ac314d 100644 --- a/adminer/include/editing.inc.php +++ b/adminer/include/editing.inc.php @@ -5,77 +5,73 @@ * @return null */ function select($result, $connection2 = null) { - if (!$result->num_rows) { - echo "

" . lang('No rows.') . "\n"; - } else { - echo "\n"; - $links = array(); // colno => orgtable - create links from these columns - $indexes = array(); // orgtable => array(column => colno) - primary keys - $columns = array(); // orgtable => array(column => ) - not selected columns in primary key - $blobs = array(); // colno => bool - display bytes for blobs - $types = array(); // colno => type - display char in - odd(''); // reset odd for each result - for ($i=0; $row = $result->fetch_row(); $i++) { - if (!$i) { - echo ""; - for ($j=0; $j < count($row); $j++) { - $field = $result->fetch_field(); - $orgtable = $field->orgtable; - $orgname = $field->orgname; - if ($orgtable != "") { - if (!isset($indexes[$orgtable])) { - // find primary key in each table - $indexes[$orgtable] = array(); - foreach (indexes($orgtable, $connection2) as $index) { - if ($index["type"] == "PRIMARY") { - $indexes[$orgtable] = array_flip($index["columns"]); - break; - } + $links = array(); // colno => orgtable - create links from these columns + $indexes = array(); // orgtable => array(column => colno) - primary keys + $columns = array(); // orgtable => array(column => ) - not selected columns in primary key + $blobs = array(); // colno => bool - display bytes for blobs + $types = array(); // colno => type - display char in + odd(''); // reset odd for each result + for ($i=0; $row = $result->fetch_row(); $i++) { + if (!$i) { + echo "
\n"; + echo ""; + for ($j=0; $j < count($row); $j++) { + $field = $result->fetch_field(); + $orgtable = $field->orgtable; + $orgname = $field->orgname; + if ($orgtable != "") { + if (!isset($indexes[$orgtable])) { + // find primary key in each table + $indexes[$orgtable] = array(); + foreach (indexes($orgtable, $connection2) as $index) { + if ($index["type"] == "PRIMARY") { + $indexes[$orgtable] = array_flip($index["columns"]); + break; } - $columns[$orgtable] = $indexes[$orgtable]; - } - if (isset($columns[$orgtable][$orgname])) { - unset($columns[$orgtable][$orgname]); - $indexes[$orgtable][$orgname] = $j; - $links[$j] = $orgtable; } + $columns[$orgtable] = $indexes[$orgtable]; } - if ($field->charsetnr == 63) { // 63 - binary - $blobs[$j] = true; - } - $types[$j] = $field->type; - echo "name != $orgname ? " title='" . h(($orgtable != "" ? "$orgtable." : "") . $orgname) . "'" : "") . ">" . h($field->name); - } - echo "\n"; - } - echo ""; - foreach ($row as $key => $val) { - if (!isset($val)) { - $val = "NULL"; - } else { - if ($blobs[$key] && !is_utf8($val)) { - $val = "" . lang('%d byte(s)', strlen($val)) . ""; //! link to download - } elseif (!strlen($val)) { // strlen - SQLite can return int - $val = " "; // some content to print a border - } else { - $val = h($val); - if ($types[$key] == 254) { // 254 - char - $val = "$val"; - } - } - if (isset($links[$key]) && !$columns[$links[$key]]) { - $link = "edit=" . urlencode($links[$key]); - foreach ($indexes[$links[$key]] as $col => $j) { - $link .= "&where" . urlencode("[" . bracket_escape($col) . "]") . "=" . urlencode($row[$j]); - } - $val = "$val"; + if (isset($columns[$orgtable][$orgname])) { + unset($columns[$orgtable][$orgname]); + $indexes[$orgtable][$orgname] = $j; + $links[$j] = $orgtable; } } - echo "
$val"; + if ($field->charsetnr == 63) { // 63 - binary + $blobs[$j] = true; + } + $types[$j] = $field->type; + echo "name != $orgname ? " title='" . h(($orgtable != "" ? "$orgtable." : "") . $orgname) . "'" : "") . ">" . h($field->name); } + echo "\n"; + } + echo ""; + foreach ($row as $key => $val) { + if (!isset($val)) { + $val = "NULL"; + } else { + if ($blobs[$key] && !is_utf8($val)) { + $val = "" . lang('%d byte(s)', strlen($val)) . ""; //! link to download + } elseif (!strlen($val)) { // strlen - SQLite can return int + $val = " "; // some content to print a border + } else { + $val = h($val); + if ($types[$key] == 254) { // 254 - char + $val = "$val"; + } + } + if (isset($links[$key]) && !$columns[$links[$key]]) { + $link = "edit=" . urlencode($links[$key]); + foreach ($indexes[$links[$key]] as $col => $j) { + $link .= "&where" . urlencode("[" . bracket_escape($col) . "]") . "=" . urlencode($row[$j]); + } + $val = "$val"; + } + } + echo "$val"; } - echo "
\n"; } + echo ($i ? "

" : "

" . lang('No rows.')) . "\n"; } /** Get referencable tables with single column primary key except self diff --git a/adminer/include/export.inc.php b/adminer/include/export.inc.php index 892dce53..7c449529 100644 --- a/adminer/include/export.inc.php +++ b/adminer/include/export.inc.php @@ -20,7 +20,7 @@ function dump_table($table, $style, $is_view = false) { $create = create_sql($table); if ($create) { if ($style == "DROP+CREATE") { - echo "DROP " . ($is_view ? "VIEW" : "TABLE") . " IF EXISTS " . idf_escape($table) . ";\n"; + echo "DROP " . ($is_view ? "VIEW" : "TABLE") . " IF EXISTS " . table($table) . ";\n"; } echo ($style != "CREATE+ALTER" ? $create : ($is_view ? substr_replace($create, " OR REPLACE", 6, 0) : substr_replace($create, " IF NOT EXISTS", 12, 0))) . ";\n\n"; } @@ -86,7 +86,7 @@ CREATE PROCEDURE adminer_alter (INOUT alter_command text) BEGIN UNTIL done END REPEAT; CLOSE columns; IF @alter_table != '' OR add_columns != '' THEN - SET alter_command = CONCAT(alter_command, 'ALTER TABLE " . idf_escape($table) . "', SUBSTR(CONCAT(add_columns, @alter_table), 2), ';\\n'); + SET alter_command = CONCAT(alter_command, 'ALTER TABLE " . table($table) . "', SUBSTR(CONCAT(add_columns, @alter_table), 2), ';\\n'); END IF; END;; DELIMITER ; @@ -104,10 +104,10 @@ function dump_data($table, $style, $select = "") { $max_packet = ($jush == "sqlite" ? 0 : 1048576); // default, minimum is 1024 if ($style) { if ($_POST["format"] == "sql" && $style == "TRUNCATE+INSERT") { - echo "TRUNCATE " . idf_escape($table) . ";\n"; + echo truncate_sql($table) . ";\n"; } $fields = fields($table); - $result = $connection->query(($select ? $select : "SELECT * FROM " . idf_escape($table)), 1); // 1 - MYSQLI_USE_RESULT //! enum and set as numbers, microtime + $result = $connection->query(($select ? $select : "SELECT * FROM " . table($table)), 1); // 1 - MYSQLI_USE_RESULT //! enum and set as numbers, microtime if ($result) { $insert = ""; $buffer = ""; @@ -116,7 +116,7 @@ function dump_data($table, $style, $select = "") { dump_csv($row); } else { if (!$insert) { - $insert = "INSERT INTO " . idf_escape($table) . " (" . implode(", ", array_map('idf_escape', array_keys($row))) . ") VALUES"; + $insert = "INSERT INTO " . table($table) . " (" . implode(", ", array_map('idf_escape', array_keys($row))) . ") VALUES"; } foreach ($row as $key => $val) { $row[$key] = (isset($val) ? (ereg('int|float|double|decimal', $fields[$key]["type"]) ? $val : $connection->quote($val)) : "NULL"); //! columns looking like functions diff --git a/adminer/include/functions.inc.php b/adminer/include/functions.inc.php index 743ecfd0..21733338 100644 --- a/adminer/include/functions.inc.php +++ b/adminer/include/functions.inc.php @@ -626,7 +626,7 @@ function search_tables() { $name = $adminer->tableName($table_status); if (isset($table_status["Engine"]) && $name != "" && (!$_POST["tables"] || in_array($table, $_POST["tables"]))) { $result = $connection->query("SELECT" . limit("1 FROM " . table($table), " WHERE " . implode(" AND ", $adminer->selectSearchProcess(fields($table), array())), 1)); - if ($result->num_rows) { + if ($result->fetch_row()) { if (!$found) { echo "