Skip to content

Commit

Permalink
Fix bind parameter in LIMIT OFFSET
Browse files Browse the repository at this point in the history
- Fixes #498

Signed-off-by: Maurício Meneghini Fauth <[email protected]>
  • Loading branch information
MauricioFauth committed Sep 27, 2023
1 parent 349a811 commit 38444dc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 31 deletions.
15 changes: 9 additions & 6 deletions src/Components/Limit.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@ class Limit extends Component
/**
* The number of rows skipped.
*
* @var int
* @var int|string
*/
public $offset;

/**
* The number of rows to be returned.
*
* @var int
* @var int|string
*/
public $rowCount;

/**
* @param int $rowCount the row count
* @param int $offset the offset
* @param int|string $rowCount the row count
* @param int|string $offset the offset
*/
public function __construct($rowCount = 0, $offset = 0)
{
Expand Down Expand Up @@ -88,8 +88,11 @@ public static function parse(Parser $parser, TokensList $list, array $options =
continue;
}

// Skip if not a number
if (($token->type !== Token::TYPE_NUMBER)) {
// Skip if not a number or a bind parameter (?)
if (
! ($token->type === Token::TYPE_NUMBER
|| ($token->type === Token::TYPE_SYMBOL && ($token->flags & Token::FLAG_SYMBOL_PARAMETER)))
) {
break;
}

Expand Down
28 changes: 3 additions & 25 deletions tests/data/bugs/gh498.out
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,8 @@
"order": null,
"limit": {
"@type": "PhpMyAdmin\\SqlParser\\Components\\Limit",
"offset": 0,
"rowCount": 0
"offset": "?",
"rowCount": "?"
},
"procedure": null,
"into": null,
Expand Down Expand Up @@ -396,28 +396,6 @@
},
"errors": {
"lexer": [],
"parser": [
[
"Unexpected token.",
{
"@type": "@28"
},
0
],
[
"Unrecognized keyword.",
{
"@type": "@30"
},
0
],
[
"Unexpected token.",
{
"@type": "@32"
},
0
]
]
"parser": []
}
}

0 comments on commit 38444dc

Please sign in to comment.