Skip to content

Commit 6621941

Browse files
committed
Fix bind parameter in LIMIT OFFSET
- Fixes #498 Signed-off-by: Maurício Meneghini Fauth <[email protected]>
1 parent 349a811 commit 6621941

File tree

3 files changed

+14
-33
lines changed

3 files changed

+14
-33
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/data/bugs/gh498.out

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,8 @@
346346
"order": null,
347347
"limit": {
348348
"@type": "PhpMyAdmin\\SqlParser\\Components\\Limit",
349-
"offset": 0,
350-
"rowCount": 0
349+
"offset": "?",
350+
"rowCount": "?"
351351
},
352352
"procedure": null,
353353
"into": null,
@@ -396,28 +396,6 @@
396396
},
397397
"errors": {
398398
"lexer": [],
399-
"parser": [
400-
[
401-
"Unexpected token.",
402-
{
403-
"@type": "@28"
404-
},
405-
0
406-
],
407-
[
408-
"Unrecognized keyword.",
409-
{
410-
"@type": "@30"
411-
},
412-
0
413-
],
414-
[
415-
"Unexpected token.",
416-
{
417-
"@type": "@32"
418-
},
419-
0
420-
]
421-
]
399+
"parser": []
422400
}
423401
}

0 commit comments

Comments
 (0)