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;
}
/** 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
;
/** 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");
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>'
;
$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;
}
/** 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) {
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);
* @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;
}
/** 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
* @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
$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();
}
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";
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
}
}
- 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) {
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) {
}
}
- function messageQuery($query) {
+ function messageQuery($query, $time) {
//! doesn't work with sql.inc.php
$connection = connection();
$result = $connection->query('SHOW MASTER STATUS');
$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