Skip to content

Commit 4e288e8

Browse files
Merge pull request #516 from MauricioFauth/limit-param
Fix bind parameter in LIMIT OFFSET
2 parents 24d734a + 6621941 commit 4e288e8

File tree

5 files changed

+417
-8
lines changed

5 files changed

+417
-8
lines changed

phpstan-baseline.neon

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,12 +271,12 @@ parameters:
271271
path: src/Components/Key.php
272272

273273
-
274-
message: "#^Property PhpMyAdmin\\\\SqlParser\\\\Components\\\\Limit\\:\\:\\$offset \\(int\\) does not accept mixed\\.$#"
274+
message: "#^Property PhpMyAdmin\\\\SqlParser\\\\Components\\\\Limit\\:\\:\\$offset \\(int\\|string\\) does not accept mixed\\.$#"
275275
count: 1
276276
path: src/Components/Limit.php
277277

278278
-
279-
message: "#^Property PhpMyAdmin\\\\SqlParser\\\\Components\\\\Limit\\:\\:\\$rowCount \\(int\\) does not accept mixed\\.$#"
279+
message: "#^Property PhpMyAdmin\\\\SqlParser\\\\Components\\\\Limit\\:\\:\\$rowCount \\(int\\|string\\) does not accept mixed\\.$#"
280280
count: 1
281281
path: src/Components/Limit.php
282282

src/Components/Limit.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,20 @@ class Limit extends Component
1919
/**
2020
* The number of rows skipped.
2121
*
22-
* @var int
22+
* @var int|string
2323
*/
2424
public $offset;
2525

2626
/**
2727
* The number of rows to be returned.
2828
*
29-
* @var int
29+
* @var int|string
3030
*/
3131
public $rowCount;
3232

3333
/**
34-
* @param int $rowCount the row count
35-
* @param int $offset the offset
34+
* @param int|string $rowCount the row count
35+
* @param int|string $offset the offset
3636
*/
3737
public function __construct($rowCount = 0, $offset = 0)
3838
{
@@ -88,8 +88,11 @@ public static function parse(Parser $parser, TokensList $list, array $options =
8888
continue;
8989
}
9090

91-
// Skip if not a number
92-
if (($token->type !== Token::TYPE_NUMBER)) {
91+
// Skip if not a number or a bind parameter (?)
92+
if (
93+
! ($token->type === Token::TYPE_NUMBER
94+
|| ($token->type === Token::TYPE_SYMBOL && ($token->flags & Token::FLAG_SYMBOL_PARAMETER)))
95+
) {
9396
break;
9497
}
9598

tests/Misc/BugsTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public function bugProvider(): array
3535
['bugs/gh412'],
3636
['bugs/gh478'],
3737
['bugs/gh492'],
38+
['bugs/gh498'],
3839
['bugs/gh499'],
3940
['bugs/gh508'],
4041
['bugs/gh511'],

tests/data/bugs/gh498.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
SELECT ?
2+
FROM uno
3+
JOIN dos ON dos.id = uno.id
4+
LIMIT ? OFFSET ?

0 commit comments

Comments
 (0)