$connection2->select_db(DB);
}
$commands = 0;
- $errors = "";
+ $errors = array();
while ($query != "") {
if (!$offset && preg_match('~^\\s*DELIMITER\\s+(.+)~i', $query, $match)) {
$delimiter = $match[1];
if (!$found && rtrim($query) == "") {
break;
}
- if (!$found || $found == $delimiter) { // end of a query
+ if ($found && $found != $delimiter) { // find matching quote or comment end
+ while (preg_match('~' . ($found == '/*' ? '\\*/' : (ereg('-- |#', $found) ? "\n" : "$found|\\\\.")) . '|$~s', $query, $match, PREG_OFFSET_CAPTURE, $offset)) { //! respect sql_mode NO_BACKSLASH_ESCAPES
+ $s = $match[0][0];
+ $offset = $match[0][1] + strlen($s);
+ if (!$s && $fp && !feof($fp)) {
+ $query .= fread($fp, 1e6);
+ } elseif ($s[0] != "\\") {
+ break;
+ }
+ }
+ } else { // end of a query
$empty = false;
$q = substr($query, 0, $match[0][1]);
$commands++;
- echo "<pre class='jush-$jush' id='sql-$commands'>" . shorten_utf8(trim($q), 1000) . "</pre>\n";
- ob_flush();
- flush(); // can take a long time - show the running query
+ $print = "<pre class='jush-$jush' id='sql-$commands'>" . shorten_utf8(trim($q), 1000) . "</pre>\n";
+ if (!$_POST["only_errors"]) {
+ echo $print;
+ ob_flush();
+ flush(); // can take a long time - show the running query
+ }
$start = explode(" ", microtime()); // microtime(true) is available since PHP 5
//! don't allow changing of character_set_results, convert encoding of displayed query
if (!$connection->multi_query($q)) {
+ echo ($_POST["only_errors"] ? $print : "");
echo "<p class='error'>" . lang('Error in query') . ": " . error() . "\n";
- $errors .= " <a href='#sql-$commands'>$commands</a>";
+ $errors[] = " <a href='#sql-$commands'>$commands</a>";
if ($_POST["error_stops"]) {
break;
}
$result = $connection->store_result();
$end = explode(" ", microtime());
$time = " <span class='time'>(" . lang('%.3f s', max(0, $end[0] - $start[0] + $end[1] - $start[1])) . ")</span>";
- if (is_object($result)) {
+ if (!is_object($result)) {
+ if (preg_match("~^$space*(CREATE|DROP|ALTER)$space+(DATABASE|SCHEMA)\\b~isU", $q)) {
+ restart_session();
+ set_session("dbs", null); // clear cache
+ session_write_close();
+ }
+ if (!$_POST["only_errors"]) {
+ echo "<p class='message' title='" . h($connection->info) . "'>" . lang('Query executed OK, %d row(s) affected.', $connection->affected_rows) . "$time\n";
+ }
+ } elseif (!$_POST["only_errors"]) {
select($result, $connection2);
echo "<p>" . ($result->num_rows ? lang('%d row(s)', $result->num_rows) : "") . $time;
if ($connection2 && preg_match("~^($space|\\()*SELECT\\b~isU", $q)) {
select(explain($connection2, $q));
echo "</div>\n";
}
- } else {
- if (preg_match("~^$space*(CREATE|DROP|ALTER)$space+(DATABASE|SCHEMA)\\b~isU", $q)) {
- restart_session();
- set_session("dbs", null); // clear cache
- session_write_close();
- }
- echo "<p class='message' title='" . h($connection->info) . "'>" . lang('Query executed OK, %d row(s) affected.', $connection->affected_rows) . "$time\n";
}
$start = $end;
} while ($connection->next_result());
}
$query = substr($query, $offset);
$offset = 0;
- } else { // find matching quote or comment end
- while (preg_match('~' . ($found == '/*' ? '\\*/' : (ereg('-- |#', $found) ? "\n" : "$found|\\\\.")) . '|$~s', $query, $match, PREG_OFFSET_CAPTURE, $offset)) { //! respect sql_mode NO_BACKSLASH_ESCAPES
- $s = $match[0][0];
- $offset = $match[0][1] + strlen($s);
- if (!$s && $fp && !feof($fp)) {
- $query .= fread($fp, 1e6);
- } elseif ($s[0] != "\\") {
- break;
- }
- }
}
}
}
}
- if ($errors && $commands > 1) {
- echo "<p class='error'>" . lang('Error in query') . ": $errors\n";
- }
if ($empty) {
echo "<p class='message'>" . lang('No commands to execute.') . "\n";
+ } elseif ($_POST["only_errors"]) {
+ echo "<p class='message'>" . lang('%d query(s) executed OK.', $commands - count($errors)) . "\n";
+ } elseif ($errors && $commands > 1) {
+ echo "<p class='error'>" . lang('Error in query') . ": " . implode("", $errors) . "\n";
}
//! MS SQL - SET SHOWPLAN_ALL OFF
} else {
<input type="submit" value="<?php echo lang('Execute'); ?>" title="Ctrl+Enter">
<?php
echo checkbox("error_stops", 1, $_POST["error_stops"], lang('Stop on error'));
+echo checkbox("only_errors", 1, $_POST["only_errors"], lang('Show only errors'));
print_fieldset("webfile", lang('From server'), $_POST["webfile"]);
$compress = array();