Skip to content

Commit 6aa387c

Browse files
Merge pull request #19586 from kamil-tekiela/Fix-views-row-count
Fix view row count
2 parents eb8e93c + a38c648 commit 6aa387c

3 files changed

Lines changed: 14 additions & 24 deletions

File tree

phpstan-baseline.neon

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6381,7 +6381,7 @@ parameters:
63816381
-
63826382
message: '#^Loose comparison via "\=\=" is not allowed\.$#'
63836383
identifier: equal.notAllowed
6384-
count: 8
6384+
count: 7
63856385
path: src/Display/Results.php
63866386

63876387
-
@@ -6528,12 +6528,6 @@ parameters:
65286528
count: 2
65296529
path: src/Display/Results.php
65306530

6531-
-
6532-
message: '#^Parameter \#1 \$value of static method PhpMyAdmin\\Util\:\:formatNumber\(\) expects float\|int\|string, int\|string\|false given\.$#'
6533-
identifier: argument.type
6534-
count: 1
6535-
path: src/Display/Results.php
6536-
65376531
-
65386532
message: '#^Parameter \#2 \$field of class PhpMyAdmin\\Display\\ForeignKeyRelatedTable constructor expects string, mixed given\.$#'
65396533
identifier: argument.type
@@ -6636,12 +6630,6 @@ parameters:
66366630
count: 1
66376631
path: src/Display/Results.php
66386632

6639-
-
6640-
message: '#^Property PhpMyAdmin\\Display\\Results\:\:\$unlimNumRows \(int\|numeric\-string\|false\) is never assigned false so it can be removed from the property type\.$#'
6641-
identifier: property.unusedType
6642-
count: 1
6643-
path: src/Display/Results.php
6644-
66456633
-
66466634
message: '#^Property PhpMyAdmin\\FieldMetadata\:\:\$name \(string\) does not accept mixed\.$#'
66476635
identifier: assign.propertyType

src/Display/Results.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,9 @@ class Results
112112
/**
113113
* the total number of rows returned by the SQL query without any appended "LIMIT" clause programmatically
114114
*
115-
* @var int|numeric-string|false
115+
* @var int|numeric-string
116116
*/
117-
private int|string|false $unlimNumRows = 0;
117+
private int|string $unlimNumRows = 0;
118118

119119
/**
120120
* meta information about fields
@@ -613,7 +613,7 @@ private function getTableNavigation(
613613
[$pageSelector, $numberTotalPage] = $this->getHtmlPageSelector();
614614
}
615615

616-
$isLastPage = $this->unlimNumRows !== -1 && $this->unlimNumRows !== false
616+
$isLastPage = $this->unlimNumRows !== -1
617617
&& ($isShowingAll
618618
|| ($this->isExactCount()
619619
&& (int) $_SESSION['tmpval']['pos'] + (int) $_SESSION['tmpval']['max_rows']
@@ -658,7 +658,7 @@ private function getTableNavigation(
658658
'pos_next' => $posNext,
659659
'pos_last' => $posLast,
660660
'is_last_page' => $isLastPage,
661-
'is_last_page_known' => $this->unlimNumRows !== false,
661+
'is_last_page_known' => $this->unlimNumRows !== -1,
662662
'onsubmit' => $onsubmit,
663663
];
664664
}
@@ -3348,8 +3348,6 @@ private function setMessageInformation(
33483348
string $preCount,
33493349
string $afterCount,
33503350
): Message {
3351-
$unlimNumRows = $this->unlimNumRows; // To use in isset()
3352-
33533351
if (! empty($statementInfo->statement->limit)) {
33543352
$firstShownRec = $statementInfo->statement->limit->offset;
33553353
$rowCount = $statementInfo->statement->limit->rowCount;
@@ -3369,7 +3367,7 @@ private function setMessageInformation(
33693367

33703368
$messageViewWarning = false;
33713369
$table = new Table($this->table, $this->db, $this->dbi);
3372-
if ($table->isView() && $total == $this->config->settings['MaxExactCountViews']) {
3370+
if ($table->isView() && $total === -1) {
33733371
$message = Message::notice(
33743372
__(
33753373
'This view has at least this number of rows. Please refer to %sdocumentation%s.',
@@ -3393,12 +3391,12 @@ private function setMessageInformation(
33933391
$message->addText('(');
33943392

33953393
if ($messageViewWarning === false) {
3396-
if ($unlimNumRows != $total) {
3394+
if ($this->unlimNumRows != $total) {
33973395
$messageTotal = Message::notice(
33983396
$preCount . __('%1$s total, %2$s in query'),
33993397
);
34003398
$messageTotal->addParam(Util::formatNumber($total, 0));
3401-
$messageTotal->addParam(Util::formatNumber($unlimNumRows, 0));
3399+
$messageTotal->addParam(Util::formatNumber($this->unlimNumRows, 0));
34023400
} else {
34033401
$messageTotal = Message::notice($preCount . __('%s total'));
34043402
$messageTotal->addParam(Util::formatNumber($total, 0));

src/Table/Table.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ public function countRecords(bool $forceExact = false): int
666666
// count could bring down a server, so we offer an
667667
// alternative: setting MaxExactCountViews to 0 will bypass
668668
// completely the record counting for views
669-
$rowCount = false;
669+
return -1;
670670
} else {
671671
// Counting all rows of a VIEW could be too long,
672672
// so use a LIMIT clause.
@@ -679,6 +679,10 @@ public function countRecords(bool $forceExact = false): int
679679
);
680680
if ($result) {
681681
$rowCount = $result->numRows();
682+
if ((int) $rowCount === $config->settings['MaxExactCountViews']) {
683+
// If we reached the limit, we can't be sure how many rows there are
684+
return -1;
685+
}
682686
}
683687
}
684688

@@ -688,7 +692,7 @@ public function countRecords(bool $forceExact = false): int
688692
return (int) $rowCount;
689693
}
690694

691-
return 0;
695+
return -1;
692696
}
693697

694698
/**

0 commit comments

Comments
 (0)