From 9eced7872d62fd043b99ceead42dcd8cadd845f2 Mon Sep 17 00:00:00 2001 From: Jakub Vrana Date: Fri, 17 Dec 2010 18:11:06 +0100 Subject: [PATCH] Display total time in show only errors mode in SQL command --- adminer/include/editing.inc.php | 9 +++++++++ adminer/sql.inc.php | 7 ++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/adminer/include/editing.inc.php b/adminer/include/editing.inc.php index d51e5ed6..efb637e4 100644 --- a/adminer/include/editing.inc.php +++ b/adminer/include/editing.inc.php @@ -108,6 +108,15 @@ function textarea($name, $value, $rows = 10, $cols = 80) { echo ""; // spellcheck - not valid before HTML5 } +/** Format time difference +* @param array ($sec, $sec) +* @param array ($sec, $sec) +* @return string HTML code +*/ +function format_time($start, $end) { + return " (" . lang('%.3f s', max(0, $end[0] - $start[0] + $end[1] - $start[1])) . ")"; +} + /** Print table columns for type edit * @param string * @param array diff --git a/adminer/sql.inc.php b/adminer/sql.inc.php index 299c2cca..48c8fbe8 100644 --- a/adminer/sql.inc.php +++ b/adminer/sql.inc.php @@ -42,6 +42,7 @@ if (!$error && $_POST) { $commands = 0; $errors = array(); $parse = '[\'`"]' . ($jush == "pgsql" ? '|\\$[^$]*\\$' : ($jush == "mssql" || $jush == "sqlite" ? '|\\[' : '')) . '|/\\*|-- |#'; //! ` and # not everywhere + $total_start = explode(" ", microtime()); while ($query != "") { if (!$offset && $jush == "sql" && preg_match('~^\\s*DELIMITER\\s+(.+)~i', $query, $match)) { $delimiter = $match[1]; @@ -85,7 +86,7 @@ if (!$error && $_POST) { do { $result = $connection->store_result(); $end = explode(" ", microtime()); - $time = " (" . lang('%.3f s', max(0, $end[0] - $start[0] + $end[1] - $start[1])) . ")" . (strlen($q) < 1000 ? " " . lang('Edit') . "" : ""); // 1000 - maximum length of encoded URL in IE is 2083 characters + $time = format_time($start, $end) . (strlen($q) < 1000 ? " " . lang('Edit') . "" : ""); // 1000 - maximum length of encoded URL in IE is 2083 characters if (!is_object($result)) { if (preg_match("~^$space*(CREATE|DROP|ALTER)$space+(DATABASE|SCHEMA)\\b~isU", $q)) { restart_session(); @@ -129,7 +130,7 @@ if (!$error && $_POST) { if ($empty) { echo "

" . lang('No commands to execute.') . "\n"; } elseif ($_POST["only_errors"]) { - echo "

" . lang('%d query(s) executed OK.', $commands - count($errors)) . "\n"; + echo "

" . lang('%d query(s) executed OK.', $commands - count($errors)) . format_time($total_start, explode(" ", microtime())) . "\n"; } elseif ($errors && $commands > 1) { echo "

" . lang('Error in query') . ": " . implode("", $errors) . "\n"; } @@ -146,7 +147,7 @@ $q = $_GET["sql"]; // overwrite $q from if ($_POST) to save memory if ($_POST) { $q = $_POST["query"]; } elseif ($_GET["history"] == "all") { - $q = implode(";\n\n\n", $history); + $q = implode(";\n\n\n", $history); // rtrim(, ';') would possibly damage DELIMITER } elseif ($_GET["history"] != "") { $q = $history[$_GET["history"]]; }