]> git.joonet.de Git - adminer.git/commitdiff
Time out long running select count
authorJakub Vrana <jakub@vrana.cz>
Mon, 20 Aug 2012 02:38:53 +0000 (19:38 -0700)
committerJakub Vrana <jakub@vrana.cz>
Mon, 20 Aug 2012 02:42:37 +0000 (19:42 -0700)
adminer/include/functions.inc.php
adminer/select.inc.php
changes.txt

index 8030b8ec17cb6b7bc34ea3aa83367bfe0231a559..03a50d135ef6e67f21f58401d54d5027c788756e 100644 (file)
@@ -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 @@ var timeout = setTimeout(function () {
 }, <?php echo 1000 * $adminer->queryTimeout(); ?>);
 </script>
 <?php
+       }
        ob_flush();
        flush();
        return $kill;
@@ -923,13 +925,15 @@ var timeout = setTimeout(function () {
 */
 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;
+                       }
                }
        }
 }
index 23c2329e428e8690a50b42693502062c735b9481..5f176deb7c2b443f95ea8224e03918b4b4d414a9 100644 (file)
@@ -393,25 +393,28 @@ if (!$columns) {
                                $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()) {
                                ?>
index 34761b55184f1659c86680985e6274b622634563..bdcff9b4af1cb60e0463914dfb373677a656105a 100644 (file)
@@ -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