mirror of
https://github.com/vrana/adminer.git
synced 2025-08-06 14:46:36 +02:00
PHPStan: Use int for $limit
This commit is contained in:
@@ -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") {
|
||||
|
@@ -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
|
||||
|
@@ -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"
|
||||
));
|
||||
}
|
||||
|
@@ -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") {
|
||||
|
@@ -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") {
|
||||
|
@@ -431,7 +431,7 @@ class Adminer {
|
||||
/** Print limit box in select */
|
||||
function selectLimitPrint(int $limit): void {
|
||||
echo "<fieldset><legend>" . lang('Limit') . "</legend><div>"; // <div> for easy styling
|
||||
echo "<input type='number' name='limit' class='size' value='" . h($limit) . "'>";
|
||||
echo "<input type='number' name='limit' class='size' value='" . intval($limit) . "'>";
|
||||
echo script("qsl('input').oninput = selectFieldChange;", "");
|
||||
echo "</div></fieldset>\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 "";
|
||||
}
|
||||
|
||||
|
@@ -76,19 +76,19 @@ abstract class SqlDriver {
|
||||
* @param list<string> $where result of adminer()->selectSearchProcess()
|
||||
* @param list<string> $group result of adminer()->selectColumnsProcess()[1]
|
||||
* @param list<string> $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"
|
||||
);
|
||||
|
@@ -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
|
||||
? '<p><a href="' . h(remove_from_uri("page") . "&page=" . ($page + 1)) . '" class="loadmore">' . lang('Load more data') . '</a>'
|
||||
. 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 "<fieldset>";
|
||||
if (JUSH != "simpledb") {
|
||||
|
@@ -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") {
|
||||
|
@@ -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() {
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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) {
|
||||
|
@@ -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))));
|
||||
|
@@ -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) {
|
||||
|
Reference in New Issue
Block a user