1
0
mirror of https://github.com/vrana/adminer.git synced 2025-08-18 12:21:24 +02:00

Print elapsed time in HTML instead of SQL command comment

This commit is contained in:
Jakub Vrana
2014-03-07 09:33:37 -08:00
parent d9fe03e1b4
commit 6a3ede75f6
10 changed files with 46 additions and 35 deletions

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

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

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

View 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();
if ($query === null) {
// return executed queries without parameter
return implode("\n", $queries);
static $start;
if (!$start) {
$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;
if ($query === null) {
// return executed queries
return array(implode("\n", $queries), format_time($start, microtime(true)));
}
$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