Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MS SQL schema support

  • Loading branch information...
commit 60c7ed9a6122954fd32bc68e1459817b171a4c52 1 parent 7f3ccd3
@vrana authored
View
2  adminer/create.inc.php
@@ -17,7 +17,7 @@
if ($_POST && !$error && !$_POST["add"] && !$_POST["drop_col"] && !$_POST["up"] && !$_POST["down"]) {
if ($_POST["drop"]) {
- query_redirect("DROP TABLE " . idf_escape($_GET["create"]), substr(ME, 0, -1), lang('Table has been dropped.'));
+ query_redirect("DROP TABLE " . table($TABLE), substr(ME, 0, -1), lang('Table has been dropped.'));
} else {
$fields = array();
$foreign = array();
View
2  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 " . idf_escape($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
View
55 adminer/drivers/mssql.inc.php
@@ -237,6 +237,10 @@ function idf_escape($idf) {
return "[" . str_replace("]", "]]", $idf) . "]";
}
+ function table($idf) {
+ return ($_GET["ns"] != "" ? idf_escape($_GET["ns"]) . "." : "") . idf_escape($idf);
+ }
+
function connect() {
global $adminer;
$connection = new Min_DB;
@@ -274,7 +278,13 @@ function logged_user() {
}
function tables_list() {
- return get_key_vals("SELECT TABLE_NAME, TABLE_TYPE FROM information_schema.TABLES");
+ global $connection;
+ /* no means for sys views discovery
+ if ($_GET["ns"] == "sys" || $_GET["ns"] == "INFORMATION_SCHEMA") {
+ return get_key_vals("SELECT name, type_desc FROM sys.system_objects WHERE type = 'V' AND schema_id = SCHEMA_ID('$_GET[ns]')");
+ }
+ */
+ return get_key_vals("SELECT TABLE_NAME, TABLE_TYPE FROM information_schema.TABLES WHERE TABLE_SCHEMA = " . $connection->quote(get_schema()));
}
function count_tables($databases) {
@@ -290,7 +300,7 @@ function count_tables($databases) {
function table_status($name = "") {
global $connection;
$return = array();
- $result = $connection->query("SELECT TABLE_NAME AS Name, TABLE_TYPE AS Engine FROM information_schema.TABLES" . ($name != "" ? " WHERE TABLE_NAME = " . $connection->quote($name) : ""));
+ $result = $connection->query("SELECT TABLE_NAME AS Name, TABLE_TYPE AS Engine FROM information_schema.TABLES WHERE TABLE_SCHEMA = " . $connection->quote(get_schema()) . ($name != "" ? " AND TABLE_NAME = " . $connection->quote($name) : ""));
while ($row = $result->fetch_assoc()) {
if ($name != "") {
return $row;
@@ -310,7 +320,7 @@ function fields($table) {
$result = $connection->query("SELECT i.*, c.is_identity
FROM information_schema.COLUMNS i
JOIN sys.columns c ON OBJECT_NAME(c.object_id) = i.TABLE_NAME AND c.name = i.COLUMN_NAME
-WHERE i.TABLE_NAME = " . $connection->quote($table)
+WHERE i.TABLE_SCHEMA = " . $connection->quote(get_schema()) . " AND i.TABLE_NAME = " . $connection->quote($table)
);
while ($row = $result->fetch_assoc()) {
$return[$row["COLUMN_NAME"]] = array(
@@ -399,7 +409,7 @@ function begin() {
}
function insert_into($table, $set) {
- return queries("INSERT INTO " . idf_escape($table) . ($set ? " (" . implode(", ", array_keys($set)) . ")\nVALUES (" . implode(", ", $set) . ")" : "DEFAULT VALUES"));
+ return queries("INSERT INTO " . table($table) . ($set ? " (" . implode(", ", array_keys($set)) . ")\nVALUES (" . implode(", ", $set) . ")" : "DEFAULT VALUES"));
}
function explain($connection, $query) {
@@ -424,7 +434,7 @@ function foreign_keys($table) {
function truncate_tables($tables) {
foreach ($tables as $table) {
- if (!queries("TRUNCATE TABLE " . idf_escape($table))) {
+ if (!queries("TRUNCATE TABLE " . table($table))) {
return false;
}
}
@@ -432,13 +442,22 @@ function truncate_tables($tables) {
}
function drop_views($views) {
- return queries("DROP VIEW " . implode(", ", array_map('idf_escape', $views)));
+ return queries("DROP VIEW " . implode(", ", array_map('table', $views)));
}
function drop_tables($tables) {
- return queries("DROP TABLE " . implode(", ", array_map('idf_escape', $tables)));
+ return queries("DROP TABLE " . implode(", ", array_map('table', $tables)));
}
+ function move_tables($tables, $views, $target) {
+ foreach (array_merge($tables, $views) as $table) {
+ if (!queries("ALTER SCHEMA " . idf_escape($target) . " TRANSFER " . table($table))) {
+ return false;
+ }
+ }
+ return true;
+ }
+
function trigger($name) {
global $connection;
$result = $connection->query("SELECT s.name [Trigger],
@@ -448,7 +467,7 @@ function trigger($name) {
FROM sysobjects s
JOIN syscomments c ON s.id = c.id
WHERE s.xtype = 'TR' AND s.name = " . $connection->quote($name)
- );
+ ); // triggers are not schema-scoped
$row = $result->fetch_assoc();
$row["Statement"] = preg_replace('~^.+\\s+AS\\s+~isU', '', $row["text"]); //! identifiers, comments
return $row;
@@ -463,7 +482,7 @@ function triggers($table) {
FROM sysobjects sys1
JOIN sysobjects sys2 ON sys1.parent_obj = sys2.id
WHERE sys1.xtype = 'TR' AND sys2.name = " . $connection->quote($table)
- );
+ ); // triggers are not schema-scoped
while ($row = $result->fetch_assoc()) {
$return[$row["name"]] = array($row["Timing"], $row["Event"]);
}
@@ -477,6 +496,22 @@ function trigger_options() {
);
}
+ function schemas() {
+ return get_vals("SELECT name FROM sys.schemas");
+ }
+
+ function get_schema() {
+ global $connection;
+ if ($_GET["ns"] != "") {
+ return $_GET["ns"];
+ }
+ return $connection->result("SELECT SCHEMA_NAME()");
+ }
+
+ function set_schema($schema) {
+ return true; // ALTER USER is permanent
+ }
+
function use_sql($database) {
return "USE " . idf_escape($database);
}
@@ -490,7 +525,7 @@ function show_status() {
}
function support($feature) {
- return ereg('^(trigger|drop_col)$', $feature); //! view|routine|scheme|
+ return ereg('^(scheme|trigger|drop_col)$', $feature); //! view|routine|
}
$jush = "mssql";
View
40 adminer/drivers/mysql.inc.php
@@ -223,6 +223,14 @@ function idf_escape($idf) {
return "`" . str_replace("`", "``", $idf) . "`";
}
+ /** Get escaped table name
+ * @param string
+ * @return string
+ */
+ function table($idf) {
+ return idf_escape($idf);
+ }
+
/** Connect to the database
* @return mixed Min_DB or string for error
*/
@@ -376,7 +384,7 @@ function fk_support($table_status) {
function fields($table) {
global $connection;
$return = array();
- $result = $connection->query("SHOW FULL COLUMNS FROM " . idf_escape($table));
+ $result = $connection->query("SHOW FULL COLUMNS FROM " . table($table));
if ($result) {
while ($row = $result->fetch_assoc()) {
preg_match('~^([^( ]+)(?:\\((.+)\\))?( unsigned)?( zerofill)?$~', $row["Type"], $match);
@@ -411,7 +419,7 @@ function indexes($table, $connection2 = null) {
$connection2 = $connection;
}
$return = array();
- $result = $connection2->query("SHOW INDEX FROM " . idf_escape($table));
+ $result = $connection2->query("SHOW INDEX FROM " . table($table));
if ($result) {
while ($row = $result->fetch_assoc()) {
$return[$row["Key_name"]]["type"] = ($row["Key_name"] == "PRIMARY" ? "PRIMARY" : ($row["Index_type"] == "FULLTEXT" ? "FULLTEXT" : ($row["Non_unique"] ? "INDEX" : "UNIQUE")));
@@ -430,7 +438,7 @@ function foreign_keys($table) {
global $connection, $on_actions;
static $pattern = '`(?:[^`]|``)+`';
$return = array();
- $create_table = $connection->result("SHOW CREATE TABLE " . idf_escape($table), 1);
+ $create_table = $connection->result("SHOW CREATE TABLE " . table($table), 1);
if ($create_table) {
preg_match_all("~CONSTRAINT ($pattern) FOREIGN KEY \\(((?:$pattern,? ?)+)\\) REFERENCES ($pattern)(?:\\.($pattern))? \\(((?:$pattern,? ?)+)\\)(?: ON DELETE (" . implode("|", $on_actions) . "))?(?: ON UPDATE (" . implode("|", $on_actions) . "))?~", $create_table, $matches, PREG_SET_ORDER);
foreach ($matches as $match) {
@@ -455,7 +463,7 @@ function foreign_keys($table) {
*/
function view($name) {
global $connection;
- return array("select" => preg_replace('~^(?:[^`]|`[^`]*`)*\\s+AS\\s+~isU', '', $connection->result("SHOW CREATE VIEW " . idf_escape($name), 1)));
+ return array("select" => preg_replace('~^(?:[^`]|`[^`]*`)*\\s+AS\\s+~isU', '', $connection->result("SHOW CREATE VIEW " . table($name), 1)));
}
/** Get sorted grouped list of collations
@@ -536,7 +544,7 @@ function rename_database($name, $collation) {
//! move triggers
$return = true; // table list may by empty
foreach (tables_list() as $table) {
- if (!queries("RENAME TABLE " . idf_escape($table) . " TO " . idf_escape($name) . "." . idf_escape($table))) {
+ if (!queries("RENAME TABLE " . table($table) . " TO " . idf_escape($name) . "." . table($table))) {
$return = false;
break;
}
@@ -598,13 +606,13 @@ function alter_table($table, $name, $fields, $foreign, $comment, $engine, $colla
. $partitioning
;
if ($table == "") {
- return queries("CREATE TABLE " . idf_escape($name) . " (\n" . implode(",\n", $alter) . "\n) $status");
+ return queries("CREATE TABLE " . table($name) . " (\n" . implode(",\n", $alter) . "\n) $status");
}
if ($table != $name) {
- $alter[] = "RENAME TO " . idf_escape($name);
+ $alter[] = "RENAME TO " . table($name);
}
$alter[] = $status;
- return queries("ALTER TABLE " . idf_escape($table) . "\n" . implode(",\n", $alter));
+ return queries("ALTER TABLE " . table($table) . "\n" . implode(",\n", $alter));
}
/** Run commands to alter indexes
@@ -616,7 +624,7 @@ function alter_indexes($table, $alter) {
foreach ($alter as $key => $val) {
$alter[$key] = ($val[2] ? "\nDROP INDEX " : "\nADD $val[0] " . ($val[0] == "PRIMARY" ? "KEY " : "")) . $val[1];
}
- return queries("ALTER TABLE " . idf_escape($table) . implode(",", $alter));
+ return queries("ALTER TABLE " . table($table) . implode(",", $alter));
}
/** Run commands to truncate tables
@@ -625,7 +633,7 @@ function alter_indexes($table, $alter) {
*/
function truncate_tables($tables) {
foreach ($tables as $table) {
- if (!queries("TRUNCATE TABLE " . idf_escape($table))) {
+ if (!queries("TRUNCATE TABLE " . table($table))) {
return false;
}
}
@@ -637,7 +645,7 @@ function truncate_tables($tables) {
* @return bool
*/
function drop_views($views) {
- return queries("DROP VIEW " . implode(", ", array_map('idf_escape', $views)));
+ return queries("DROP VIEW " . implode(", ", array_map('table', $views)));
}
/** Drop tables
@@ -645,7 +653,7 @@ function drop_views($views) {
* @return bool
*/
function drop_tables($tables) {
- return queries("DROP TABLE " . implode(", ", array_map('idf_escape', $tables)));
+ return queries("DROP TABLE " . implode(", ", array_map('table', $tables)));
}
/** Move tables to other schema
@@ -656,7 +664,7 @@ function drop_tables($tables) {
function move_tables($tables, $views, $target) {
$rename = array();
foreach (array_merge($tables, $views) as $table) { // views will report SQL error
- $rename[] = idf_escape($table) . " TO " . idf_escape($target) . "." . idf_escape($table);
+ $rename[] = table($table) . " TO " . idf_escape($target) . "." . table($table);
}
return queries("RENAME TABLE " . implode(", ", $rename));
//! move triggers
@@ -757,7 +765,7 @@ function begin() {
* @return bool
*/
function insert_into($table, $set) {
- return queries("INSERT INTO " . idf_escape($table) . " (" . implode(", ", array_keys($set)) . ")\nVALUES (" . implode(", ", $set) . ")");
+ return queries("INSERT INTO " . table($table) . " (" . implode(", ", array_keys($set)) . ")\nVALUES (" . implode(", ", $set) . ")");
}
/** Explain select
@@ -797,7 +805,7 @@ function set_schema($schema) {
*/
function create_sql($table) {
global $connection;
- return $connection->result("SHOW CREATE TABLE " . idf_escape($table), 1);
+ return $connection->result("SHOW CREATE TABLE " . table($table), 1);
}
/** Get SQL command to change database
@@ -820,7 +828,7 @@ function trigger_sql($table, $style) {
if ($result->num_rows) {
while ($row = $result->fetch_assoc()) {
$return .= "\n" . ($style == 'CREATE+ALTER' ? "DROP TRIGGER IF EXISTS " . idf_escape($row["Trigger"]) . ";;\n" : "")
- . "CREATE TRIGGER " . idf_escape($row["Trigger"]) . " $row[Timing] $row[Event] ON " . idf_escape($row["Table"]) . " FOR EACH ROW\n$row[Statement];;\n";
+ . "CREATE TRIGGER " . idf_escape($row["Trigger"]) . " $row[Timing] $row[Event] ON " . table($row["Table"]) . " FOR EACH ROW\n$row[Statement];;\n";
}
}
return $return;
View
32 adminer/drivers/pgsql.inc.php
@@ -149,6 +149,10 @@ function idf_escape($idf) {
return '"' . str_replace('"', '""', $idf) . '"';
}
+ function table($idf) {
+ return idf_escape($idf);
+ }
+
function connect() {
global $adminer;
$connection = new Min_DB;
@@ -351,7 +355,7 @@ function alter_table($table, $name, $fields, $foreign, $comment, $engine, $colla
$alter[] = ($table != "" ? "ADD " : " ") . implode($val);
} else {
if ($column != $val[0]) {
- $queries[] = "ALTER TABLE " . idf_escape($table) . " RENAME $column TO $val[0]";
+ $queries[] = "ALTER TABLE " . table($table) . " RENAME $column TO $val[0]";
}
$alter[] = "ALTER $column TYPE$val[1]";
if (!$val[6]) {
@@ -360,21 +364,21 @@ function alter_table($table, $name, $fields, $foreign, $comment, $engine, $colla
}
}
if ($field[0] != "" || $val5 != "") {
- $queries[] = "COMMENT ON COLUMN " . idf_escape($table) . ".$val[0] IS " . ($val5 != "" ? substr($val5, 9) : "''");
+ $queries[] = "COMMENT ON COLUMN " . table($table) . ".$val[0] IS " . ($val5 != "" ? substr($val5, 9) : "''");
}
}
}
$alter = array_merge($alter, $foreign);
if ($table == "") {
- array_unshift($queries, "CREATE TABLE " . idf_escape($name) . " (\n" . implode(",\n", $alter) . "\n)");
+ array_unshift($queries, "CREATE TABLE " . table($name) . " (\n" . implode(",\n", $alter) . "\n)");
} elseif ($alter) {
- array_unshift($queries, "ALTER TABLE " . idf_escape($table) . "\n" . implode(",\n", $alter));
+ array_unshift($queries, "ALTER TABLE " . table($table) . "\n" . implode(",\n", $alter));
}
if ($table != "" && $table != $name) {
- $queries[] = "ALTER TABLE " . idf_escape($table) . " RENAME TO " . idf_escape($name);
+ $queries[] = "ALTER TABLE " . table($table) . " RENAME TO " . table($name);
}
if ($table != "" || $comment != "") {
- $queries[] = "COMMENT ON TABLE " . idf_escape($name) . " IS " . $connection->quote($comment);
+ $queries[] = "COMMENT ON TABLE " . table($name) . " IS " . $connection->quote($comment);
}
if ($auto_increment != "") {
//! $queries[] = "SELECT setval(pg_get_serial_sequence(" . $connection->quote($name) . ", ), $auto_increment)";
@@ -395,36 +399,36 @@ function alter_indexes($table, $alter) {
$create[] = ($val[2] ? "\nDROP CONSTRAINT " : "\nADD $val[0] " . ($val[0] == "PRIMARY" ? "KEY " : "")) . $val[1];
} elseif ($val[2]) {
$drop[] = $val[1];
- } elseif (!queries("CREATE INDEX " . idf_escape(uniqid($table . "_")) . " ON " . idf_escape($table) . " $val[1]")) {
+ } elseif (!queries("CREATE INDEX " . idf_escape(uniqid($table . "_")) . " ON " . table($table) . " $val[1]")) {
return false;
}
}
- return ((!$create || queries("ALTER TABLE " . idf_escape($table) . implode(",", $create)))
+ return ((!$create || queries("ALTER TABLE " . table($table) . implode(",", $create)))
&& (!$drop || queries("DROP INDEX " . implode(", ", $drop)))
);
}
function truncate_tables($tables) {
- return queries("TRUNCATE " . implode(", ", array_map('idf_escape', $tables)));
+ return queries("TRUNCATE " . implode(", ", array_map('table', $tables)));
return true;
}
function drop_views($views) {
- return queries("DROP VIEW " . implode(", ", array_map('idf_escape', $views)));
+ return queries("DROP VIEW " . implode(", ", array_map('table', $views)));
}
function drop_tables($tables) {
- return queries("DROP TABLE " . implode(", ", array_map('idf_escape', $tables)));
+ return queries("DROP TABLE " . implode(", ", array_map('table', $tables)));
}
function move_tables($tables, $views, $target) {
foreach ($tables as $table) {
- if (!queries("ALTER TABLE " . idf_escape($table) . " SET SCHEMA " . idf_escape($target))) {
+ if (!queries("ALTER TABLE " . table($table) . " SET SCHEMA " . idf_escape($target))) {
return false;
}
}
foreach ($views as $table) {
- if (!queries("ALTER VIEW " . idf_escape($table) . " SET SCHEMA " . idf_escape($target))) {
+ if (!queries("ALTER VIEW " . table($table) . " SET SCHEMA " . idf_escape($target))) {
return false;
}
}
@@ -459,7 +463,7 @@ function begin() {
}
function insert_into($table, $set) {
- return queries("INSERT INTO " . idf_escape($table) . ($set ? " (" . implode(", ", array_keys($set)) . ")\nVALUES (" . implode(", ", $set) . ")" : "DEFAULT VALUES"));
+ return queries("INSERT INTO " . table($table) . ($set ? " (" . implode(", ", array_keys($set)) . ")\nVALUES (" . implode(", ", $set) . ")" : "DEFAULT VALUES"));
}
function explain($connection, $query) {
View
26 adminer/drivers/sqlite.inc.php
@@ -203,6 +203,10 @@ function idf_escape($idf) {
return '"' . str_replace('"', '""', $idf) . '"';
}
+ function table($idf) {
+ return idf_escape($idf);
+ }
+
function connect() {
return new Min_DB;
}
@@ -266,7 +270,7 @@ function fk_support($table_status) {
function fields($table) {
global $connection;
$return = array();
- $result = $connection->query("PRAGMA table_info(" . idf_escape($table) . ")");
+ $result = $connection->query("PRAGMA table_info(" . table($table) . ")");
if (is_object($result)) {
while ($row = $result->fetch_assoc()) {
$type = strtolower($row["type"]);
@@ -298,7 +302,7 @@ function indexes($table, $connection2 = null) {
if ($primary) {
$return[""] = array("type" => "PRIMARY", "columns" => $primary, "lengths" => array());
}
- $result = $connection->query("PRAGMA index_list(" . idf_escape($table) . ")");
+ $result = $connection->query("PRAGMA index_list(" . table($table) . ")");
if (is_object($result)) {
while ($row = $result->fetch_assoc()) {
$return[$row["name"]]["type"] = ($row["unique"] ? "UNIQUE" : "INDEX");
@@ -315,7 +319,7 @@ function indexes($table, $connection2 = null) {
function foreign_keys($table) {
global $connection;
$return = array();
- $result = $connection->query("PRAGMA foreign_key_list(" . idf_escape($table) . ")");
+ $result = $connection->query("PRAGMA foreign_key_list(" . table($table) . ")");
if (is_object($result)) {
while ($row = $result->fetch_assoc()) {
$foreign_key = &$return[$row["id"]];
@@ -400,14 +404,14 @@ function alter_table($table, $name, $fields, $foreign, $comment, $engine, $colla
$alter = array_merge($alter, $foreign);
if ($table != "") {
foreach ($alter as $val) {
- if (!queries("ALTER TABLE " . idf_escape($table) . " $val")) {
+ if (!queries("ALTER TABLE " . table($table) . " $val")) {
return false;
}
}
- if ($table != $name && !queries("ALTER TABLE " . idf_escape($table) . " RENAME TO " . idf_escape($name))) {
+ if ($table != $name && !queries("ALTER TABLE " . table($table) . " RENAME TO " . table($name))) {
return false;
}
- } elseif (!queries("CREATE TABLE " . idf_escape($name) . " (\n" . implode(",\n", $alter) . "\n)")) {
+ } elseif (!queries("CREATE TABLE " . table($name) . " (\n" . implode(",\n", $alter) . "\n)")) {
return false;
}
if ($auto_increment) {
@@ -418,7 +422,7 @@ function alter_table($table, $name, $fields, $foreign, $comment, $engine, $colla
function alter_indexes($table, $alter) {
foreach ($alter as $val) {
- if (!queries(($val[2] ? "DROP INDEX" : "CREATE" . ($val[0] != "INDEX" ? " UNIQUE" : "") . " INDEX " . idf_escape(uniqid($table . "_")) . " ON " . idf_escape($table)) . " $val[1]")) { //! primary key must be created in CREATE TABLE
+ if (!queries(($val[2] ? "DROP INDEX" : "CREATE" . ($val[0] != "INDEX" ? " UNIQUE" : "") . " INDEX " . idf_escape(uniqid($table . "_")) . " ON " . table($table)) . " $val[1]")) { //! primary key must be created in CREATE TABLE
return false;
}
}
@@ -427,7 +431,7 @@ function alter_indexes($table, $alter) {
function truncate_tables($tables) {
foreach ($tables as $table) {
- if (!queries("DELETE FROM " . idf_escape($table))) {
+ if (!queries("DELETE FROM " . table($table))) {
return false;
}
}
@@ -436,7 +440,7 @@ function truncate_tables($tables) {
function drop_views($views) {
foreach ($views as $view) {
- if (!queries("DROP VIEW " . idf_escape($view))) {
+ if (!queries("DROP VIEW " . table($view))) {
return false;
}
}
@@ -445,7 +449,7 @@ function drop_views($views) {
function drop_tables($tables) {
foreach ($tables as $table) {
- if (!queries("DROP TABLE " . idf_escape($table))) {
+ if (!queries("DROP TABLE " . table($table))) {
return false;
}
}
@@ -493,7 +497,7 @@ function begin() {
}
function insert_into($table, $set) {
- return queries("INSERT INTO " . idf_escape($table) . ($set ? " (" . implode(", ", array_keys($set)) . ")\nVALUES (" . implode(", ", $set) . ")" : "DEFAULT VALUES"));
+ return queries("INSERT INTO " . table($table) . ($set ? " (" . implode(", ", array_keys($set)) . ")\nVALUES (" . implode(", ", $set) . ")" : "DEFAULT VALUES"));
}
function explain($connection, $query) {
View
6 adminer/edit.inc.php
@@ -16,7 +16,7 @@
$location = ME . "select=" . urlencode($TABLE);
}
if (isset($_POST["delete"])) {
- query_redirect("DELETE" . limit1("FROM " . idf_escape($_GET["edit"]) . "\nWHERE $where"), $location, lang('Item has been deleted.'));
+ query_redirect("DELETE" . limit1("FROM " . table($TABLE) . "\nWHERE $where"), $location, lang('Item has been deleted.'));
} else {
$set = array();
foreach ($fields as $name => $field) {
@@ -29,7 +29,7 @@
if (!$set) {
redirect($location);
}
- query_redirect("UPDATE" . limit1(idf_escape($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 {
queries_redirect($location, lang('Item has been inserted.'), insert_into($TABLE, $set));
}
@@ -56,7 +56,7 @@
}
$row = array();
if ($select) {
- $result = $connection->query("SELECT" . limit(implode(", ", $select) . " FROM " . idf_escape($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;
View
6 adminer/foreign.inc.php
@@ -2,7 +2,7 @@
$TABLE = $_GET["foreign"];
if ($_POST && !$error && !$_POST["add"] && !$_POST["change"] && !$_POST["change-js"]) {
if ($_POST["drop"]) {
- query_redirect("ALTER TABLE " . idf_escape($TABLE) . "\nDROP " . ($jush == "sql" ? "FOREIGN KEY " : "CONSTRAINT ") . idf_escape($_GET["name"]), ME . "table=" . urlencode($TABLE), lang('Foreign key has been dropped.'));
+ query_redirect("ALTER TABLE " . table($TABLE) . "\nDROP " . ($jush == "sql" ? "FOREIGN KEY " : "CONSTRAINT ") . idf_escape($_GET["name"]), ME . "table=" . urlencode($TABLE), lang('Foreign key has been dropped.'));
} else {
$source = array_filter($_POST["source"], 'strlen');
ksort($source); // enforce input order
@@ -10,9 +10,9 @@
foreach ($source as $key => $val) {
$target[$key] = $_POST["target"][$key];
}
- query_redirect("ALTER TABLE " . idf_escape($TABLE)
+ query_redirect("ALTER TABLE " . table($TABLE)
. ($_GET["name"] != "" ? "\nDROP FOREIGN KEY " . idf_escape($_GET["name"]) . "," : "")
- . "\nADD FOREIGN KEY (" . implode(", ", array_map('idf_escape', $source)) . ") REFERENCES " . idf_escape($_POST["table"]) . " (" . implode(", ", array_map('idf_escape', $target)) . ")"
+ . "\nADD FOREIGN KEY (" . implode(", ", array_map('idf_escape', $source)) . ") REFERENCES " . table($_POST["table"]) . " (" . implode(", ", array_map('idf_escape', $target)) . ")"
. (in_array($_POST["on_delete"], $on_actions) ? " ON DELETE $_POST[on_delete]" : "")
. (in_array($_POST["on_update"], $on_actions) ? " ON UPDATE $_POST[on_update]" : "")
, ME . "table=" . urlencode($TABLE), ($_GET["name"] != "" ? lang('Foreign key has been altered.') : lang('Foreign key has been created.')));
View
2  adminer/include/adminer.inc.php
@@ -552,7 +552,7 @@ function navigation($missing) {
: (isset($_GET["schema"]) ? '<input type="hidden" name="schema" value="">'
: (isset($_GET["dump"]) ? '<input type="hidden" name="dump" value="">'
: "")));
- echo "</form>\n";
+ echo "</p></form>\n";
}
}
View
2  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 " . idf_escape($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 "<ul>\n";
View
2  adminer/scheme.inc.php
@@ -8,7 +8,7 @@
if ($_GET["ns"] == "") {
query_redirect("CREATE SCHEMA " . idf_escape($_POST["name"]), $link, lang('Schema has been created.'));
} elseif ($_GET["ns"] != $_POST["name"]) {
- query_redirect("ALTER SCHEMA " . idf_escape($_GET["ns"]) . " RENAME TO " . idf_escape($_POST["name"]), $link, lang('Schema has been altered.'));
+ query_redirect("ALTER SCHEMA " . idf_escape($_GET["ns"]) . " RENAME TO " . idf_escape($_POST["name"]), $link, lang('Schema has been altered.')); //! sp_rename in MS SQL
} else {
redirect($link);
}
View
14 adminer/select.inc.php
@@ -23,7 +23,7 @@
$where = $adminer->selectSearchProcess($fields, $indexes);
$order = $adminer->selectOrderProcess($fields, $indexes);
$limit = $adminer->selectLimitProcess();
-$from = ($select ? implode(", ", $select) : "*") . "\nFROM " . idf_escape($TABLE) . ($where ? "\nWHERE " . implode(" AND ", $where) : "");
+$from = ($select ? implode(", ", $select) : "*") . "\nFROM " . table($TABLE) . ($where ? "\nWHERE " . implode(" AND ", $where) : "");
$group_by = ($group && count($group) < count($select) ? "\nGROUP BY " . implode(", ", $group) : "") . ($order ? "\nORDER BY " . implode(", ", $order) : "");
if ($_POST && !$error) {
@@ -64,7 +64,7 @@
if ($_POST["save"] || $_POST["delete"]) { // edit
$result = true;
$affected = 0;
- $query = idf_escape($TABLE);
+ $query = table($TABLE);
$set = array();
if (!$_POST["delete"]) {
foreach ($columns as $name => $val) { //! should check also for edit or insert privileges
@@ -77,7 +77,7 @@
}
}
}
- $query .= ($_POST["clone"] ? " (" . implode(", ", array_keys($set)) . ")\nSELECT " . implode(", ", $set) . "\nFROM " . idf_escape($TABLE) : " SET\n" . implode(",\n", $set));
+ $query .= ($_POST["clone"] ? " (" . implode(", ", array_keys($set)) . ")\nSELECT " . implode(", ", $set) . "\nFROM " . table($TABLE) : " SET\n" . implode(",\n", $set));
}
if ($_POST["delete"] || $set) {
$command = "UPDATE";
@@ -117,7 +117,7 @@
$key = bracket_escape($key, 1); // 1 - back
$set[] = idf_escape($key) . " = " . $adminer->processInput($fields[$key], $val);
}
- $result = queries("UPDATE" . limit1(idf_escape($TABLE) . " SET " . implode(", ", $set) . " WHERE " . where_check($unique_idf) . ($where ? " AND " . implode(" AND ", $where) : ""))); // can change row on a different page without unique key
+ $result = queries("UPDATE" . limit1(table($TABLE) . " SET " . implode(", ", $set) . " WHERE " . where_check($unique_idf) . ($where ? " AND " . implode(" AND ", $where) : ""))); // can change row on a different page without unique key
if (!$result) {
break;
}
@@ -145,7 +145,7 @@
$set .= ", " . idf_escape($cols[$i]) . " = " . ($col == "" && $fields[$cols[$i]]["null"] ? "NULL" : $connection->quote(str_replace('""', '"', preg_replace('~^"|"$~', '', $col))));
}
$set = substr($set, 1);
- $result = queries("INSERT INTO " . idf_escape($_GET["select"]) . " SET$set ON DUPLICATE KEY UPDATE$set");
+ $result = queries("INSERT INTO " . table($TABLE) . " SET$set ON DUPLICATE KEY UPDATE$set");
if (!$result) {
break;
}
@@ -198,7 +198,7 @@
$page = $_GET["page"];
if ($page == "last") {
- $found_rows = $connection->result("SELECT COUNT(*) FROM " . idf_escape($TABLE) . ($where ? " WHERE " . implode(" AND ", $where) : ""));
+ $found_rows = $connection->result("SELECT COUNT(*) FROM " . table($TABLE) . ($where ? " WHERE " . implode(" AND ", $where) : ""));
$page = floor(($found_rows - 1) / $limit);
}
@@ -345,7 +345,7 @@
// slow with big tables
ob_flush();
flush();
- $found_rows = $connection->result("SELECT COUNT(*) FROM " . idf_escape($TABLE) . ($where ? " WHERE " . implode(" AND ", $where) : ""));
+ $found_rows = $connection->result("SELECT COUNT(*) FROM " . table($TABLE) . ($where ? " WHERE " . implode(" AND ", $where) : ""));
} else {
$exact_count = false;
}
View
4 adminer/trigger.inc.php
@@ -6,9 +6,9 @@
$dropped = false;
if ($_POST && !$error && in_array($_POST["Timing"], $trigger_options["Timing"]) && in_array($_POST["Event"], $trigger_event) && in_array($_POST["Type"], $trigger_options["Type"])) {
$timing_event = " $_POST[Timing] $_POST[Event]";
- $on = " ON " . idf_escape($TABLE);
+ $on = " ON " . table($TABLE);
$dropped = drop_create(
- "DROP TRIGGER " . idf_escape($_GET["name"]) . ($jush == "pgsql" ? " ON " . idf_escape($TABLE) : ""),
+ "DROP TRIGGER " . idf_escape($_GET["name"]) . ($jush == "pgsql" ? $on : ""),
"CREATE TRIGGER " . idf_escape($_POST["Trigger"]) . ($jush == "mssql" ? $on . $timing_event : $timing_event . $on) . " $_POST[Type]\n$_POST[Statement]",
ME . "table=" . urlencode($TABLE),
lang('Trigger has been dropped.'),
View
4 adminer/view.inc.php
@@ -3,8 +3,8 @@
$dropped = false;
if ($_POST && !$error) {
$dropped = drop_create(
- "DROP VIEW " . idf_escape($TABLE),
- "CREATE VIEW " . idf_escape($_POST["name"]) . " AS\n$_POST[select]",
+ "DROP VIEW " . table($TABLE),
+ "CREATE VIEW " . table($_POST["name"]) . " AS\n$_POST[select]",
($_POST["drop"] ? substr(ME, 0, -1) : ME . "table=" . urlencode($_POST["name"])),
lang('View has been dropped.'),
lang('View has been altered.'),
Please sign in to comment.
Something went wrong with that request. Please try again.