]> git.joonet.de Git - adminer.git/commitdiff
Print SQL command with multiple queries
authorjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Wed, 3 Sep 2008 13:55:43 +0000 (13:55 +0000)
committerjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Wed, 3 Sep 2008 13:55:43 +0000 (13:55 +0000)
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@482 7c3ca157-0c34-0410-bff1-cbf682f78f5c

database.inc.php
functions.inc.php
processlist.inc.php
select.inc.php

index 776960b0a8690f0e314245dadffcdcd31e71315f..2775968549220025d76af4c398678658cad14bde 100644 (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"]))) {
                        $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"]) {
index 33cd8726b475e32184da289fdc9990ff9144bbc5..18de4993336cc89ebb3d67a6630dbf70daa108be 100644 (file)
@@ -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"]));
index 4175f151a74f39476f6b2a32cc2a4b48612e16be..683cfda0690dfdf71fceb8e3caed653cab988379 100644 (file)
@@ -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);
 ?>
index ef39cc2d3e01c6ec42d23a3e8ec234a40fc3d6c1..ccf75a68f4d7dcbc93ae102409e9722d291ee814 100644 (file)
@@ -66,7 +66,7 @@ if ($_POST && !$error) {
                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 && !$error) {
                        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 @@ if ($_POST && !$error) {
                        $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 && !$error) {
        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" : ""));