1
0
mirror of https://github.com/vrana/adminer.git synced 2025-08-16 19:44:00 +02:00

Print SQL command with multiple queries

git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@482 7c3ca157-0c34-0410-bff1-cbf682f78f5c
This commit is contained in:
jakubvrana
2008-09-03 13:55:43 +00:00
parent c2b7e0e15d
commit 748ee836ca
4 changed files with 24 additions and 18 deletions

View File

@@ -8,16 +8,15 @@ if ($_POST && !$error) {
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"]))) { 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"); $result = $mysql->query("SHOW TABLES");
while ($row = $result->fetch_row()) { 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; break;
} }
} }
$result->free(); $result->free();
if (!$row) { if (!$row) {
$mysql->query("DROP DATABASE " . idf_escape($_GET["db"])); $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 { } else {
if (!$_POST["collation"]) { if (!$_POST["collation"]) {

View File

@@ -195,11 +195,14 @@ function redirect($location, $message = null) {
exit; 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; global $mysql, $error, $SELF;
$id = "sql-" . count($_SESSION["messages"]); $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>'; $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 && !$mysql->query($query)) { if ($execute) {
$failed = !$mysql->query($query);
}
if ($failed) {
$error = htmlspecialchars($mysql->error) . $sql; $error = htmlspecialchars($mysql->error) . $sql;
return false; return false;
} }
@@ -209,6 +212,16 @@ function query_redirect($query, $location, $message, $redirect = true, $execute
return true; 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 = "") { function remove_from_uri($param = "") {
$param = "($param|" . session_name() . ")"; $param = "($param|" . session_name() . ")";
return preg_replace("~\\?$param=[^&]*&~", '?', preg_replace("~\\?$param=[^&]*\$|&$param=[^&]*~", '', $_SERVER["REQUEST_URI"])); return preg_replace("~\\?$param=[^&]*&~", '?', preg_replace("~\\?$param=[^&]*\$|&$param=[^&]*~", '', $_SERVER["REQUEST_URI"]));

View File

@@ -2,14 +2,11 @@
if ($_POST && !$error) { if ($_POST && !$error) {
$killed = 0; $killed = 0;
foreach ((array) $_POST["kill"] as $val) { foreach ((array) $_POST["kill"] as $val) {
if ($mysql->query("KILL " . intval($val))) { if (queries("KILL " . intval($val))) {
$killed++; $killed++;
} }
} }
if ($killed || !$_POST["kill"]) { query_redirect(queries(), $SELF . "processlist=", lang('%d process(es) has been killed.', $killed), $killed || !$_POST["kill"], false, !$killed && $_POST["kill"]);
redirect($SELF . "processlist=", lang('%d process(es) has been killed.', $killed));
}
$error = htmlspecialchars($mysql->error);
} }
page_header(lang('Process list'), $error); page_header(lang('Process list'), $error);
?> ?>

View File

@@ -66,7 +66,7 @@ if ($_POST && !$error) {
dump_table($_GET["select"], ""); dump_table($_GET["select"], "");
} }
if (isset($_POST["truncate"])) { 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; $deleted = $mysql->affected_rows;
} elseif ($_POST["export_result"]) { } elseif ($_POST["export_result"]) {
dump_data($_GET["select"], "INSERT", ($where ? "FROM " . idf_escape($_GET["select"]) . " WHERE " . implode(" AND ", $where) : "")); dump_data($_GET["select"], "INSERT", ($where ? "FROM " . idf_escape($_GET["select"]) . " WHERE " . implode(" AND ", $where) : ""));
@@ -76,7 +76,7 @@ if ($_POST && !$error) {
if ($_POST["export"]) { if ($_POST["export"]) {
dump_data($_GET["select"], "INSERT", "FROM " . idf_escape($_GET["select"]) . " WHERE " . implode(" AND ", where($delete)) . " LIMIT 1"); dump_data($_GET["select"], "INSERT", "FROM " . idf_escape($_GET["select"]) . " WHERE " . implode(" AND ", where($delete)) . " LIMIT 1");
} else { } 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) { if (!$result) {
break; break;
} }
@@ -90,7 +90,7 @@ if ($_POST && !$error) {
$result1 = $mysql->query("SELECT * $from"); $result1 = $mysql->query("SELECT * $from");
while ($row1 = $result1->fetch_assoc()) { while ($row1 = $result1->fetch_assoc()) {
parse_str(implode("&", unique_idf($row1, $indexes)), $delete); 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) { if (!$result) {
break; break;
} }
@@ -102,10 +102,7 @@ if ($_POST && !$error) {
if ($_POST["export"] || $_POST["export_result"]) { if ($_POST["export"] || $_POST["export_result"]) {
exit; exit;
} }
if ($result) { query_redirect(queries(), remove_from_uri("page"), lang('%d item(s) have been deleted.', $deleted), $result, false, !$result);
redirect(remove_from_uri("page"), lang('%d item(s) have been deleted.', $deleted));
}
$error = htmlspecialchars($mysql->error);
} }
page_header(lang('Select') . ": " . htmlspecialchars($_GET["select"]), ($error ? lang('Error during deleting') . ": $error" : "")); page_header(lang('Select') . ": " . htmlspecialchars($_GET["select"]), ($error ? lang('Error during deleting') . ": $error" : ""));