Skip to content

Commit f37328e

Browse files
committed
Selection::page() for $page < 1 returns no rows
1 parent 15ccd8b commit f37328e

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/Database/Table/Selection.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,9 @@ public function page($page, $itemsPerPage, & $numOfPages = NULL)
374374
if (func_num_args() > 2) {
375375
$numOfPages = (int) ceil($this->count('*') / $itemsPerPage);
376376
}
377+
if ($page < 1) {
378+
$itemsPerPage = 0;
379+
}
377380
return $this->limit($itemsPerPage, ($page - 1) * $itemsPerPage);
378381
}
379382

tests/Database/Table/Table.limit.phpt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ Assert::same(
3333
);
3434

3535
Assert::same(
36-
reformat('SELECT * FROM [author] LIMIT 10'),
37-
$context->table('author')->page(0, 10)->getSql()
36+
reformat('SELECT * FROM [author] LIMIT 0'),
37+
$context->table('author')->page(0, 10, $count)->getSql()
3838
);
39+
Assert::same(1, $count);
3940

4041
Assert::same(
4142
reformat('SELECT * FROM [author] LIMIT 10 OFFSET 10'),

0 commit comments

Comments
 (0)