Permalink
Browse files

Print SQL query by error

git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@479 7c3ca157-0c34-0410-bff1-cbf682f78f5c
  • Loading branch information...
1 parent c463946 commit c48a017e0eb2ddb53e8b10d712619ec7e4f639e8 jakubvrana committed Sep 2, 2008
Showing with 26 additions and 36 deletions.
  1. +2 −6 createv.inc.php
  2. +3 −6 database.inc.php
  3. +2 −2 design.inc.php
  4. +9 −4 functions.inc.php
  5. +2 −6 procedure.inc.php
  6. +1 −1 processlist.inc.php
  7. +1 −1 select.inc.php
  8. +1 −1 table.inc.php
  9. +1 −1 todo.txt
  10. +2 −6 trigger.inc.php
  11. +2 −2 user.inc.php
View
@@ -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
@@ -4,11 +4,8 @@
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 @@
$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
@@ -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
@@ -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
@@ -3,13 +3,9 @@
$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
@@ -9,7 +9,7 @@
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
@@ -105,7 +105,7 @@
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
@@ -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
@@ -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
@@ -4,13 +4,9 @@
$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
@@ -91,7 +91,7 @@ function all_privileges(&$grants, $privileges) {
($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 @@ function all_privileges(&$grants, $privileges) {
}
}
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')));

0 comments on commit c48a017

Please sign in to comment.