Permalink
Browse files

Print SQL command with multiple queries

git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@482 7c3ca157-0c34-0410-bff1-cbf682f78f5c
  • Loading branch information...
1 parent c2b7e0e commit 748ee836ca7543d0ac0f7a31753cc475ab395233 jakubvrana committed Sep 3, 2008
Showing with 24 additions and 18 deletions.
  1. +2 −3 database.inc.php
  2. +16 −3 functions.inc.php
  3. +2 −5 processlist.inc.php
  4. +4 −7 select.inc.php
View
@@ -8,16 +8,15 @@
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]))) {
+ if (!queries("RENAME TABLE " . idf_escape($row[0]) . " TO " . idf_escape($_POST["name"]) . "." . idf_escape($row[0]))) {
break;
}
}
$result->free();
if (!$row) {
$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);
+ query_redirect(queries(), preg_replace('~db=[^&]*&~', '', $SELF) . "db=" . urlencode($_POST["name"]), lang('Database has been renamed.'), !$row, false, $row);
}
} else {
if (!$_POST["collation"]) {
View
@@ -195,11 +195,14 @@ function redirect($location, $message = null) {
exit;
}
-function query_redirect($query, $location, $message, $redirect = true, $execute = true) {
+function query_redirect($query, $location, $message, $redirect = true, $execute = true, $failed = false) {
global $mysql, $error, $SELF;
$id = "sql-" . count($_SESSION["messages"]);
- $sql = " <a href='#$id' onclick=\"return !toggle('$id');\">" . lang('SQL command') . "</a><span id='$id' class='hidden'><br /><code class='jush-sql'>" . htmlspecialchars($query) . '</code> <a href="' . htmlspecialchars($SELF) . 'sql=' . urlencode($query) . '">' . lang('Edit') . '</a></span>';
- if ($execute && !$mysql->query($query)) {
+ $sql = ($query ? " <a href='#$id' onclick=\"return !toggle('$id');\">" . lang('SQL command') . "</a><span id='$id' class='hidden'><br /><code class='jush-sql'>" . htmlspecialchars($query) . '</code> <a href="' . htmlspecialchars($SELF) . 'sql=' . urlencode($query) . '">' . lang('Edit') . '</a></span>' : "");
+ if ($execute) {
+ $failed = !$mysql->query($query);
+ }
+ if ($failed) {
$error = htmlspecialchars($mysql->error) . $sql;
return false;
}
@@ -209,6 +212,16 @@ function query_redirect($query, $location, $message, $redirect = true, $execute
return true;
}
+function queries($query = null) {
+ global $mysql;
+ static $queries = array();
+ if (!isset($query)) {
+ return implode("\n", $queries);
+ }
+ $queries[] = $query;
+ return $mysql->query($query);
+}
+
function remove_from_uri($param = "") {
$param = "($param|" . session_name() . ")";
return preg_replace("~\\?$param=[^&]*&~", '?', preg_replace("~\\?$param=[^&]*\$|&$param=[^&]*~", '', $_SERVER["REQUEST_URI"]));
View
@@ -2,14 +2,11 @@
if ($_POST && !$error) {
$killed = 0;
foreach ((array) $_POST["kill"] as $val) {
- if ($mysql->query("KILL " . intval($val))) {
+ if (queries("KILL " . intval($val))) {
$killed++;
}
}
- if ($killed || !$_POST["kill"]) {
- redirect($SELF . "processlist=", lang('%d process(es) has been killed.', $killed));
- }
- $error = htmlspecialchars($mysql->error);
+ query_redirect(queries(), $SELF . "processlist=", lang('%d process(es) has been killed.', $killed), $killed || !$_POST["kill"], false, !$killed && $_POST["kill"]);
}
page_header(lang('Process list'), $error);
?>
View
@@ -66,7 +66,7 @@
dump_table($_GET["select"], "");
}
if (isset($_POST["truncate"])) {
- $result = $mysql->query($where ? "DELETE FROM " . idf_escape($_GET["select"]) . " WHERE " . implode(" AND ", $where) : "TRUNCATE " . idf_escape($_GET["select"]));
+ $result = queries($where ? "DELETE FROM " . idf_escape($_GET["select"]) . " WHERE " . implode(" AND ", $where) : "TRUNCATE " . idf_escape($_GET["select"]));
$deleted = $mysql->affected_rows;
} elseif ($_POST["export_result"]) {
dump_data($_GET["select"], "INSERT", ($where ? "FROM " . idf_escape($_GET["select"]) . " WHERE " . implode(" AND ", $where) : ""));
@@ -76,7 +76,7 @@
if ($_POST["export"]) {
dump_data($_GET["select"], "INSERT", "FROM " . idf_escape($_GET["select"]) . " WHERE " . implode(" AND ", where($delete)) . " LIMIT 1");
} else {
- $result = $mysql->query("DELETE FROM " . idf_escape($_GET["select"]) . " WHERE " . implode(" AND ", where($delete)) . " LIMIT 1");
+ $result = queries("DELETE FROM " . idf_escape($_GET["select"]) . " WHERE " . implode(" AND ", where($delete)) . " LIMIT 1");
if (!$result) {
break;
}
@@ -90,7 +90,7 @@
$result1 = $mysql->query("SELECT * $from");
while ($row1 = $result1->fetch_assoc()) {
parse_str(implode("&", unique_idf($row1, $indexes)), $delete);
- $result = $mysql->query("DELETE FROM " . idf_escape($_GET["select"]) . " WHERE " . implode(" AND ", where($delete)) . " LIMIT 1");
+ $result = queries("DELETE FROM " . idf_escape($_GET["select"]) . " WHERE " . implode(" AND ", where($delete)) . " LIMIT 1");
if (!$result) {
break;
}
@@ -102,10 +102,7 @@
if ($_POST["export"] || $_POST["export_result"]) {
exit;
}
- if ($result) {
- redirect(remove_from_uri("page"), lang('%d item(s) have been deleted.', $deleted));
- }
- $error = htmlspecialchars($mysql->error);
+ query_redirect(queries(), remove_from_uri("page"), lang('%d item(s) have been deleted.', $deleted), $result, false, !$result);
}
page_header(lang('Select') . ": " . htmlspecialchars($_GET["select"]), ($error ? lang('Error during deleting') . ": $error" : ""));

0 comments on commit 748ee83

Please sign in to comment.