]> git.joonet.de Git - adminer.git/commitdiff
Print current time next to executed SQL queries
authorJakub Vrana <jakub@vrana.cz>
Sat, 10 Mar 2012 10:28:13 +0000 (02:28 -0800)
committerJakub Vrana <jakub@vrana.cz>
Tue, 27 Mar 2012 06:21:38 +0000 (23:21 -0700)
adminer/include/adminer.inc.php
adminer/include/editing.inc.php
adminer/sql.inc.php
changes.txt
editor/include/adminer.inc.php

index 97b81e0b9ad535cc3d5ca5d7cad3ba69ad57562c..a46461dd7cbd4dabaaeb72a361de9b0be13d2b9f 100644 (file)
@@ -438,11 +438,11 @@ username.form['driver'].onchange();
                restart_session();
                $id = "sql-" . ($count++);
                $history = &get_session("queries");
-               if (strlen($query) > 1e6) { // not DB - reset in drop database
+               if (strlen($query) > 1e6) {
                        $query = ereg_replace('[\x80-\xFF]+$', '', substr($query, 0, 1e6)) . "\n..."; // [\x80-\xFF] - valid UTF-8, \n - can end by one-line comment
                }
-               $history[$_GET["db"]][] = $query; // not DB - $_GET["db"] is changed in database.inc.php //! respect $_GET["ns"]
-               return " <a href='#$id' onclick=\"return !toggle('$id');\">" . lang('SQL command') . "</a><div id='$id' class='hidden'><pre><code class='jush-$jush'>" . shorten_utf8($query, 1000) . '</code></pre><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>';
+               $history[$_GET["db"]][] = array($query, 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><div id='$id' class='hidden'><pre><code class='jush-$jush'>" . shorten_utf8($query, 1000) . '</code></pre><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>'; // @ - time zone may be not set
        }
        
        /** Functions displayed in edit form
index 34d444d98bdf33ea99d42baed6072ee669232d5d..e104e119310c04ec076351443919773fa3538515 100644 (file)
@@ -114,7 +114,7 @@ function textarea($name, $value, $rows = 10, $cols = 80) {
        echo "<textarea name='$name' rows='$rows' cols='$cols' class='sqlarea' spellcheck='false' wrap='off' onkeydown='return textareaKeydown(this, event);'>"; // spellcheck, wrap - not valid before HTML5
        if (is_array($value)) {
                foreach ($value as $val) { // not implode() to save memory
-                       echo h($val) . "\n\n\n";
+                       echo h($val[0]) . "\n\n\n"; // $val == array($query, $time)
                }
        } else {
                echo h($value);
index 5ae86a28948b44ad2396f843dcef1f398893abee..a3b33f2d11ea6a12ef8afc5231fd2b45b39a2717 100644 (file)
@@ -34,8 +34,8 @@ if (!$error && $_POST) {
                }
                if ($query != "" && strlen($query) < 1e6) { // don't add big queries
                        $q = $query . (ereg(";[ \t\r\n]*\$", $query) ? "" : ";"); //! doesn't work with DELIMITER |
-                       if (!$history || end($history) != $q) { // no repeated queries
-                               $history[] = $q;
+                       if (!$history || reset(end($history)) != $q) { // no repeated queries
+                               $history[] = array($q, time());
                        }
                }
                $space = "(?:\\s|/\\*.*\\*/|(?:#|-- )[^\n]*\n|--\n)";
@@ -171,7 +171,7 @@ if ($_POST) {
 } elseif ($_GET["history"] == "all") {
        $q = $history;
 } elseif ($_GET["history"] != "") {
-       $q = $history[$_GET["history"]];
+       $q = $history[$_GET["history"]][0];
 }
 textarea("query", $q, 20);
 echo ($_POST ? "" : "<script type='text/javascript'>document.getElementsByTagName('textarea')[0].focus();</script>\n");
@@ -202,8 +202,8 @@ echo "</div></fieldset>\n";
 if ($history) {
        print_fieldset("history", lang('History'), $_GET["history"] != "");
        foreach ($history as $key => $val) {
-               //! save and display timestamp
-               echo '<a href="' . h(ME . "sql=&history=$key") . '">' . lang('Edit') . "</a> <code class='jush-$jush'>" . shorten_utf8(ltrim(str_replace("\n", " ", str_replace("\r", "", preg_replace('~^(#|-- ).*~m', '', $val)))), 80, "</code>") . "<br>\n";
+               list($q, $time) = $val;
+               echo '<a href="' . h(ME . "sql=&history=$key") . '">' . lang('Edit') . "</a> <span class='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
        }
        echo "<input type='submit' name='clear' value='" . lang('Clear') . "'>\n";
        echo "<a href='" . h(ME . "sql=&history=all") . "'>" . lang('Edit all') . "</a>\n";
index 48be227f9bd76f29ad7cbc89ec6e8c56213329ff..e16f59ec000bec9a44da031a50b2aee66f1bdf58 100644 (file)
@@ -1,4 +1,5 @@
 Adminer 3.4.0-dev:
+Print current time next to executed SQL queries
 Replace JSMin by better JavaScript minifier
 Ukrainian translation
 
index 4ad048f650c4a758a4a2758faabea5c3bb778132..11d40d540cc2ee64ae826aa83ef2b68ab9191b5a 100644 (file)
@@ -408,7 +408,7 @@ ORDER BY ORDINAL_POSITION", null, "") as $row) { //! requires MySQL 5
        }
        
        function messageQuery($query) {
-               return "<!--\n" . str_replace("--", "--><!-- ", $query) . "\n-->";
+               return " <span class='time'>" . @date("H:i:s") . "</span><!--\n" . str_replace("--", "--><!-- ", $query) . "\n-->";
        }
        
        function editFunctions($field) {