Permalink
Browse files

Time out long running select count

  • Loading branch information...
1 parent 1f53cd3 commit 6a7021db28875dd8dcd3a66a9fc2ec3438c63143 @vrana committed Aug 20, 2012
Showing with 22 additions and 15 deletions.
  1. +11 −7 adminer/include/functions.inc.php
  2. +10 −7 adminer/select.inc.php
  3. +1 −1 changes.txt
@@ -905,6 +905,7 @@ function is_url($string) {
function kill_timeout() {
global $adminer, $token;
$kill = mt_rand();
+ if (support("kill")) {
?>
<script type="text/javascript">
var timeout = setTimeout(function () {
@@ -913,6 +914,7 @@ function kill_timeout() {
}, <?php echo 1000 * $adminer->queryTimeout(); ?>);
</script>
<?php
+ }
ob_flush();
flush();
return $kill;
@@ -923,13 +925,15 @@ function kill_timeout() {
*/
function cancel_kill_timeout() {
global $connection;
- echo "<script type='text/javascript'>clearTimeout(timeout);</script>\n";
- ob_flush();
- flush();
- if ($connection->errno == 2006) { // 2006 - CR_SERVER_GONE_ERROR
- $connection2 = connect();
- if (is_object($connection2)) {
- $connection = $connection2;
+ if (support("kill")) {
+ echo "<script type='text/javascript'>clearTimeout(timeout);</script>\n";
+ ob_flush();
+ flush();
+ if ($connection->errno == 2006) { // 2006 - CR_SERVER_GONE_ERROR
+ $connection2 = connect();
+ if (is_object($connection2)) {
+ $connection = $connection2;
+ }
}
}
}
View
@@ -393,25 +393,28 @@
$found_rows = found_rows($table_status, $where);
if ($found_rows < max(1e4, 2 * ($page + 1) * $limit)) {
// slow with big tables
- ob_flush();
- flush();
- $found_rows = $connection->result("SELECT COUNT(*) FROM " . table($TABLE) . ($where ? " WHERE " . implode(" AND ", $where) : ""));
+ $kill = kill_timeout();
+ $found_rows = @$connection->result("/* Adminer $kill */ SELECT COUNT(*) FROM " . table($TABLE) . ($where ? " WHERE " . implode(" AND ", $where) : "")); // @ - may be kill
+ cancel_kill_timeout();
} else {
$exact_count = false;
}
}
echo "<p class='pages'>";
- if (+$limit && $found_rows > $limit) {
+ if (+$limit && ($found_rows === false || $found_rows > $limit)) {
// display first, previous 4, next 4 and last page
- $max_page = floor(($found_rows - 1) / $limit);
+ $max_page = ($found_rows === false
+ ? $page + (count($rows) >= $limit ? 2 : 1)
+ : floor(($found_rows - 1) / $limit)
+ );
echo '<a href="' . h(remove_from_uri("page")) . "\" onclick=\"pageClick(this.href, +prompt('" . lang('Page') . "', '" . ($page + 1) . "'), event); return false;\">" . lang('Page') . "</a>:";
echo pagination(0, $page) . ($page > 5 ? " ..." : "");
for ($i = max(1, $page - 4); $i < min($max_page, $page + 5); $i++) {
echo pagination($i, $page);
}
- echo ($page + 5 < $max_page ? " ..." : "") . ($exact_count ? pagination($max_page, $page) : ' <a href="' . h(remove_from_uri() . "&page=last") . '">' . lang('last') . "</a>");
+ echo ($page + 5 < $max_page ? " ..." : "") . ($exact_count && $found_rows !== false ? pagination($max_page, $page) : ' <a href="' . h(remove_from_uri() . "&page=last") . '">' . lang('last') . "</a>");
}
- echo " (" . ($exact_count ? "" : "~ ") . lang('%d row(s)', $found_rows) . ") " . checkbox("all", 1, 0, lang('whole result')) . "\n";
+ echo ($found_rows !== false ? " (" . ($exact_count ? "" : "~ ") . lang('%d row(s)', $found_rows) . ")" : "") . " " . checkbox("all", 1, 0, lang('whole result')) . "\n";
if ($adminer->selectCommandPrint()) {
?>
View
@@ -1,6 +1,6 @@
Adminer 3.5.2-dev:
Edit strings with \n in textarea
-Time out long running database list
+Time out long running database list and select count
Use VALUES() in INSERT+UPDATE export
Style logout button as link

0 comments on commit 6a7021d

Please sign in to comment.