Skip to content

Commit

Permalink
Merge pull request #516 from MauricioFauth/limit-param
Browse files Browse the repository at this point in the history
Fix bind parameter in LIMIT OFFSET
  • Loading branch information
MauricioFauth committed Sep 27, 2023
2 parents 24d734a + 6621941 commit 4e288e8
Show file tree
Hide file tree
Showing 5 changed files with 417 additions and 8 deletions.
4 changes: 2 additions & 2 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -271,12 +271,12 @@ parameters:
path: src/Components/Key.php

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

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

Expand Down
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
1 change: 1 addition & 0 deletions tests/Misc/BugsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public function bugProvider(): array
['bugs/gh412'],
['bugs/gh478'],
['bugs/gh492'],
['bugs/gh498'],
['bugs/gh499'],
['bugs/gh508'],
['bugs/gh511'],
Expand Down
4 changes: 4 additions & 0 deletions tests/data/bugs/gh498.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SELECT ?
FROM uno
JOIN dos ON dos.id = uno.id
LIMIT ? OFFSET ?

0 comments on commit 4e288e8

Please sign in to comment.