Return string from warnings()

This commit is contained in:
Jakub Vrana 2018-02-01 11:43:44 +01:00
parent e3346fb0bc
commit e9add6d985
4 changed files with 17 additions and 21 deletions

View file

@ -278,7 +278,12 @@ if (!defined("DRIVER")) {
} }
function warnings() { function warnings() {
return $this->_conn->query("SHOW WARNINGS"); $result = $this->_conn->query("SHOW WARNINGS");
if ($result && $result->num_rows) {
ob_start();
select($result); // select() usually needs to print a big table progressively
return ob_get_clean();
}
} }
} }

View file

@ -212,12 +212,10 @@ class Adminer {
; ;
$print = "</p>\n"; // required for IE9 inline edit $print = "</p>\n"; // required for IE9 inline edit
$warnings = $driver->warnings(); $warnings = $driver->warnings();
if ($warnings && $warnings->num_rows) { if ($warnings) {
$id = "warnings"; $id = "warnings";
ob_start();
select($warnings); // select() usually needs to print a big table progressively
$return .= ", <a href='#$id'>" . lang('Warnings') . "</a>" . script("qsl('a').onclick = partial(toggle, '$id');", "") $return .= ", <a href='#$id'>" . lang('Warnings') . "</a>" . script("qsl('a').onclick = partial(toggle, '$id');", "")
. "$print<div id='$id' class='hidden'>\n" . ob_get_clean() . "</div>\n" . "$print<div id='$id' class='hidden'>\n$warnings</div>\n"
; ;
} else { } else {
$return .= $print; $return .= $print;
@ -629,16 +627,13 @@ class Adminer {
$return = " <span class='time'>" . @date("H:i:s") . "</span>"; // @ - time zone may be not set $return = " <span class='time'>" . @date("H:i:s") . "</span>"; // @ - time zone may be not set
$warnings = $driver->warnings(); $warnings = $driver->warnings();
$print = ""; $print = "";
if ($warnings && $warnings->num_rows) { if ($warnings) {
$id = "warnings-" . count($history[$_GET["db"]]); $id = "warnings-" . count($history[$_GET["db"]]);
$return .= " <a href='#$id' class='toggle'>" . lang('Warnings') . "</a>,"; $return .= " <a href='#$id' class='toggle'>" . lang('Warnings') . "</a>,";
ob_start(); $print = "<div id='$id' class='hidden'>\n$warnings</div>\n";
select($warnings); // select() usually needs to print a big table progressively
$print = "<div id='$id' class='hidden'>\n" . ob_get_clean() . "</div>\n";
} }
$id = "sql-" . count($history[$_GET["db"]]); $id = "sql-" . count($history[$_GET["db"]]);
return $return return "$return <a href='#$id' class='toggle'>" . lang('SQL command') . "</a>"
. " <a href='#$id' class='toggle'>" . lang('SQL command') . "</a>"
. $print . $print
. "<div id='$id' class='hidden'><pre><code class='jush-$jush'>" . shorten_utf8($query, 1000) . '</code></pre>' . "<div id='$id' class='hidden'><pre><code class='jush-$jush'>" . shorten_utf8($query, 1000) . '</code></pre>'
. ($time ? " <span class='time'>($time)</span>" : '') . ($time ? " <span class='time'>($time)</span>" : '')

View file

@ -114,10 +114,10 @@
} }
/** Get warnings about the last command /** Get warnings about the last command
* @return Min_Result or false * @return string HTML
*/ */
function warnings() { function warnings() {
return false; return '';
} }
} }

View file

@ -130,9 +130,9 @@ if (!$error && $_POST) {
$time = " <span class='time'>(" . format_time($start) . ")</span>" $time = " <span class='time'>(" . format_time($start) . ")</span>"
. (strlen($q) < 1000 ? " <a href='" . h(ME) . "sql=" . urlencode(trim($q)) . "'>" . lang('Edit') . "</a>" : "") // 1000 - maximum length of encoded URL in IE is 2083 characters . (strlen($q) < 1000 ? " <a href='" . h(ME) . "sql=" . urlencode(trim($q)) . "'>" . lang('Edit') . "</a>" : "") // 1000 - maximum length of encoded URL in IE is 2083 characters
; ;
$warnings = $driver->warnings(); $warnings = ($_POST["only_errors"] ? "" : $driver->warnings());
$warnings_id = "warnings-$commands"; if ($warnings) {
if ($warnings && $warnings->num_rows) { $warnings_id = "warnings-$commands";
$time .= ", <a href='#$warnings_id'>" . lang('Warnings') . "</a>" . script("qsl('a').onclick = partial(toggle, '$warnings_id');", ""); $time .= ", <a href='#$warnings_id'>" . lang('Warnings') . "</a>" . script("qsl('a').onclick = partial(toggle, '$warnings_id');", "");
} }
$explain = null; $explain = null;
@ -168,11 +168,7 @@ if (!$error && $_POST) {
echo "<p class='message' title='" . h($connection->info) . "'>" . lang('Query executed OK, %d row(s) affected.', $connection->affected_rows) . "$time\n"; echo "<p class='message' title='" . h($connection->info) . "'>" . lang('Query executed OK, %d row(s) affected.', $connection->affected_rows) . "$time\n";
} }
} }
if ($warnings && $warnings->num_rows && !$_POST["only_errors"]) { echo ($warnings ? "<div id='$warnings_id' class='hidden'>\n$warnings</div>\n" : "");
echo "<div id='$warnings_id' class='hidden'>\n";
select($warnings);
echo "</div>\n";
}
if ($explain) { if ($explain) {
echo "<div id='$explain_id' class='hidden'>\n"; echo "<div id='$explain_id' class='hidden'>\n";
select($explain, $connection2, $orgtables); select($explain, $connection2, $orgtables);