Skip to content

Commit

Permalink
Print current time next to executed SQL queries
Browse files Browse the repository at this point in the history
  • Loading branch information
vrana committed Mar 27, 2012
1 parent b254503 commit 24c51fe
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 10 deletions.
6 changes: 3 additions & 3 deletions adminer/include/adminer.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -438,11 +438,11 @@ function messageQuery($query) {
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
Expand Down
2 changes: 1 addition & 1 deletion adminer/include/editing.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions adminer/sql.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
}
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)";
Expand Down Expand Up @@ -171,7 +171,7 @@
} 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");
Expand Down Expand Up @@ -202,8 +202,8 @@
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";
Expand Down
1 change: 1 addition & 0 deletions changes.txt
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion editor/include/adminer.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ function selectEmailProcess($where, $foreignKeys) {
}

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) {
Expand Down

0 comments on commit 24c51fe

Please sign in to comment.