diff --git a/adminer/create.inc.php b/adminer/create.inc.php index 809bdba1..0a0569b0 100644 --- a/adminer/create.inc.php +++ b/adminer/create.inc.php @@ -119,7 +119,7 @@ if ($_POST) { } if (support("partitioning")) { $from = "FROM information_schema.PARTITIONS WHERE TABLE_SCHEMA = " . $connection->quote(DB) . " AND TABLE_NAME = " . $connection->quote($TABLE); - $result = $connection->query("SELECT" . limit("PARTITION_METHOD, PARTITION_ORDINAL_POSITION, PARTITION_EXPRESSION $from ORDER BY PARTITION_ORDINAL_POSITION", 1)); + $result = $connection->query("SELECT PARTITION_METHOD, PARTITION_ORDINAL_POSITION, PARTITION_EXPRESSION $from ORDER BY PARTITION_ORDINAL_POSITION LIMIT 1"); list($row["partition_by"], $row["partitions"], $row["partition"]) = $result->fetch_row(); $row["partition_names"] = array(); $row["partition_values"] = array(); diff --git a/adminer/download.inc.php b/adminer/download.inc.php index 9641369d..5a86efe5 100644 --- a/adminer/download.inc.php +++ b/adminer/download.inc.php @@ -2,5 +2,5 @@ $TABLE = $_GET["download"]; header("Content-Type: application/octet-stream"); header("Content-Disposition: attachment; filename=" . friendly_url("$TABLE-" . implode("_", $_GET["where"])) . "." . friendly_url($_GET["field"])); -echo $connection->result("SELECT" . limit(idf_escape($_GET["field"]) . " FROM " . table($TABLE) . " WHERE " . where($_GET), 1)); +echo $connection->result("SELECT" . limit(idf_escape($_GET["field"]) . " FROM " . table($TABLE), " WHERE " . where($_GET), 1)); exit; // don't output footer diff --git a/adminer/drivers/mssql.inc.php b/adminer/drivers/mssql.inc.php index 399437e5..4fa7c81b 100644 --- a/adminer/drivers/mssql.inc.php +++ b/adminer/drivers/mssql.inc.php @@ -44,7 +44,6 @@ if (isset($_GET["mssql"])) { return $this->query("USE $database"); } - function query($query, $unbuffered = false) { $result = sqlsrv_query($this->_link, $query); //! , array(), ($unbuffered ? array() : array("Scrollable" => "keyset")) if (!$result) { @@ -255,12 +254,12 @@ if (isset($_GET["mssql"])) { return get_vals("EXEC sp_databases"); } - function limit($query, $limit, $offset = 0, $separator = " ") { - return (isset($limit) ? " TOP (" . ($limit + $offset) . ")" : "") . " $query"; // seek later + function limit($query, $where, $limit, $offset = 0, $separator = " ") { + return (isset($limit) ? " TOP (" . ($limit + $offset) . ")" : "") . " $query$where"; // seek later } - function limit1($query) { - return limit($query, 1); + function limit1($query, $where) { + return limit($query, $where, 1); } function db_collation($db, $collations) { diff --git a/adminer/drivers/mysql.inc.php b/adminer/drivers/mysql.inc.php index 2ff4099a..5f261d35 100644 --- a/adminer/drivers/mysql.inc.php +++ b/adminer/drivers/mysql.inc.php @@ -266,21 +266,22 @@ if (!defined("DRIVER")) { /** Formulate SQL query with limit * @param string everything after SELECT + * @param string including WHERE * @param int * @param int * @param string * @return string */ - function limit($query, $limit, $offset = 0, $separator = " ") { - return " $query" . (isset($limit) ? $separator . "LIMIT $limit" . ($offset ? " OFFSET $offset" : "") : ""); + function limit($query, $where, $limit, $offset = 0, $separator = " ") { + return " $query$where" . (isset($limit) ? $separator . "LIMIT $limit" . ($offset ? " OFFSET $offset" : "") : ""); } /** Formulate SQL modification query with limit 1 * @param string everything after UPDATE or DELETE * @return string */ - function limit1($query) { - return limit($query, 1); + function limit1($query, $where) { + return limit($query, $where, 1); } /** Get database collation diff --git a/adminer/drivers/pgsql.inc.php b/adminer/drivers/pgsql.inc.php index 2858db39..48fcca3c 100644 --- a/adminer/drivers/pgsql.inc.php +++ b/adminer/drivers/pgsql.inc.php @@ -45,11 +45,11 @@ if (isset($_GET["pgsql"])) { if ($database == DB) { return $this->_database; } - $link = @pg_connect($this->_connection . " dbname='" . addcslashes($database, "'\\") . "'", PGSQL_CONNECT_FORCE_NEW); - if ($link) { - $this->_link = $link; + $return = @pg_connect($this->_connection . " dbname='" . addcslashes($database, "'\\") . "'", PGSQL_CONNECT_FORCE_NEW); + if ($return) { + $this->_link = $return; } - return $link; + return $return; } function close() { @@ -108,15 +108,15 @@ if (isset($_GET["pgsql"])) { function fetch_field() { $column = $this->_offset++; - $row = new stdClass; + $return = new stdClass; if (function_exists('pg_field_table')) { - $row->orgtable = pg_field_table($this->_result, $column); + $return->orgtable = pg_field_table($this->_result, $column); } - $row->name = pg_field_name($this->_result, $column); - $row->orgname = $row->name; - $row->type = pg_field_type($this->_result, $column); - $row->charsetnr = ($row->type == "bytea" ? 63 : 0); // 63 - binary - return $row; + $return->name = pg_field_name($this->_result, $column); + $return->orgname = $return->name; + $return->type = pg_field_type($this->_result, $column); + $return->charsetnr = ($return->type == "bytea" ? 63 : 0); // 63 - binary + return $return; } function __destruct() { @@ -167,12 +167,12 @@ if (isset($_GET["pgsql"])) { return get_vals("SELECT datname FROM pg_database"); } - function limit($query, $limit, $offset = 0, $separator = " ") { - return " $query" . (isset($limit) ? $separator . "LIMIT $limit" . ($offset ? " OFFSET $offset" : "") : ""); + function limit($query, $where, $limit, $offset = 0, $separator = " ") { + return " $query$where" . (isset($limit) ? $separator . "LIMIT $limit" . ($offset ? " OFFSET $offset" : "") : ""); } - function limit1($query) { - return " $query"; + function limit1($query, $where) { + return " $query$where"; } function db_collation($db, $collations) { diff --git a/adminer/drivers/sqlite.inc.php b/adminer/drivers/sqlite.inc.php index bafb141e..de871033 100644 --- a/adminer/drivers/sqlite.inc.php +++ b/adminer/drivers/sqlite.inc.php @@ -215,13 +215,13 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) { return array(); } - function limit($query, $limit, $offset = 0, $separator = " ") { - return " $query" . (isset($limit) ? $separator . "LIMIT $limit" . ($offset ? " OFFSET $offset" : "") : ""); + function limit($query, $where, $limit, $offset = 0, $separator = " ") { + return " $query$where" . (isset($limit) ? $separator . "LIMIT $limit" . ($offset ? " OFFSET $offset" : "") : ""); } - function limit1($query) { + function limit1($query, $where) { global $connection; - return ($connection->result("SELECT sqlite_compileoption_used('ENABLE_UPDATE_DELETE_LIMIT')") ? limit($query, 1) : " $query"); + return ($connection->result("SELECT sqlite_compileoption_used('ENABLE_UPDATE_DELETE_LIMIT')") ? limit($query, $where, 1) : " $query$where"); } function db_collation($db, $collations) { diff --git a/adminer/edit.inc.php b/adminer/edit.inc.php index 9a853912..c23867da 100644 --- a/adminer/edit.inc.php +++ b/adminer/edit.inc.php @@ -16,7 +16,7 @@ if ($_POST && !$error && !isset($_GET["select"])) { $location = ME . "select=" . urlencode($TABLE); } if (isset($_POST["delete"])) { - query_redirect("DELETE" . limit1("FROM " . table($TABLE) . "\nWHERE $where"), $location, lang('Item has been deleted.')); + query_redirect("DELETE" . limit1("FROM " . table($TABLE), $where), $location, lang('Item has been deleted.')); } else { $set = array(); foreach ($fields as $name => $field) { @@ -29,7 +29,7 @@ if ($_POST && !$error && !isset($_GET["select"])) { if (!$set) { redirect($location); } - query_redirect("UPDATE" . limit1(table($TABLE) . " SET" . implode(",", $set) . "\nWHERE $where"), $location, lang('Item has been updated.')); + query_redirect("UPDATE" . limit1(table($TABLE) . " SET" . implode(",", $set), "\nWHERE $where"), $location, lang('Item has been updated.')); } else { $result = insert_into($TABLE, $set); $last_id = ($result ? last_id() : 0); @@ -58,7 +58,7 @@ if ($_POST["save"]) { } $row = array(); if ($select) { - $result = $connection->query("SELECT" . limit(implode(", ", $select) . " FROM " . table($TABLE) . " WHERE $where", (isset($_GET["select"]) ? 2 : 1))); + $result = $connection->query("SELECT" . limit(implode(", ", $select) . " FROM " . table($TABLE), " WHERE $where", (isset($_GET["select"]) ? 2 : 1))); $row = $result->fetch_assoc(); if (isset($_GET["select"]) && $result->fetch_assoc()) { $row = null; diff --git a/adminer/include/functions.inc.php b/adminer/include/functions.inc.php index 787e38b7..9ba0f691 100644 --- a/adminer/include/functions.inc.php +++ b/adminer/include/functions.inc.php @@ -609,7 +609,7 @@ function search_tables() { foreach (table_status() as $table => $table_status) { $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)); + $result = $connection->query("SELECT" . limit("1 FROM " . table($table), " WHERE " . implode(" AND ", $adminer->selectSearchProcess(fields($table), array())), 1)); if ($result->num_rows) { if (!$found) { echo "