From 66219412c4d2b11b46f9e404071987441d9daedd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Wed, 27 Sep 2023 11:52:22 -0300 Subject: [PATCH] Fix bind parameter in LIMIT OFFSET MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Fixes #498 Signed-off-by: MaurĂ­cio Meneghini Fauth --- phpstan-baseline.neon | 4 ++-- src/Components/Limit.php | 15 +++++++++------ tests/data/bugs/gh498.out | 28 +++------------------------- 3 files changed, 14 insertions(+), 33 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 0d1a703fe..cb9ed9efc 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -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 diff --git a/src/Components/Limit.php b/src/Components/Limit.php index af4ff5923..172fd3074 100644 --- a/src/Components/Limit.php +++ b/src/Components/Limit.php @@ -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) { @@ -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; } diff --git a/tests/data/bugs/gh498.out b/tests/data/bugs/gh498.out index 44fbc5a21..1b4e5d533 100644 --- a/tests/data/bugs/gh498.out +++ b/tests/data/bugs/gh498.out @@ -346,8 +346,8 @@ "order": null, "limit": { "@type": "PhpMyAdmin\\SqlParser\\Components\\Limit", - "offset": 0, - "rowCount": 0 + "offset": "?", + "rowCount": "?" }, "procedure": null, "into": null, @@ -396,28 +396,6 @@ }, "errors": { "lexer": [], - "parser": [ - [ - "Unexpected token.", - { - "@type": "@28" - }, - 0 - ], - [ - "Unrecognized keyword.", - { - "@type": "@30" - }, - 0 - ], - [ - "Unexpected token.", - { - "@type": "@32" - }, - 0 - ] - ] + "parser": [] } } \ No newline at end of file