diff --git a/adminer/drivers/mssql.inc.php b/adminer/drivers/mssql.inc.php index 58c1141d..8a05696c 100644 --- a/adminer/drivers/mssql.inc.php +++ b/adminer/drivers/mssql.inc.php @@ -301,7 +301,7 @@ if (isset($_GET["mssql"])) { } function limit($query, $where, $limit, $offset = 0, $separator = " ") { - return ($limit !== null ? " TOP (" . ($limit + $offset) . ")" : "") . " $query$where"; // seek later + return ($limit ? " TOP (" . ($limit + $offset) . ")" : "") . " $query$where"; // seek later } function limit1($table, $query, $where, $separator = "\n") { diff --git a/adminer/drivers/mysql.inc.php b/adminer/drivers/mysql.inc.php index 1235bcc2..d5690ce3 100644 --- a/adminer/drivers/mysql.inc.php +++ b/adminer/drivers/mysql.inc.php @@ -387,7 +387,7 @@ if (!defined('Adminer\DRIVER')) { * @param string $where including WHERE */ function limit(string $query, string $where, int $limit, int $offset = 0, string $separator = " "): string { - return " $query$where" . ($limit !== null ? $separator . "LIMIT $limit" . ($offset ? " OFFSET $offset" : "") : ""); + return " $query$where" . ($limit ? $separator . "LIMIT $limit" . ($offset ? " OFFSET $offset" : "") : ""); } /** Formulate SQL modification query with limit 1 diff --git a/adminer/drivers/oracle.inc.php b/adminer/drivers/oracle.inc.php index 88bbfb5d..7ec8d4ae 100644 --- a/adminer/drivers/oracle.inc.php +++ b/adminer/drivers/oracle.inc.php @@ -200,7 +200,7 @@ ORDER BY 1" function limit($query, $where, $limit, $offset = 0, $separator = " ") { return ($offset ? " * FROM (SELECT t.*, rownum AS rnum FROM (SELECT $query$where) t WHERE rownum <= " . ($limit + $offset) . ") WHERE rnum > $offset" - : ($limit !== null ? " * FROM (SELECT $query$where) WHERE rownum <= " . ($limit + $offset) + : ($limit ? " * FROM (SELECT $query$where) WHERE rownum <= " . ($limit + $offset) : " $query$where" )); } diff --git a/adminer/drivers/pgsql.inc.php b/adminer/drivers/pgsql.inc.php index 958bbc78..5c9b0f8b 100644 --- a/adminer/drivers/pgsql.inc.php +++ b/adminer/drivers/pgsql.inc.php @@ -319,7 +319,7 @@ ORDER BY datname"); } function limit($query, $where, $limit, $offset = 0, $separator = " ") { - return " $query$where" . ($limit !== null ? $separator . "LIMIT $limit" . ($offset ? " OFFSET $offset" : "") : ""); + return " $query$where" . ($limit ? $separator . "LIMIT $limit" . ($offset ? " OFFSET $offset" : "") : ""); } function limit1($table, $query, $where, $separator = "\n") { diff --git a/adminer/drivers/sqlite.inc.php b/adminer/drivers/sqlite.inc.php index 5a2ac298..df910d1b 100644 --- a/adminer/drivers/sqlite.inc.php +++ b/adminer/drivers/sqlite.inc.php @@ -178,7 +178,7 @@ if (isset($_GET["sqlite"])) { } function limit($query, $where, $limit, $offset = 0, $separator = " ") { - return " $query$where" . ($limit !== null ? $separator . "LIMIT $limit" . ($offset ? " OFFSET $offset" : "") : ""); + return " $query$where" . ($limit ? $separator . "LIMIT $limit" . ($offset ? " OFFSET $offset" : "") : ""); } function limit1($table, $query, $where, $separator = "\n") { diff --git a/adminer/include/adminer.inc.php b/adminer/include/adminer.inc.php index f64b8710..45c12430 100644 --- a/adminer/include/adminer.inc.php +++ b/adminer/include/adminer.inc.php @@ -431,7 +431,7 @@ class Adminer { /** Print limit box in select */ function selectLimitPrint(int $limit): void { echo "
" . lang('Limit') . "
"; //
for easy styling - echo ""; + echo ""; echo script("qsl('input').oninput = selectFieldChange;", ""); echo "
\n"; } @@ -613,7 +613,7 @@ class Adminer { * @param int $page index of page starting at zero * @return string empty string to use default query */ - function selectQueryBuild(array $select, array $where, array $group, array $order, ?int $limit, ?int $page): string { + function selectQueryBuild(array $select, array $where, array $group, array $order, int $limit, ?int $page): string { return ""; } diff --git a/adminer/include/driver.inc.php b/adminer/include/driver.inc.php index cc9e10da..9452beaf 100644 --- a/adminer/include/driver.inc.php +++ b/adminer/include/driver.inc.php @@ -76,19 +76,19 @@ abstract class SqlDriver { * @param list $where result of adminer()->selectSearchProcess() * @param list $group result of adminer()->selectColumnsProcess()[1] * @param list $order result of adminer()->selectOrderProcess() - * @param int|numeric-string $limit result of adminer()->selectLimitProcess() + * @param int $limit result of adminer()->selectLimitProcess() * @param int $page index of page starting at zero * @param bool $print whether to print the query * @return Result|false */ - function select(string $table, array $select, array $where, array $group, array $order = array(), $limit = 1, ?int $page = 0, bool $print = false) { + function select(string $table, array $select, array $where, array $group, array $order = array(), int $limit = 1, ?int $page = 0, bool $print = false) { $is_group = (count($group) < count($select)); $query = adminer()->selectQueryBuild($select, $where, $group, $order, $limit, $page); if (!$query) { $query = "SELECT" . limit( - ($_GET["page"] != "last" && $limit != "" && $group && $is_group && JUSH == "sql" ? "SQL_CALC_FOUND_ROWS " : "") . implode(", ", $select) . "\nFROM " . table($table), + ($_GET["page"] != "last" && $limit && $group && $is_group && JUSH == "sql" ? "SQL_CALC_FOUND_ROWS " : "") . implode(", ", $select) . "\nFROM " . table($table), ($where ? "\nWHERE " . implode(" AND ", $where) : "") . ($group && $is_group ? "\nGROUP BY " . implode(", ", $group) : "") . ($order ? "\nORDER BY " . implode(", ", $order) : ""), - ($limit != "" ? +$limit : null), + $limit, ($page ? $limit * $page : 0), "\n" ); diff --git a/adminer/select.inc.php b/adminer/select.inc.php index 682fd09f..81e07af1 100644 --- a/adminer/select.inc.php +++ b/adminer/select.inc.php @@ -273,7 +273,7 @@ if (!$columns && support("table")) { $page = $_GET["page"]; if ($page == "last") { $found_rows = get_val(count_rows($TABLE, $where, $is_group, $group)); - $page = floor(max(0, intval($found_rows) - 1) / intval($limit)); + $page = floor(max(0, intval($found_rows) - 1) / $limit); } $select2 = $select; @@ -318,7 +318,7 @@ if (!$columns && support("table")) { } // use count($rows) without LIMIT, COUNT(*) without grouping, FOUND_ROWS otherwise (slowest) - if ($_GET["page"] != "last" && $limit != "" && $group && $is_group && JUSH == "sql") { + if ($_GET["page"] != "last" && $limit && $group && $is_group && JUSH == "sql") { $found_rows = get_val(" SELECT FOUND_ROWS()"); // space to allow mysql.trace_mode } @@ -488,11 +488,11 @@ if (!$columns && support("table")) { $exact_count = true; $found_rows = null; if ($_GET["page"] != "last") { - if ($limit == "" || (count($rows) < $limit && ($rows || !$page))) { + if (!$limit || (count($rows) < $limit && ($rows || !$page))) { $found_rows = ($page ? $page * $limit : 0) + count($rows); } elseif (JUSH != "sql" || !$is_group) { $found_rows = ($is_group ? false : found_rows($table_status, $where)); - if (intval($found_rows) < max(1e4, 2 * ($page + 1) * intval($limit))) { + if (intval($found_rows) < max(1e4, 2 * ($page + 1) * $limit)) { // slow with big tables $found_rows = first(slow_query(count_rows($TABLE, $where, $is_group, $group))); } else { @@ -501,11 +501,11 @@ if (!$columns && support("table")) { } } - $pagination = ($limit != "" && ($found_rows === false || $found_rows > $limit || $page)); + $pagination = ($limit && ($found_rows === false || $found_rows > $limit || $page)); if ($pagination) { echo (($found_rows === false ? count($rows) + 1 : $found_rows - $page * $limit) > $limit ? '

' . lang('Load more data') . '' - . script("qsl('a').onclick = partial(selectLoadMore, " . intval($limit) . ", '" . lang('Loading') . "…');", "") + . script("qsl('a').onclick = partial(selectLoadMore, $limit, '" . lang('Loading') . "…');", "") : '' ); echo "\n"; @@ -516,7 +516,7 @@ if (!$columns && support("table")) { // display first, previous 4, next 4 and last page $max_page = ($found_rows === false ? $page + (count($rows) >= $limit ? 2 : 1) - : floor(($found_rows - 1) / intval($limit)) + : floor(($found_rows - 1) / $limit) ); echo "

"; if (JUSH != "simpledb") { diff --git a/plugins/drivers/clickhouse.php b/plugins/drivers/clickhouse.php index ed760560..eae90dd6 100644 --- a/plugins/drivers/clickhouse.php +++ b/plugins/drivers/clickhouse.php @@ -243,7 +243,7 @@ if (isset($_GET["clickhouse"])) { } function limit($query, $where, $limit, $offset = 0, $separator = " ") { - return " $query$where" . ($limit !== null ? $separator . "LIMIT $limit" . ($offset ? ", $offset" : "") : ""); + return " $query$where" . ($limit ? $separator . "LIMIT $limit" . ($offset ? ", $offset" : "") : ""); } function limit1($table, $query, $where, $separator = "\n") { diff --git a/plugins/drivers/elastic.php b/plugins/drivers/elastic.php index c7db74ef..b22af2cd 100644 --- a/plugins/drivers/elastic.php +++ b/plugins/drivers/elastic.php @@ -146,7 +146,7 @@ if (isset($_GET["elastic"])) { } if ($limit) { - $data["size"] = +$limit; + $data["size"] = $limit; if ($page) { $data["from"] = ($page * $limit); } @@ -308,7 +308,7 @@ if (isset($_GET["elastic"])) { } function limit($query, $where, $limit, $offset = 0, $separator = " ") { - return " $query$where" . ($limit !== null ? $separator . "LIMIT $limit" . ($offset ? " OFFSET $offset" : "") : ""); + return " $query$where" . ($limit ? $separator . "LIMIT $limit" . ($offset ? " OFFSET $offset" : "") : ""); } function collations() { diff --git a/plugins/drivers/firebird.php b/plugins/drivers/firebird.php index c4a6ca65..d81bbd94 100644 --- a/plugins/drivers/firebird.php +++ b/plugins/drivers/firebird.php @@ -107,7 +107,7 @@ if (isset($_GET["firebird"])) { function limit($query, $where, $limit, $offset = 0, $separator = " ") { $return = ''; - $return .= ($limit !== null ? $separator . "FIRST $limit" . ($offset ? " SKIP $offset" : "") : ""); + $return .= ($limit ? $separator . "FIRST $limit" . ($offset ? " SKIP $offset" : "") : ""); $return .= " $query$where"; return $return; } diff --git a/plugins/drivers/imap.php b/plugins/drivers/imap.php index 31b18fbf..29583057 100644 --- a/plugins/drivers/imap.php +++ b/plugins/drivers/imap.php @@ -208,7 +208,7 @@ if (isset($_GET["imap"])) { } function limit($query, $where, $limit, $offset = 0, $separator = " ") { - return " $query$where" . ($limit !== null ? $separator . "LIMIT $limit" . ($offset ? " OFFSET $offset" : "") : ""); + return " $query$where" . ($limit ? $separator . "LIMIT $limit" . ($offset ? " OFFSET $offset" : "") : ""); } function idf_escape($idf) { diff --git a/plugins/drivers/mongo.php b/plugins/drivers/mongo.php index 5a77ed11..ae50ac81 100644 --- a/plugins/drivers/mongo.php +++ b/plugins/drivers/mongo.php @@ -344,10 +344,7 @@ if (isset($_GET["mongo"])) { $val = preg_replace('~ DESC$~', '', $val, 1, $count); $sort[$val] = ($count ? -1 : 1); } - if (isset($_GET['limit']) && is_numeric($_GET['limit']) && $_GET['limit'] > 0) { - $limit = $_GET['limit']; - } - $limit = min(200, max(1, (int) $limit)); + $limit = min(200, max(1, $limit)); $skip = $page * $limit; try { return new Result($this->conn->_link->executeQuery($this->conn->_db_name . ".$table", new \MongoDB\Driver\Query($where, array('projection' => $select, 'limit' => $limit, 'skip' => $skip, 'sort' => $sort)))); diff --git a/plugins/drivers/simpledb.php b/plugins/drivers/simpledb.php index 4bcc0f12..52f558be 100644 --- a/plugins/drivers/simpledb.php +++ b/plugins/drivers/simpledb.php @@ -340,7 +340,7 @@ if (isset($_GET["simpledb"])) { } function limit($query, $where, $limit, $offset = 0, $separator = " ") { - return " $query$where" . ($limit !== null ? $separator . "LIMIT $limit" : ""); + return " $query$where" . ($limit ? $separator . "LIMIT $limit" : ""); } function unconvert_field($field, $return) {