]> git.joonet.de Git - adminer.git/commitdiff
Display total time in show only errors mode in SQL command
authorJakub Vrana <jakub@vrana.cz>
Fri, 17 Dec 2010 17:11:06 +0000 (18:11 +0100)
committerJakub Vrana <jakub@vrana.cz>
Fri, 17 Dec 2010 17:11:06 +0000 (18:11 +0100)
adminer/include/editing.inc.php
adminer/sql.inc.php

index d51e5ed6db81c1a948a990096b47457cd3026923..efb637e410ce56d61209695c38ef0cb86541b802 100644 (file)
@@ -108,6 +108,15 @@ function textarea($name, $value, $rows = 10, $cols = 80) {
        echo "<textarea name='$name' rows='$rows' cols='$cols' style='width: 98%;' spellcheck='false' onkeypress='return textareaKeypress(this, event, true);'>" . h($value) . "</textarea>"; // 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 " <span class='time'>(" . lang('%.3f s', max(0, $end[0] - $start[0] + $end[1] - $start[1])) . ")</span>";
+}
+
 /** Print table columns for type edit
 * @param string
 * @param array
index 299c2cca52e89440220b5a775bdefbb87e0a6ec6..48c8fbe8aab046b1a152354acf4bf09a41feb989 100644 (file)
@@ -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 = " <span class='time'>(" . lang('%.3f s', max(0, $end[0] - $start[0] + $end[1] - $start[1])) . ")</span>" . (strlen($q) < 1000 ? " <a href='" . h(ME) . "sql=" . urlencode(trim($q)) . "'>" . lang('Edit') . "</a>" : ""); // 1000 - maximum length of encoded URL in IE is 2083 characters
+                                                               $time = format_time($start, $end) . (strlen($q) < 1000 ? " <a href='" . h(ME) . "sql=" . urlencode(trim($q)) . "'>" . lang('Edit') . "</a>" : ""); // 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 "<p class='message'>" . lang('No commands to execute.') . "\n";
                } elseif ($_POST["only_errors"]) {
-                       echo "<p class='message'>" . lang('%d query(s) executed OK.', $commands - count($errors)) . "\n";
+                       echo "<p class='message'>" . lang('%d query(s) executed OK.', $commands - count($errors)) . format_time($total_start, explode(" ", microtime())) . "\n";
                } elseif ($errors && $commands > 1) {
                        echo "<p class='error'>" . 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"]];
 }