]> git.joonet.de Git - adminer.git/commitdiff
Print elapsed time in HTML instead of SQL command comment
authorJakub Vrana <jakub@vrana.cz>
Fri, 7 Mar 2014 17:33:37 +0000 (09:33 -0800)
committerJakub Vrana <jakub@vrana.cz>
Fri, 7 Mar 2014 17:33:37 +0000 (09:33 -0800)
adminer/drivers/elastic.inc.php
adminer/include/adminer.inc.php
adminer/include/driver.inc.php
adminer/include/editing.inc.php
adminer/include/functions.inc.php
adminer/sql.inc.php
changes.txt
editor/include/adminer.inc.php
plugins/master-slave.php
plugins/sql-log.php

index 413a67b1eedfbb3713b563a60100be99770275f4..289f90225ebdec897d26c7042bd47de06e6d774a 100644 (file)
@@ -139,10 +139,11 @@ if (isset($_GET["elastic"])) {
                        if ($data["query"] && !$data["query"]["filtered"]["query"]) {
                                $data["query"]["filtered"]["query"] = array("match_all" => array());
                        }
+                       $start = microtime(true);
+                       $search = $this->_conn->query($query, $data);
                        if ($print) {
-                               echo $adminer->selectQuery("$query: " . print_r($data, true));
+                               echo $adminer->selectQuery("$query: " . print_r($data, true), format_time($start, microtime(true)));
                        }
-                       $search = $this->_conn->query($query, $data);
                        if (!$search) {
                                return false;
                        }
index 500f56d43de486cf1d90dfbf26b65ee4416d0173..9d68dc1cbae1a7f05477edf173c33f1e04feef62 100644 (file)
@@ -177,11 +177,12 @@ username.form['auth[driver]'].onchange();
 
        /** Query printed in select before execution
        * @param string query to be executed
+       * @param string elapsed time
        * @return string
        */
-       function selectQuery($query) {
+       function selectQuery($query, $time) {
                global $jush;
-               return "<p><code class='jush-$jush'>" . h(str_replace("\n", " ", $query)) . "</code>"
+               return "<p><code class='jush-$jush'>" . h(str_replace("\n", " ", $query)) . "</code> <span class='time'>($time)</span>"
                        . (support("sql") ? " <a href='" . h(ME) . "sql=" . urlencode($query) . "'>" . lang('Edit') . "</a>" : "")
                        . "</p>" // </p> - required for IE9 inline edit
                ;
@@ -500,9 +501,10 @@ username.form['auth[driver]'].onchange();
 
        /** Query printed after execution in the message
        * @param string executed query
+       * @param string elapsed time
        * @return string
        */
-       function messageQuery($query) {
+       function messageQuery($query, $time) {
                global $jush;
                restart_session();
                $history = &get_session("queries");
@@ -510,9 +512,10 @@ username.form['auth[driver]'].onchange();
                if (strlen($query) > 1e6) {
                        $query = preg_replace('~[\x80-\xFF]+$~', '', substr($query, 0, 1e6)) . "\n..."; // [\x80-\xFF] - valid UTF-8, \n - can end by one-line comment
                }
-               $history[$_GET["db"]][] = array($query, time()); // not DB - $_GET["db"] is changed in database.inc.php //! respect $_GET["ns"]
+               $history[$_GET["db"]][] = array($query, time(), $time); // not DB - $_GET["db"] is changed in database.inc.php //! respect $_GET["ns"]
                return " <span class='time'>" . @date("H:i:s") . "</span> <a href='#$id' onclick=\"return !toggle('$id');\">" . lang('SQL command') . "</a>" // @ - time zone may be not set
                        . "<div id='$id' class='hidden'><pre><code class='jush-$jush'>" . shorten_utf8($query, 1000) . '</code></pre>'
+                       . ($time ? " <span class='time'>($time)</span>" : '')
                        . (support("sql") ? '<p><a href="' . h(str_replace("db=" . urlencode(DB), "db=" . urlencode($_GET["db"]), ME) . 'sql=&history=' . (count($history[$_GET["db"]]) - 1)) . '">' . lang('Edit') . '</a>' : '')
                        . '</div>'
                ;
index 25bd021717c62071f16a57070cc49a806e167e10..c0b4b9ad24ac56554844b7acf8baf4d1ad8c1594 100644 (file)
@@ -45,7 +45,7 @@
                $start = microtime(true);
                $return = $this->_conn->query($query);
                if ($print) {
-                       echo $adminer->selectQuery($query . ";\n-- " . format_time($start, microtime(true)));
+                       echo $adminer->selectQuery($query, format_time($start, microtime(true)));
                }
                return $return;
        }
index 76e4aa2ea8880a2861b1efc18397da662ea318a1..4da94da27ec0c3abe6abfb6e6eabc12d6810cbcb 100644 (file)
@@ -111,9 +111,9 @@ function referencable_primary($self) {
 
 /** Print SQL <textarea> tag
 * @param string
+* @param string or array in which case [0] of every element is used
 * @param int
 * @param int
-* @param string
 * @return null
 */
 function textarea($name, $value, $rows = 10, $cols = 80) {
@@ -121,7 +121,7 @@ function textarea($name, $value, $rows = 10, $cols = 80) {
        echo "<textarea name='$name' rows='$rows' cols='$cols' class='sqlarea jush-$jush' spellcheck='false' wrap='off'>";
        if (is_array($value)) {
                foreach ($value as $val) { // not implode() to save memory
-                       echo h($val[0]) . "\n\n\n"; // $val == array($query, $time)
+                       echo h($val[0]) . "\n\n\n"; // $val == array($query, $time, $elapsed)
                }
        } else {
                echo h($value);
index 744a55b258c2ecef8a9af7801e7603874af31dfd..44618a569023b794ddc4d2ea3f9bb8f5f341a6a2 100644 (file)
@@ -548,17 +548,16 @@ function redirect($location, $message = null) {
 * @param bool
 * @return bool
 */
-function query_redirect($query, $location, $message, $redirect = true, $execute = true, $failed = false) {
+function query_redirect($query, $location, $message, $redirect = true, $execute = true, $failed = false, $time = "") {
        global $connection, $error, $adminer;
-       $time = "";
        if ($execute) {
                $start = microtime(true);
                $failed = !$connection->query($query);
-               $time = "; -- " . format_time($start, microtime(true));
+               $time = format_time($start, microtime(true));
        }
        $sql = "";
        if ($query) {
-               $sql = $adminer->messageQuery($query . $time);
+               $sql = $adminer->messageQuery($query, $time);
        }
        if ($failed) {
                $error = error() . $sql;
@@ -571,21 +570,22 @@ function query_redirect($query, $location, $message, $redirect = true, $execute
 }
 
 /** Execute and remember query
-* @param string null to return remembered queries, end with ';' to use DELIMITER
-* @return Min_Result
+* @param string or null to return remembered queries, end with ';' to use DELIMITER
+* @return Min_Result or string if $query = null
 */
-function queries($query = null) {
+function queries($query) {
        global $connection;
        static $queries = array();
+       static $start;
+       if (!$start) {
+               $start = microtime(true);
+       }
        if ($query === null) {
-               // return executed queries without parameter
-               return implode("\n", $queries);
+               // return executed queries
+               return array(implode("\n", $queries), format_time($start, microtime(true)));
        }
-       $start = microtime(true);
-       $return = $connection->query($query);
-       $queries[] = (preg_match('~;$~', $query) ? "DELIMITER ;;\n$query;\nDELIMITER " : $query)
-               . "; -- " . format_time($start, microtime(true));
-       return $return;
+       $queries[] = (preg_match('~;$~', $query) ? "DELIMITER ;;\n$query;\nDELIMITER " : $query) . ";";
+       return $connection->query($query);
 }
 
 /** Apply command to all array items
@@ -610,7 +610,8 @@ function apply_queries($query, $tables, $escape = 'table') {
 * @return bool
 */
 function queries_redirect($location, $message, $redirect) {
-       return query_redirect(queries(), $location, $message, $redirect, false, !$redirect);
+       list($queries, $time) = queries(null);
+       return query_redirect($queries, $location, $message, $redirect, false, !$redirect, $time);
 }
 
 /** Format time difference
index 27b0cc3758912303dcd38e8b576d34f17de57050..636e6d72a26207992e95122b2430ba8710b54fa9 100644 (file)
@@ -39,7 +39,7 @@ if (!$error && $_POST) {
                        $q = $query . (preg_match("~;[ \t\r\n]*\$~", $query) ? "" : ";"); //! doesn't work with DELIMITER |
                        if (!$history || reset(end($history)) != $q) { // no repeated queries
                                restart_session();
-                               $history[] = array($q, time());
+                               $history[] = array($q, time()); //! add elapsed time
                                set_session("queries", $history_all); // required because reference is unlinked by stop_session()
                                stop_session();
                        }
@@ -224,8 +224,13 @@ if (!isset($_GET["import"]) && $history) {
        print_fieldset("history", lang('History'), $_GET["history"] != "");
        for ($val = end($history); $val; $val = prev($history)) { // not array_reverse() to save memory
                $key = key($history);
-               list($q, $time) = $val;
-               echo '<a href="' . h(ME . "sql=&history=$key") . '">' . lang('Edit') . "</a> <span class='time' title='" . @date('Y-m-d', $time) . "'>" . @date("H:i:s", $time) . "</span> <code class='jush-$jush'>" . shorten_utf8(ltrim(str_replace("\n", " ", str_replace("\r", "", preg_replace('~^(#|-- ).*~m', '', $q)))), 80, "</code>") . "<br>\n"; // @ - time zone may be not set
+               list($q, $time, $elapsed) = $val;
+               echo '<a href="' . h(ME . "sql=&history=$key") . '">' . lang('Edit') . "</a>"
+                       . " <span class='time' title='" . @date('Y-m-d', $time) . "'>" . @date("H:i:s", $time) . "</span>" // @ - time zone may be not set
+                       . " <code class='jush-$jush'>" . shorten_utf8(ltrim(str_replace("\n", " ", str_replace("\r", "", preg_replace('~^(#|-- ).*~m', '', $q)))), 80, "</code>")
+                       . ($elapsed ? " <span class='time'>($elapsed)</span>" : "")
+                       . "<br>\n"
+               ;
        }
        echo "<input type='submit' name='clear' value='" . lang('Clear') . "'>\n";
        echo "<a href='" . h(ME . "sql=&history=all") . "'>" . lang('Edit all') . "</a>\n";
index df665bb71d43b2b0b004827fdd1e10f838e38372..9f898cc55d93183e7811bcabddb93b006656e7a8 100644 (file)
@@ -3,6 +3,7 @@ Provide size of all databases in the overview
 Compute number of tables in the overview explicitly
 Display edit form after error in clone or multi-edit
 Display time of the select command
+Print elapsed time in HTML instead of SQL command comment
 Improve gzip export ratio (bug #387)
 MySQL: Fix editing rows by binary values, bug since Adminer 3.7.1
 MySQL: Respect daylight saving time in dump, bug since Adminer 3.6.4
index 1a075807bde1f19aad287a9722a82414305f508e..3d71146239d0582b5acd6fe785b8c2b4f8cbd0f2 100644 (file)
@@ -128,8 +128,8 @@ ORDER BY ORDINAL_POSITION", null, "") as $row) { //! requires MySQL 5
                }
        }
 
-       function selectQuery($query) {
-               return "<!--\n" . str_replace("--", "--><!-- ", $query) . "\n-->\n";
+       function selectQuery($query, $time) {
+               return "<!--\n" . str_replace("--", "--><!-- ", $query) . "\n($time)\n-->\n";
        }
 
        function rowDescription($table) {
@@ -425,8 +425,8 @@ ORDER BY ORDINAL_POSITION", null, "") as $row) { //! requires MySQL 5
                return "";
        }
 
-       function messageQuery($query) {
-               return " <span class='time'>" . @date("H:i:s") . "</span><!--\n" . str_replace("--", "--><!-- ", $query) . "\n-->";
+       function messageQuery($query, $time) {
+               return " <span class='time'>" . @date("H:i:s") . "</span><!--\n" . str_replace("--", "--><!-- ", $query) . "\n" . ($time ? "($time)\n" : "") . "-->";
        }
 
        function editFunctions($field) {
index 6de7c252bb60966179bb487efa3b453e1862945b..27054151902267766ef03c5fd895813ba6c7a1de 100644 (file)
@@ -30,7 +30,7 @@ class AdminerMasterSlave {
                }
        }
 
-       function messageQuery($query) {
+       function messageQuery($query, $time) {
                //! doesn't work with sql.inc.php
                $connection = connection();
                $result = $connection->query('SHOW MASTER STATUS');
index 083e6348b8cd84b853c28bce45c2a35b16226f35..de1fe85d38d584079bf68df75ec54757ed5f6715 100644 (file)
@@ -17,7 +17,7 @@ class AdminerSqlLog {
                $this->filename = $filename;
        }
        
-       function messageQuery($query) {
+       function messageQuery($query, $time) {
                if ($this->filename == "") {
                        $adminer = adminer();
                        $this->filename = $adminer->database() . ".sql"; // no database goes to ".sql" to avoid collisions