From 2adc1745412b16137392d86a5f4dd0e09d44a184 Mon Sep 17 00:00:00 2001 From: Jakub Vrana Date: Wed, 31 Jan 2018 17:28:12 +0100 Subject: [PATCH] MySQL: Display warnings in SQL command --- adminer/drivers/mysql.inc.php | 4 ++ adminer/include/driver.inc.php | 13 +++++ adminer/include/functions.inc.php | 2 +- adminer/include/version.inc.php | 2 +- adminer/lang/cs.inc.php | 1 + adminer/lang/xx.inc.php | 1 + adminer/sql.inc.php | 84 ++++++++++++++++++------------- changes.txt | 3 +- 8 files changed, 71 insertions(+), 39 deletions(-) diff --git a/adminer/drivers/mysql.inc.php b/adminer/drivers/mysql.inc.php index cbeda2c8..8eba872c 100644 --- a/adminer/drivers/mysql.inc.php +++ b/adminer/drivers/mysql.inc.php @@ -276,6 +276,10 @@ if (!defined("DRIVER")) { } return queries($prefix . implode(",\n", $values) . $suffix); } + + function warnings() { + return $this->_conn->query("SHOW WARNINGS"); + } } diff --git a/adminer/include/driver.inc.php b/adminer/include/driver.inc.php index 3be05dff..37ef47e5 100644 --- a/adminer/include/driver.inc.php +++ b/adminer/include/driver.inc.php @@ -99,12 +99,25 @@ return queries("BEGIN"); } + /** Commit transaction + * @return bool + */ function commit() { return queries("COMMIT"); } + /** Rollback transaction + * @return bool + */ function rollback() { return queries("ROLLBACK"); } + /** Get warnings about the last command + * @return resource or false + */ + function warnings() { + return false; + } + } diff --git a/adminer/include/functions.inc.php b/adminer/include/functions.inc.php index 5bff85c5..30eb1e91 100644 --- a/adminer/include/functions.inc.php +++ b/adminer/include/functions.inc.php @@ -415,7 +415,7 @@ function get_key_vals($query, $connection2 = null, $timeout = 0, $set_keys = tru * @param string * @param Min_DB * @param string -* @return array associative +* @return array of associative arrays */ function get_rows($query, $connection2 = null, $error = "

") { global $connection; diff --git a/adminer/include/version.inc.php b/adminer/include/version.inc.php index e1a68694..d622ca07 100644 --- a/adminer/include/version.inc.php +++ b/adminer/include/version.inc.php @@ -1,2 +1,2 @@ array('Příkaz proběhl v pořádku, byl změněn %d záznam.', 'Příkaz proběhl v pořádku, byly změněny %d záznamy.', 'Příkaz proběhl v pořádku, bylo změněno %d záznamů.'), 'No commands to execute.' => 'Žádné příkazy k vykonání.', 'Error in query' => 'Chyba v dotazu', + 'Warnings' => 'Varování', 'ATTACH queries are not supported.' => 'Dotazy ATTACH nejsou podporované.', 'Execute' => 'Provést', 'Stop on error' => 'Zastavit při chybě', diff --git a/adminer/lang/xx.inc.php b/adminer/lang/xx.inc.php index cad1d58e..987e09cb 100644 --- a/adminer/lang/xx.inc.php +++ b/adminer/lang/xx.inc.php @@ -52,6 +52,7 @@ $translations = array( 'Query executed OK, %d row(s) affected.' => array('Xx, %d.', 'Xx, %d.'), 'No commands to execute.' => 'Xx.', 'Error in query' => 'Xx', + 'Warnings' => 'Xx', 'ATTACH queries are not supported.' => 'Xx.', 'Execute' => 'Xx', 'Stop on error' => 'Xx', diff --git a/adminer/sql.inc.php b/adminer/sql.inc.php index 408ac591..c7ca3d50 100644 --- a/adminer/sql.inc.php +++ b/adminer/sql.inc.php @@ -117,9 +117,6 @@ if (!$error && $_POST) { do { $result = $connection->store_result(); - $time = " (" . format_time($start) . ")" - . (strlen($q) < 1000 ? " " . lang('Edit') . "" : "") // 1000 - maximum length of encoded URL in IE is 2083 characters - ; if ($connection->error) { echo ($_POST["only_errors"] ? $print : ""); @@ -129,41 +126,56 @@ if (!$error && $_POST) { break 2; } - } elseif (is_object($result)) { - $limit = $_POST["limit"]; - $orgtables = select($result, $connection2, array(), $limit); - if (!$_POST["only_errors"]) { - echo "

\n"; - $num_rows = $result->num_rows; - echo "

" . ($num_rows ? ($limit && $num_rows > $limit ? lang('%d / ', $limit) : "") . lang('%d row(s)', $num_rows) : ""); - echo $time; - $id = "export-$commands"; - $export = ", " . lang('Export') . "" . script("qsl('a').onclick = partial(toggle, '$id');", "") . "\n" - ; - if ($connection2 && preg_match("~^($space|\\()*+SELECT\\b~i", $q) && ($explain = explain($connection2, $q))) { - $id = "explain-$commands"; - echo ", EXPLAIN" . script("qsl('a').onclick = partial(toggle, '$id');", "") . $export; - echo "

\n"; - } else { - echo $export; - } - echo "
\n"; - } - } else { - if (preg_match("~^$space*+(CREATE|DROP|ALTER)$space++(DATABASE|SCHEMA)\\b~i", $q)) { - restart_session(); - set_session("dbs", null); // clear cache - stop_session(); + $time = " (" . format_time($start) . ")" + . (strlen($q) < 1000 ? " " . lang('Edit') . "" : "") // 1000 - maximum length of encoded URL in IE is 2083 characters + ; + $warnings = $driver->warnings(); + $warnings_id = "warnings-$commands"; + if ($warnings && $warnings->num_rows) { + $time .= ", " . lang('Warnings') . "" . script("qsl('a').onclick = partial(toggle, '$warnings_id');", ""); } - if (!$_POST["only_errors"]) { - echo "

" . lang('Query executed OK, %d row(s) affected.', $connection->affected_rows) . "$time\n"; + if (is_object($result)) { + $limit = $_POST["limit"]; + $orgtables = select($result, $connection2, array(), $limit); + if (!$_POST["only_errors"]) { + echo "

\n"; + $num_rows = $result->num_rows; + echo "

" . ($num_rows ? ($limit && $num_rows > $limit ? lang('%d / ', $limit) : "") . lang('%d row(s)', $num_rows) : ""); + echo $time; + $id = "export-$commands"; + $export = ", " . lang('Export') . "" . script("qsl('a').onclick = partial(toggle, '$id');", "") . "\n" + ; + if ($connection2 && preg_match("~^($space|\\()*+SELECT\\b~i", $q) && ($explain = explain($connection2, $q))) { + $id = "explain-$commands"; + echo ", EXPLAIN" . script("qsl('a').onclick = partial(toggle, '$id');", "") . $export; + echo "

\n"; + } else { + echo $export; + } + echo "
\n"; + } + + } else { + if (preg_match("~^$space*+(CREATE|DROP|ALTER)$space++(DATABASE|SCHEMA)\\b~i", $q)) { + restart_session(); + set_session("dbs", null); // clear cache + stop_session(); + } + if (!$_POST["only_errors"]) { + echo "

" . lang('Query executed OK, %d row(s) affected.', $connection->affected_rows) . "$time\n"; + } + } + if ($warnings && $warnings->num_rows && (!$_POST["only_errors"] || is_object($result))) { + echo "

\n"; } } diff --git a/changes.txt b/changes.txt index 9c7ac54c..1cc6ea06 100644 --- a/changes.txt +++ b/changes.txt @@ -1,8 +1,9 @@ -Adminer 4.5.1-dev: +Adminer 4.6.0-dev: Fix counting selected rows after going back to select page PHP <5.3 compatibility even with Elasticsearch enabled Fully support functions in default values Stop redirecting links via adminer.org +MySQL: Display warnings in SQL command MariaDB: Support JSON since MariaDB 10.2 PostgreSQL: Support functions PostgreSQL: Allow editing views with uppercase letters (bug #467)