Print SQL query by message
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@477 7c3ca157-0c34-0410-bff1-cbf682f78f5c
This commit is contained in:
parent
aa5a11907a
commit
f91b2c4bed
|
@ -5,9 +5,7 @@ if (strlen($_GET["create"])) {
|
|||
|
||||
if ($_POST && !$error && !$_POST["add"] && !$_POST["drop_col"] && !$_POST["up"] && !$_POST["down"]) {
|
||||
if ($_POST["drop"]) {
|
||||
if ($mysql->query("DROP TABLE " . idf_escape($_GET["create"]))) {
|
||||
redirect(substr($SELF, 0, -1), lang('Table has been dropped.'));
|
||||
}
|
||||
query_redirect("DROP TABLE " . idf_escape($_GET["create"]), substr($SELF, 0, -1), lang('Table has been dropped.'));
|
||||
} else {
|
||||
$auto_increment_index = " PRIMARY KEY";
|
||||
if (strlen($_GET["create"]) && strlen($_POST["fields"][$_POST["auto_increment_col"]]["orig"])) {
|
||||
|
@ -46,18 +44,13 @@ if ($_POST && !$error && !$_POST["add"] && !$_POST["drop_col"] && !$_POST["up"]
|
|||
. (strlen($_POST["Auto_increment"]) ? " AUTO_INCREMENT=" . intval($_POST["Auto_increment"]) : "")
|
||||
. " COMMENT='" . $mysql->escape_string($_POST["Comment"]) . "'"
|
||||
;
|
||||
$location = $SELF . "table=" . urlencode($_POST["name"]);
|
||||
if (strlen($_GET["create"])) {
|
||||
$query = "ALTER TABLE " . idf_escape($_GET["create"]) . " " . implode(", ", $fields) . ", RENAME TO " . idf_escape($_POST["name"]) . ", $status";
|
||||
$message = lang('Table has been altered.');
|
||||
query_redirect("ALTER TABLE " . idf_escape($_GET["create"]) . " " . implode(", ", $fields) . ", RENAME TO " . idf_escape($_POST["name"]) . ", $status", $location, lang('Table has been altered.'));
|
||||
} else {
|
||||
$query = "CREATE TABLE " . idf_escape($_POST["name"]) . " (" . implode(", ", $fields) . ")$status";
|
||||
$message = lang('Table has been created.');
|
||||
}
|
||||
if ($mysql->query($query)) {
|
||||
redirect($SELF . "table=" . urlencode($_POST["name"]), $message);
|
||||
query_redirect("CREATE TABLE " . idf_escape($_POST["name"]) . " (" . implode(", ", $fields) . ")$status", $location, lang('Table has been created.'));
|
||||
}
|
||||
}
|
||||
$error = $mysql->error;
|
||||
}
|
||||
page_header((strlen($_GET["create"]) ? lang('Alter table') : lang('Create table')), $error, array("table" => $_GET["create"]), $_GET["create"]);
|
||||
|
||||
|
|
|
@ -7,10 +7,10 @@ if ($_POST && !$error) {
|
|||
}
|
||||
$dropped = true;
|
||||
}
|
||||
if (!$_POST["drop"] && $mysql->query("CREATE VIEW " . idf_escape($_POST["name"]) . " AS " . $_POST["select"])) {
|
||||
redirect($SELF . "view=" . urlencode($_POST["name"]), (strlen($_GET["createv"]) ? lang('View has been altered.') : lang('View has been created.')));
|
||||
}
|
||||
$error = $mysql->error;
|
||||
if (!$_POST["drop"]) {
|
||||
query_redirect("CREATE VIEW " . idf_escape($_POST["name"]) . " AS " . $_POST["select"], $SELF . "view=" . urlencode($_POST["name"]), (strlen($_GET["createv"]) ? lang('View has been altered.') : lang('View has been created.')));
|
||||
}
|
||||
}
|
||||
|
||||
page_header((strlen($_GET["createv"]) ? lang('Alter view') : lang('Create view')), $error, array("view" => $_GET["createv"]), $_GET["createv"]);
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
<?php
|
||||
if ($_POST && !$error) {
|
||||
if ($_POST["drop"]) {
|
||||
if ($mysql->query("DROP DATABASE " . idf_escape($_GET["db"]))) {
|
||||
unset($_SESSION["databases"][$_GET["server"]]);
|
||||
redirect(substr(preg_replace('~db=[^&]*&~', '', $SELF), 0, -1), lang('Database has been dropped.'));
|
||||
}
|
||||
unset($_SESSION["databases"][$_GET["server"]]);
|
||||
query_redirect("DROP DATABASE " . idf_escape($_GET["db"]), substr(preg_replace('~db=[^&]*&~', '', $SELF), 0, -1), lang('Database has been dropped.'));
|
||||
} elseif ($_GET["db"] !== $_POST["name"]) {
|
||||
if ($mysql->query("CREATE DATABASE " . idf_escape($_POST["name"]) . ($_POST["collation"] ? " COLLATE '" . $mysql->escape_string($_POST["collation"]) . "'" : ""))) {
|
||||
unset($_SESSION["databases"][$_GET["server"]]);
|
||||
|
@ -23,10 +21,13 @@ if ($_POST && !$error) {
|
|||
redirect(preg_replace('~db=[^&]*&~', '', $SELF) . "db=" . urlencode($_POST["name"]), lang('Database has been renamed.'));
|
||||
}
|
||||
}
|
||||
} elseif (!$_POST["collation"] || $mysql->query("ALTER DATABASE " . idf_escape($_POST["name"]) . " COLLATE '" . $mysql->escape_string($_POST["collation"]) . "'")) {
|
||||
redirect(substr($SELF, 0, -1), ($_POST["collation"] ? lang('Database has been altered.') : null));
|
||||
$error = $mysql->error;
|
||||
} else {
|
||||
if (!$_POST["collation"]) {
|
||||
redirect(substr($SELF, 0, -1));
|
||||
}
|
||||
query_redirect("ALTER DATABASE " . idf_escape($_POST["name"]) . " COLLATE '" . $mysql->escape_string($_POST["collation"]) . "'", substr($SELF, 0, -1), lang('Database has been altered.'));
|
||||
}
|
||||
$error = $mysql->error;
|
||||
}
|
||||
page_header(strlen($_GET["db"]) ? lang('Alter database') : lang('Create database'), $error, array(), $_GET["db"]);
|
||||
|
||||
|
|
23
edit.inc.php
23
edit.inc.php
|
@ -7,12 +7,11 @@ foreach ($fields as $name => $field) {
|
|||
}
|
||||
}
|
||||
if ($_POST && !$error) {
|
||||
$set = array();
|
||||
$location = $SELF . (isset($_GET["default"]) ? "table=" : ($_POST["insert"] ? "edit=" : "select=")) . urlencode($_GET["edit"]);
|
||||
if (isset($_POST["delete"])) {
|
||||
$set = true;
|
||||
$query = "DELETE FROM " . idf_escape($_GET["edit"]) . " WHERE " . implode(" AND ", $where) . " LIMIT 1";
|
||||
$message = lang('Item has been deleted.');
|
||||
query_redirect("DELETE FROM " . idf_escape($_GET["edit"]) . " WHERE " . implode(" AND ", $where) . " LIMIT 1", $location, lang('Item has been deleted.'));
|
||||
} else {
|
||||
$set = array();
|
||||
foreach ($fields as $name => $field) {
|
||||
$val = process_input($name, $field);
|
||||
if ($val !== false) {
|
||||
|
@ -25,21 +24,17 @@ if ($_POST && !$error) {
|
|||
}
|
||||
}
|
||||
}
|
||||
if (!$set) {
|
||||
redirect($location);
|
||||
}
|
||||
if (isset($_GET["default"])) {
|
||||
$query = "ALTER TABLE " . idf_escape($_GET["edit"]) . implode(",", $set);
|
||||
$message = lang('Default values has been set.');
|
||||
query_redirect("ALTER TABLE " . idf_escape($_GET["edit"]) . implode(",", $set), $location, lang('Default values has been set.'));
|
||||
} elseif ($where) {
|
||||
$query = "UPDATE " . idf_escape($_GET["edit"]) . " SET " . implode(", ", $set) . " WHERE " . implode(" AND ", $where) . " LIMIT 1";
|
||||
$message = lang('Item has been updated.');
|
||||
query_redirect("UPDATE " . idf_escape($_GET["edit"]) . " SET " . implode(", ", $set) . " WHERE " . implode(" AND ", $where) . " LIMIT 1", $location, lang('Item has been updated.'));
|
||||
} else {
|
||||
$query = "INSERT INTO " . idf_escape($_GET["edit"]) . " SET " . implode(", ", $set);
|
||||
$message = lang('Item has been inserted.');
|
||||
query_redirect("INSERT INTO " . idf_escape($_GET["edit"]) . " SET " . implode(", ", $set), $location, lang('Item has been inserted.'));
|
||||
}
|
||||
}
|
||||
if (!$set || $mysql->query($query)) {
|
||||
redirect($SELF . (isset($_GET["default"]) ? "table=" : ($_POST["insert"] ? "edit=" : "select=")) . urlencode($_GET["edit"]), ($set ? $message : null));
|
||||
}
|
||||
$error = $mysql->error;
|
||||
}
|
||||
page_header((isset($_GET["default"]) ? lang('Default values') : ($_GET["where"] ? lang('Edit') : lang('Insert'))), $error, array((isset($_GET["default"]) ? "table" : "select") => $_GET["edit"]), $_GET["edit"]);
|
||||
|
||||
|
|
|
@ -3,16 +3,11 @@ $intervals = array("YEAR", "QUARTER", "MONTH", "DAY", "HOUR", "MINUTE", "WEEK",
|
|||
|
||||
if ($_POST && !$error) {
|
||||
if ($_POST["drop"]) {
|
||||
if ($mysql->query("DROP EVENT " . idf_escape($_GET["event"]))) {
|
||||
redirect(substr($SELF, 0, -1), lang('Event has been dropped.'));
|
||||
}
|
||||
query_redirect("DROP EVENT " . idf_escape($_GET["event"]), substr($SELF, 0, -1), lang('Event has been dropped.'));
|
||||
} elseif (in_array($_POST["INTERVAL_FIELD"], $intervals)) {
|
||||
$schedule = " ON SCHEDULE " . ($_POST["INTERVAL_VALUE"] ? "EVERY '" . $mysql->escape_string($_POST["INTERVAL_VALUE"]) . "' $_POST[INTERVAL_FIELD]" . ($_POST["STARTS"] ? " STARTS '" . $mysql->escape_string($_POST["STARTS"]) . "'" : "") . ($_POST["ENDS"] ? " ENDS '" . $mysql->escape_string($_POST["ENDS"]) . "'" : "") : "AT '" . $mysql->escape_string($_POST["STARTS"]) . "'");
|
||||
if ($mysql->query((strlen($_GET["event"]) ? "ALTER EVENT " . idf_escape($_GET["event"]) . $schedule . ($_GET["event"] != $_POST["EVENT_NAME"] ? " RENAME TO " . idf_escape($_POST["EVENT_NAME"]) : "") : "CREATE EVENT " . idf_escape($_POST["EVENT_NAME"]) . $schedule) . " DO $_POST[EVENT_DEFINITION]")) {
|
||||
redirect(substr($SELF, 0, -1), (strlen($_GET["event"]) ? lang('Event has been altered.') : lang('Event has been created.')));
|
||||
}
|
||||
query_redirect((strlen($_GET["event"]) ? "ALTER EVENT " . idf_escape($_GET["event"]) . $schedule . ($_GET["event"] != $_POST["EVENT_NAME"] ? " RENAME TO " . idf_escape($_POST["EVENT_NAME"]) : "") : "CREATE EVENT " . idf_escape($_POST["EVENT_NAME"]) . $schedule) . " DO $_POST[EVENT_DEFINITION]", substr($SELF, 0, -1), (strlen($_GET["event"]) ? lang('Event has been altered.') : lang('Event has been created.')));
|
||||
}
|
||||
$error = $mysql->error;
|
||||
}
|
||||
page_header((strlen($_GET["event"]) ? lang('Alter event') . ": " . htmlspecialchars($_GET["event"]) : lang('Create event')), $error);
|
||||
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
<?php
|
||||
if ($_POST && !$error && !$_POST["add"] && !$_POST["change"] && !$_POST["change-js"]) {
|
||||
if ($_POST["drop"]) {
|
||||
if ($mysql->query("ALTER TABLE " . idf_escape($_GET["foreign"]) . " DROP FOREIGN KEY " . idf_escape($_GET["name"]))) {
|
||||
redirect($SELF . "table=" . urlencode($_GET["foreign"]), lang('Foreign key has been dropped.'));
|
||||
}
|
||||
query_redirect("ALTER TABLE " . idf_escape($_GET["foreign"]) . " DROP FOREIGN KEY " . idf_escape($_GET["name"]), $SELF . "table=" . urlencode($_GET["foreign"]), lang('Foreign key has been dropped.'));
|
||||
} else {
|
||||
$source = array_filter($_POST["source"], 'strlen');
|
||||
ksort($source);
|
||||
|
@ -11,18 +9,13 @@ if ($_POST && !$error && !$_POST["add"] && !$_POST["change"] && !$_POST["change-
|
|||
foreach ($source as $key => $val) {
|
||||
$target[$key] = $_POST["target"][$key];
|
||||
}
|
||||
if ($mysql->query("
|
||||
ALTER TABLE " . idf_escape($_GET["foreign"])
|
||||
. (strlen($_GET["name"]) ? " DROP FOREIGN KEY " . idf_escape($_GET["name"]) . "," : "") . "
|
||||
ADD FOREIGN KEY (" . implode(", ", array_map('idf_escape', $source)) . ")
|
||||
REFERENCES " . idf_escape($_POST["table"]) . " (" . implode(", ", array_map('idf_escape', $target)) . ")"
|
||||
query_redirect("ALTER TABLE " . idf_escape($_GET["foreign"])
|
||||
. (strlen($_GET["name"]) ? " DROP FOREIGN KEY " . idf_escape($_GET["name"]) . "," : "")
|
||||
. " ADD FOREIGN KEY (" . implode(", ", array_map('idf_escape', $source)) . ") REFERENCES " . idf_escape($_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]" : "")
|
||||
)) {
|
||||
redirect($SELF . "table=" . urlencode($_GET["foreign"]), (strlen($_GET["name"]) ? lang('Foreign key has been altered.') : lang('Foreign key has been created.')));
|
||||
}
|
||||
, $SELF . "table=" . urlencode($_GET["foreign"]), (strlen($_GET["name"]) ? lang('Foreign key has been altered.') : lang('Foreign key has been created.')));
|
||||
}
|
||||
$error = $mysql->error;
|
||||
}
|
||||
page_header(lang('Foreign key'), $error, array("table" => $_GET["foreign"]), $_GET["foreign"]);
|
||||
|
||||
|
|
|
@ -195,6 +195,14 @@ function redirect($location, $message = null) {
|
|||
exit;
|
||||
}
|
||||
|
||||
function query_redirect($query, $location, $message) {
|
||||
global $mysql, $error, $SELF;
|
||||
if ($mysql->query($query)) {
|
||||
redirect($location, $message . "<br /><code class='jush-sql'>" . htmlspecialchars($query) . '</code> - <a href="' . htmlspecialchars($SELF) . 'sql=' . urlencode($query) . '">' . lang('edit') . '</a>');
|
||||
}
|
||||
$error = $mysql->error;
|
||||
}
|
||||
|
||||
function remove_from_uri($param = "") {
|
||||
$param = "($param|" . session_name() . ")";
|
||||
return preg_replace("~\\?$param=[^&]*&~", '?', preg_replace("~\\?$param=[^&]*\$|&$param=[^&]*~", '', $_SERVER["REQUEST_URI"]));
|
||||
|
|
|
@ -33,10 +33,10 @@ if ($_POST && !$error && !$_POST["add"]) {
|
|||
foreach ($indexes as $name => $existing) {
|
||||
$alter[] = "DROP INDEX " . idf_escape($name);
|
||||
}
|
||||
if (!$alter || $mysql->query("ALTER TABLE " . idf_escape($_GET["indexes"]) . " " . implode(", ", $alter))) {
|
||||
redirect($SELF . "table=" . urlencode($_GET["indexes"]), ($alter ? lang('Indexes has been altered.') : null));
|
||||
if (!$alter) {
|
||||
redirect($SELF . "table=" . urlencode($_GET["indexes"]));
|
||||
}
|
||||
$error = $mysql->error;
|
||||
query_redirect("ALTER TABLE " . idf_escape($_GET["indexes"]) . " " . implode(", ", $alter), $SELF . "table=" . urlencode($_GET["indexes"]), lang('Indexes has been altered.'));
|
||||
}
|
||||
page_header(lang('Indexes'), $error, array("table" => $_GET["indexes"]), $_GET["indexes"]);
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ if ($_POST && !$error && !$_POST["add"] && !$_POST["drop_col"] && !$_POST["up"]
|
|||
}
|
||||
$dropped = true;
|
||||
}
|
||||
$error = $mysql->error;
|
||||
if (!$_POST["drop"]) {
|
||||
$set = array();
|
||||
$fields = array_filter((array) $_POST["fields"], 'strlen');
|
||||
|
@ -18,16 +19,12 @@ if ($_POST && !$error && !$_POST["add"] && !$_POST["drop_col"] && !$_POST["up"]
|
|||
$set[] = (in_array($field["inout"], $inout) ? "$field[inout] " : "") . idf_escape($field["field"]) . process_type($field, "CHARACTER SET");
|
||||
}
|
||||
}
|
||||
if ($mysql->query(
|
||||
"CREATE $routine " . idf_escape($_POST["name"])
|
||||
query_redirect("CREATE $routine " . idf_escape($_POST["name"])
|
||||
. " (" . implode(", ", $set) . ")"
|
||||
. (isset($_GET["function"]) ? " RETURNS" . process_type($_POST["returns"], "CHARACTER SET") : "") . "
|
||||
$_POST[definition]"
|
||||
)) {
|
||||
redirect(substr($SELF, 0, -1), (strlen($_GET["procedure"]) ? lang('Routine has been altered.') : lang('Routine has been created.')));
|
||||
}
|
||||
. (isset($_GET["function"]) ? " RETURNS" . process_type($_POST["returns"], "CHARACTER SET") : "")
|
||||
. " $_POST[definition]"
|
||||
, substr($SELF, 0, -1), (strlen($_GET["procedure"]) ? lang('Routine has been altered.') : lang('Routine has been created.')));
|
||||
}
|
||||
$error = $mysql->error;
|
||||
}
|
||||
page_header((strlen($_GET["procedure"]) ? (isset($_GET["function"]) ? lang('Alter function') : lang('Alter procedure')) . ": " . htmlspecialchars($_GET["procedure"]) : (isset($_GET["function"]) ? lang('Create function') : lang('Create procedure'))), $error);
|
||||
|
||||
|
|
1
todo.txt
1
todo.txt
|
@ -11,5 +11,6 @@ Transactions in export
|
|||
Compress export and import
|
||||
Partitioning (MySQL 5.1)
|
||||
Create view options
|
||||
Utilize query_redirect - createv, database, procedure, trigger, select
|
||||
? Execution time in sql.inc.php
|
||||
? Save token also to cookie - for session expiration and login in other window
|
||||
|
|
|
@ -10,14 +10,12 @@ if ($_POST && !$error) {
|
|||
}
|
||||
$dropped = true;
|
||||
}
|
||||
$error = $mysql->error;
|
||||
if (!$_POST["drop"]) {
|
||||
if (in_array($_POST["Timing"], $trigger_time) && in_array($_POST["Event"], $trigger_event) && $mysql->query(
|
||||
"CREATE TRIGGER " . idf_escape($_POST["Trigger"]) . " $_POST[Timing] $_POST[Event] ON " . idf_escape($_GET["trigger"]) . " FOR EACH ROW $_POST[Statement]"
|
||||
)) {
|
||||
redirect($SELF . "table=" . urlencode($_GET["trigger"]), (strlen($_GET["name"]) ? lang('Trigger has been altered.') : lang('Trigger has been created.')));
|
||||
if (in_array($_POST["Timing"], $trigger_time) && in_array($_POST["Event"], $trigger_event)) {
|
||||
query_redirect("CREATE TRIGGER " . idf_escape($_POST["Trigger"]) . " $_POST[Timing] $_POST[Event] ON " . idf_escape($_GET["trigger"]) . " FOR EACH ROW $_POST[Statement]", $SELF . "table=" . urlencode($_GET["trigger"]), (strlen($_GET["name"]) ? lang('Trigger has been altered.') : lang('Trigger has been created.')));
|
||||
}
|
||||
}
|
||||
$error = $mysql->error;
|
||||
}
|
||||
page_header((strlen($_GET["name"]) ? lang('Alter trigger') . ": " . htmlspecialchars($_GET["name"]) : lang('Create trigger')), $error, array("table" => $_GET["trigger"]));
|
||||
|
||||
|
|
|
@ -68,9 +68,7 @@ if ($_POST && !$error) {
|
|||
$new_user = $mysql->escape_string($_POST["user"]) . "'@'" . $mysql->escape_string($_POST["host"]);
|
||||
$pass = $mysql->escape_string($_POST["pass"]);
|
||||
if ($_POST["drop"]) {
|
||||
if ($mysql->query("DROP USER '$old_user'")) {
|
||||
redirect($SELF . "privileges=", lang('User has been dropped.'));
|
||||
}
|
||||
query_redirect("DROP USER '$old_user'", $SELF . "privileges=", lang('User has been dropped.'));
|
||||
} elseif ($old_user == $new_user || $mysql->query(($mysql->server_info < 5 ? "GRANT USAGE ON *.* TO" : "CREATE USER") . " '$new_user' IDENTIFIED BY" . ($_POST["hashed"] ? " PASSWORD" : "") . " '$pass'")) {
|
||||
if ($old_user == $new_user) {
|
||||
$mysql->query("SET PASSWORD FOR '$new_user' = " . ($_POST["hashed"] ? "'$pass'" : "PASSWORD('$pass')"));
|
||||
|
|
Loading…
Reference in a new issue