Print current time next to executed SQL queries

This commit is contained in:
Jakub Vrana 2012-03-10 02:28:13 -08:00
parent b254503fb2
commit 24c51fe11f
5 changed files with 11 additions and 10 deletions

View 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

View 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);

View 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";

View 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

View 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) {