1
0
mirror of https://github.com/vrana/adminer.git synced 2025-08-11 17:14:07 +02:00

Print SQL query by error

git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@479 7c3ca157-0c34-0410-bff1-cbf682f78f5c
This commit is contained in:
jakubvrana
2008-09-02 12:39:04 +00:00
parent c463946e20
commit c48a017e0e
11 changed files with 26 additions and 36 deletions

View File

@@ -1,13 +1,9 @@
<?php
$dropped = false;
if ($_POST && !$error) {
if (strlen($_GET["createv"]) && ($_POST["dropped"] || $mysql->query("DROP VIEW " . idf_escape($_GET["createv"])))) {
if ($_POST["drop"]) {
redirect(substr($SELF, 0, -1), lang('View has been dropped.'));
}
$dropped = true;
if (strlen($_GET["createv"])) {
$dropped = query_redirect("DROP VIEW " . idf_escape($_GET["createv"]), substr($SELF, 0, -1), lang('View has been dropped.'), $_POST["drop"], !$_POST["dropped"]);
}
$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.')));
}

View File

@@ -4,11 +4,8 @@ if ($_POST && !$error) {
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"]]);
if (!strlen($_GET["db"])) {
redirect($SELF . "db=" . urlencode($_POST["name"]), lang('Database has been created.'));
}
unset($_SESSION["databases"][$_GET["server"]]);
if (query_redirect("CREATE DATABASE " . idf_escape($_POST["name"]) . ($_POST["collation"] ? " COLLATE '" . $mysql->escape_string($_POST["collation"]) . "'" : ""), $SELF . "db=" . urlencode($_POST["name"]), lang('Database has been created.'), !strlen($_GET["db"]))) {
$result = $mysql->query("SHOW TABLES");
while ($row = $result->fetch_row()) {
if (!$mysql->query("RENAME TABLE " . idf_escape($row[0]) . " TO " . idf_escape($_POST["name"]) . "." . idf_escape($row[0]))) {
@@ -20,8 +17,8 @@ if ($_POST && !$error) {
$mysql->query("DROP DATABASE " . idf_escape($_GET["db"]));
redirect(preg_replace('~db=[^&]*&~', '', $SELF) . "db=" . urlencode($_POST["name"]), lang('Database has been renamed.'));
}
$error = htmlspecialchars($mysql->error);
}
$error = $mysql->error;
} else {
if (!$_POST["collation"]) {
redirect(substr($SELF, 0, -1));

View File

@@ -35,7 +35,7 @@ function page_header($title, $error = "", $breadcrumb = array(), $title2 = "") {
}
echo "<h2>$title" . (strlen($title2) ? ": " . htmlspecialchars($title2) : "") . "</h2>\n";
if ($_SESSION["messages"]) {
echo "<p class='message'>" . implode("<br />", $_SESSION["messages"]) . "</p>\n";
echo "<p class='message'>" . implode("</p>\n<p class='message'>", $_SESSION["messages"]) . "</p>\n";
$_SESSION["messages"] = array();
}
if (!$_SESSION["tokens"][$_GET["server"]]["?logout"]) {
@@ -45,7 +45,7 @@ function page_header($title, $error = "", $breadcrumb = array(), $title2 = "") {
session_write_close();
}
if ($error) {
echo "<p class='error'>" . htmlspecialchars($error) . "</p>\n";
echo "<p class='error'>$error</p>\n";
}
}

View File

@@ -195,12 +195,17 @@ function redirect($location, $message = null) {
exit;
}
function query_redirect($query, $location, $message) {
function query_redirect($query, $location, $message, $redirect = true, $execute = true) {
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>');
$sql = ' <a href="' . htmlspecialchars($SELF) . 'sql=' . urlencode($query) . '">' . lang('SQL command') . "</a>";
if ($execute && !$mysql->query($query)) {
$error = htmlspecialchars($mysql->error) . $sql;
return false;
}
$error = $mysql->error;
if ($redirect) {
redirect($location, $message . $sql);
}
return true;
}
function remove_from_uri($param = "") {

View File

@@ -3,13 +3,9 @@ $routine = (isset($_GET["function"]) ? "FUNCTION" : "PROCEDURE");
$dropped = false;
if ($_POST && !$error && !$_POST["add"] && !$_POST["drop_col"] && !$_POST["up"] && !$_POST["down"]) {
if (strlen($_GET["procedure"]) && ($_POST["dropped"] || $mysql->query("DROP $routine " . idf_escape($_GET["procedure"])))) {
if ($_POST["drop"]) {
redirect(substr($SELF, 0, -1), lang('Routine has been dropped.'));
}
$dropped = true;
if (strlen($_GET["procedure"])) {
$dropped = query_redirect("DROP $routine " . idf_escape($_GET["procedure"]), substr($SELF, 0, -1), lang('Routine has been dropped.'), $_POST["drop"], !$_POST["dropped"]);
}
$error = $mysql->error;
if (!$_POST["drop"]) {
$set = array();
$fields = array_filter((array) $_POST["fields"], 'strlen');

View File

@@ -9,7 +9,7 @@ if ($_POST && !$error) {
if ($killed || !$_POST["kill"]) {
redirect($SELF . "processlist=", lang('%d process(es) has been killed.', $killed));
}
$error = $mysql->error;
$error = htmlspecialchars($mysql->error);
}
page_header(lang('Process list'), $error);
?>

View File

@@ -105,7 +105,7 @@ if ($_POST && !$error) {
if ($result) {
redirect(remove_from_uri("page"), lang('%d item(s) have been deleted.', $deleted));
}
$error = $mysql->error;
$error = htmlspecialchars($mysql->error);
}
page_header(lang('Select') . ": " . htmlspecialchars($_GET["select"]), ($error ? lang('Error during deleting') . ": $error" : ""));

View File

@@ -1,7 +1,7 @@
<?php
$result = $mysql->query("SHOW COLUMNS FROM " . idf_escape($_GET["table"]));
if (!$result) {
$error = $mysql->error;
$error = htmlspecialchars($mysql->error);
}
page_header(lang('Table') . ": " . htmlspecialchars($_GET["table"]), $error);

View File

@@ -11,6 +11,6 @@ Transactions in export
Compress export and import
Partitioning (MySQL 5.1)
Create view options
Utilize query_redirect - createv, database, procedure, trigger, select
Utilize query_redirect - select
? Execution time in sql.inc.php
? Save token also to cookie - for session expiration and login in other window

View File

@@ -4,13 +4,9 @@ $trigger_event = array("INSERT", "UPDATE", "DELETE");
$dropped = false;
if ($_POST && !$error) {
if (strlen($_GET["name"]) && ($_POST["dropped"] || $mysql->query("DROP TRIGGER " . idf_escape($_GET["name"])))) {
if ($_POST["drop"]) {
redirect($SELF . "table=" . urlencode($_GET["trigger"]), lang('Trigger has been dropped.'));
}
$dropped = true;
if (strlen($_GET["name"])) {
$dropped = query_redirect("DROP TRIGGER " . idf_escape($_GET["name"]), $SELF . "table=" . urlencode($_GET["trigger"]), lang('Trigger has been dropped.'), $_POST["drop"], !$_POST["dropped"]);
}
$error = $mysql->error;
if (!$_POST["drop"]) {
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.')));

View File

@@ -91,7 +91,7 @@ if ($_POST && !$error) {
($grant && !$mysql->query("GRANT " . implode("$match[2], ", $grant) . "$match[2] ON $match[1] TO '$new_user'")) //! SQL injection
|| ($revoke && !$mysql->query("REVOKE " . implode("$match[2], ", $revoke) . "$match[2] ON $match[1] FROM '$new_user'"))
)) {
$error = $mysql->error;
$error = htmlspecialchars($mysql->error);
if ($old_user != $new_user) {
$mysql->query("DROP USER '$new_user'");
}
@@ -112,7 +112,7 @@ if ($_POST && !$error) {
}
}
if (!$error) {
$error = $mysql->error;
$error = htmlspecialchars($mysql->error);
}
}
page_header((isset($_GET["host"]) ? lang('Username') . ": " . htmlspecialchars("$_GET[user]@$_GET[host]") : lang('Create user')), $error, array("privileges" => lang('Privileges')));