Allow limiting number of displayed rows in SQL command (bug #406)

This commit is contained in:
Jakub Vrana 2014-12-06 11:11:34 -08:00
parent f839d5ac25
commit 25329cebf3
7 changed files with 17 additions and 6 deletions

View file

@ -3,9 +3,10 @@
* @param Min_Result * @param Min_Result
* @param Min_DB connection to examine indexes * @param Min_DB connection to examine indexes
* @param array * @param array
* @param int
* @return array $orgtables * @return array $orgtables
*/ */
function select($result, $connection2 = null, $orgtables = array()) { function select($result, $connection2 = null, $orgtables = array(), $limit = 0) {
global $jush; global $jush;
$links = array(); // colno => orgtable - create links from these columns $links = array(); // colno => orgtable - create links from these columns
$indexes = array(); // orgtable => array(column => colno) - primary keys $indexes = array(); // orgtable => array(column => colno) - primary keys
@ -14,7 +15,7 @@ function select($result, $connection2 = null, $orgtables = array()) {
$types = array(); // colno => type - display char in <code> $types = array(); // colno => type - display char in <code>
$return = array(); // table => orgtable - mapping to use in EXPLAIN $return = array(); // table => orgtable - mapping to use in EXPLAIN
odd(''); // reset odd for each result odd(''); // reset odd for each result
for ($i=0; $row = $result->fetch_row(); $i++) { for ($i=0; (!$limit || $i < $limit) && ($row = $result->fetch_row()); $i++) {
if (!$i) { if (!$i) {
echo "<table cellspacing='0' class='nowrap'>\n"; echo "<table cellspacing='0' class='nowrap'>\n";
echo "<thead><tr>"; echo "<thead><tr>";

View file

@ -1,2 +1,2 @@
<?php <?php
$VERSION = "4.1.1-dev"; $VERSION = "4.2.0-dev";

View file

@ -235,11 +235,13 @@ $translations = array(
'Sort' => 'Seřadit', 'Sort' => 'Seřadit',
'descending' => 'sestupně', 'descending' => 'sestupně',
'Limit' => 'Limit', 'Limit' => 'Limit',
'Limit rows' => 'Limit řádek',
'Text length' => 'Délka textů', 'Text length' => 'Délka textů',
'Action' => 'Akce', 'Action' => 'Akce',
'Full table scan' => 'Průchod celé tabulky', 'Full table scan' => 'Průchod celé tabulky',
'Unable to select the table' => 'Nepodařilo se vypsat tabulku', 'Unable to select the table' => 'Nepodařilo se vypsat tabulku',
'No rows.' => 'Žádné řádky.', 'No rows.' => 'Žádné řádky.',
'%d / ' => '%d / ',
'%d row(s)' => array('%d řádek', '%d řádky', '%d řádků'), '%d row(s)' => array('%d řádek', '%d řádky', '%d řádků'),
'Page' => 'Stránka', 'Page' => 'Stránka',
'last' => 'poslední', 'last' => 'poslední',

View file

@ -5,6 +5,7 @@ $translations = array(
'%d byte(s)' => array('%d byte', '%d bytes'), '%d byte(s)' => array('%d byte', '%d bytes'),
'Routine has been called, %d row(s) affected.' => array('Routine has been called, %d row affected.', 'Routine has been called, %d rows affected.'), 'Routine has been called, %d row(s) affected.' => array('Routine has been called, %d row affected.', 'Routine has been called, %d rows affected.'),
'%d process(es) have been killed.' => array('%d process has been killed.', '%d processes have been killed.'), '%d process(es) have been killed.' => array('%d process has been killed.', '%d processes have been killed.'),
'%d / ' => '%d / ',
'%d row(s)' => array('%d row', '%d rows'), '%d row(s)' => array('%d row', '%d rows'),
'%d item(s) have been affected.' => array('%d item has been affected.', '%d items have been affected.'), '%d item(s) have been affected.' => array('%d item has been affected.', '%d items have been affected.'),
'%d row(s) have been imported.' => array('%d row has been imported.', '%d rows have been imported.'), '%d row(s) have been imported.' => array('%d row has been imported.', '%d rows have been imported.'),

View file

@ -234,11 +234,13 @@ $translations = array(
'Sort' => 'xx', 'Sort' => 'xx',
'descending' => 'xx', 'descending' => 'xx',
'Limit' => 'xx', 'Limit' => 'xx',
'Limit rows' => 'xx',
'Text length' => 'xx', 'Text length' => 'xx',
'Action' => 'xx', 'Action' => 'xx',
'Full table scan' => 'xx', 'Full table scan' => 'xx',
'Unable to select the table' => 'xx', 'Unable to select the table' => 'xx',
'No rows.' => 'xx', 'No rows.' => 'xx',
'%d / ' => 'xx',
'%d row(s)' => array('xx', 'xx'), '%d row(s)' => array('xx', 'xx'),
'Page' => 'xx', 'Page' => 'xx',
'last' => 'xx', 'last' => 'xx',

View file

@ -121,10 +121,13 @@ if (!$error && $_POST) {
} }
} elseif (is_object($result)) { } elseif (is_object($result)) {
$orgtables = select($result, $connection2); $limit = $_POST["limit"];
$orgtables = select($result, $connection2, array(), $limit);
if (!$_POST["only_errors"]) { if (!$_POST["only_errors"]) {
echo "<form action='' method='post'>\n"; echo "<form action='' method='post'>\n";
echo "<p>" . ($result->num_rows ? lang('%d row(s)', $result->num_rows) : "") . $time; $num_rows = $result->num_rows;
echo "<p>" . ($num_rows ? ($limit && $num_rows > $limit ? lang('%d / ', $limit) : "") . lang('%d row(s)', $num_rows) : "");
echo $time;
$id = "export-$commands"; $id = "export-$commands";
$export = ", <a href='#$id' onclick=\"return !toggle('$id');\">" . lang('Export') . "</a><span id='$id' class='hidden'>: " $export = ", <a href='#$id' onclick=\"return !toggle('$id');\">" . lang('Export') . "</a><span id='$id' class='hidden'>: "
. html_select("output", $adminer->dumpOutput(), $adminer_export["output"]) . " " . html_select("output", $adminer->dumpOutput(), $adminer_export["output"]) . " "
@ -199,6 +202,7 @@ if (!isset($_GET["import"])) {
textarea("query", $q, 20); textarea("query", $q, 20);
echo ($_POST ? "" : "<script type='text/javascript'>focus(document.getElementsByTagName('textarea')[0]);</script>\n"); echo ($_POST ? "" : "<script type='text/javascript'>focus(document.getElementsByTagName('textarea')[0]);</script>\n");
echo "<p>$execute\n"; echo "<p>$execute\n";
echo lang('Limit rows') . ": <input type='number' name='limit' class='size' value='" . h($_POST ? $_POST["limit"] : $_GET["limit"]) . "'>\n";
} else { } else {
echo "<fieldset><legend>" . lang('File upload') . "</legend><div>"; echo "<fieldset><legend>" . lang('File upload') . "</legend><div>";

View file

@ -1,4 +1,5 @@
Adminer 4.1.1-dev: Adminer 4.2.0-dev:
Allow limiting number of displayed rows in SQL command
Fix reading routine column collations Fix reading routine column collations
Unlock session in alter database Unlock session in alter database
Make master key unreadable to others (bug #410) Make master key unreadable to others (bug #410)