Skip to content

Commit 8ae80e9

Browse files
committed
Merge branch 'QA'
2 parents 37c4bae + e68b29f commit 8ae80e9

5 files changed

Lines changed: 40 additions & 18 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Change Log
22

3+
# [5.4.2] - YYYY-MM-DD
4+
- Added check for quoted symbol to avoid parser error in case of keyword (#317)
5+
36
## [5.4.1] - 2020-10-15
47
* Fix array_key_exists warning when parsing a "DEFAULT FALSE" token (#299)
58

@@ -57,6 +60,9 @@
5760
* Fix for error message with multiple CALL statements (#223)
5861
* Recognize the question mark character as a parameter (#242)
5962

63+
# [4.7.2] - YYYY-MM-DD
64+
- Added check for quoted symbol to avoid parser error in case of keyword (#317)
65+
6066
## [4.7.1] - 2020-10-15
6167
* Fix array_key_exists warning when parsing a "DEFAULT FALSE" token (#299)
6268

src/Components/AlterOperation.php

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -278,30 +278,31 @@ public static function parse(Parser $parser, TokensList $list, array $options =
278278
} elseif (($token->value === ',') && ($brackets === 0)) {
279279
break;
280280
}
281-
} elseif (! empty(Parser::$STATEMENT_PARSERS[$token->value])) {
282-
// We have reached the end of ALTER operation and suddenly found
283-
// a start to new statement, but have not find a delimiter between them
284-
285-
if (! ($token->value === 'SET' && $list->tokens[$list->idx - 1]->value === 'CHARACTER')) {
281+
} elseif (! self::checkIfTokenQuotedSymbol($token)) {
282+
if (! empty(Parser::$STATEMENT_PARSERS[$token->value])) {
283+
// We have reached the end of ALTER operation and suddenly found
284+
// a start to new statement, but have not find a delimiter between them
285+
286+
if (! ($token->value === 'SET' && $list->tokens[$list->idx - 1]->value === 'CHARACTER')) {
287+
$parser->error(
288+
'A new statement was found, but no delimiter between it and the previous one.',
289+
$token
290+
);
291+
break;
292+
}
293+
} elseif ((array_key_exists($array_key, self::$DB_OPTIONS)
294+
|| array_key_exists($array_key, self::$TABLE_OPTIONS))
295+
&& ! self::checkIfColumnDefinitionKeyword($array_key)
296+
) {
297+
// This alter operation has finished, which means a comma
298+
// was missing before start of new alter operation
286299
$parser->error(
287-
'A new statement was found, but no delimiter between it and the previous one.',
300+
'Missing comma before start of a new alter operation.',
288301
$token
289302
);
290303
break;
291304
}
292-
} elseif ((array_key_exists($array_key, self::$DB_OPTIONS)
293-
|| array_key_exists($array_key, self::$TABLE_OPTIONS))
294-
&& ! self::checkIfColumnDefinitionKeyword($array_key)
295-
) {
296-
// This alter operation has finished, which means a comma
297-
// was missing before start of new alter operation
298-
$parser->error(
299-
'Missing comma before start of a new alter operation.',
300-
$token
301-
);
302-
break;
303305
}
304-
305306
$ret->unknown[] = $token;
306307
}
307308
}
@@ -362,4 +363,16 @@ private static function checkIfColumnDefinitionKeyword($tokenValue)
362363
// both table as well as a specific column in the table
363364
return in_array($tokenValue, $common_options);
364365
}
366+
367+
/**
368+
* Check if token is symbol and quoted with backtick
369+
*
370+
* @param Token $token token to check
371+
*
372+
* @return bool
373+
*/
374+
private static function checkIfTokenQuotedSymbol($token)
375+
{
376+
return $token->type === Token::TYPE_SYMBOL && $token->flags === Token::FLAG_SYMBOL_BACKTICK;
377+
}
365378
}

tests/Misc/BugsTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public function bugProvider()
2424
['bugs/gh9'],
2525
['bugs/gh14'],
2626
['bugs/gh16'],
27+
['bugs/gh317'],
2728
['bugs/pma11800'],
2829
['bugs/pma11836'],
2930
['bugs/pma11843'],

tests/data/bugs/gh317.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE `demo` ADD KEY `IDX_REPAIR` (`REPAIR`);

tests/data/bugs/gh317.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
a:4:{s:5:"query";s:51:"ALTER TABLE `demo` ADD KEY `IDX_REPAIR` (`REPAIR`);";s:5:"lexer";O:26:"PhpMyAdmin\SqlParser\Lexer":8:{s:3:"str";s:51:"ALTER TABLE `demo` ADD KEY `IDX_REPAIR` (`REPAIR`);";s:3:"len";i:51;s:4:"last";i:51;s:4:"list";O:31:"PhpMyAdmin\SqlParser\TokensList":3:{s:6:"tokens";a:17:{i:0;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:5:"ALTER";s:5:"value";s:5:"ALTER";s:7:"keyword";s:5:"ALTER";s:4:"type";i:1;s:5:"flags";i:3;s:8:"position";i:0;}i:1;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:1:" ";s:5:"value";s:1:" ";s:7:"keyword";N;s:4:"type";i:3;s:5:"flags";i:0;s:8:"position";i:5;}i:2;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:5:"TABLE";s:5:"value";s:5:"TABLE";s:7:"keyword";s:5:"TABLE";s:4:"type";i:1;s:5:"flags";i:3;s:8:"position";i:6;}i:3;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:1:" ";s:5:"value";s:1:" ";s:7:"keyword";N;s:4:"type";i:3;s:5:"flags";i:0;s:8:"position";i:11;}i:4;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:6:"`demo`";s:5:"value";s:4:"demo";s:7:"keyword";N;s:4:"type";i:8;s:5:"flags";i:2;s:8:"position";i:12;}i:5;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:1:" ";s:5:"value";s:1:" ";s:7:"keyword";N;s:4:"type";i:3;s:5:"flags";i:0;s:8:"position";i:18;}i:6;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:3:"ADD";s:5:"value";s:3:"ADD";s:7:"keyword";s:3:"ADD";s:4:"type";i:1;s:5:"flags";i:3;s:8:"position";i:19;}i:7;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:1:" ";s:5:"value";s:1:" ";s:7:"keyword";N;s:4:"type";i:3;s:5:"flags";i:0;s:8:"position";i:22;}i:8;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:3:"KEY";s:5:"value";s:3:"KEY";s:7:"keyword";s:3:"KEY";s:4:"type";i:1;s:5:"flags";i:19;s:8:"position";i:23;}i:9;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:1:" ";s:5:"value";s:1:" ";s:7:"keyword";N;s:4:"type";i:3;s:5:"flags";i:0;s:8:"position";i:26;}i:10;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:12:"`IDX_REPAIR`";s:5:"value";s:10:"IDX_REPAIR";s:7:"keyword";N;s:4:"type";i:8;s:5:"flags";i:2;s:8:"position";i:27;}i:11;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:1:" ";s:5:"value";s:1:" ";s:7:"keyword";N;s:4:"type";i:3;s:5:"flags";i:0;s:8:"position";i:39;}i:12;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:1:"(";s:5:"value";s:1:"(";s:7:"keyword";N;s:4:"type";i:2;s:5:"flags";i:16;s:8:"position";i:40;}i:13;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:8:"`REPAIR`";s:5:"value";s:6:"REPAIR";s:7:"keyword";N;s:4:"type";i:8;s:5:"flags";i:2;s:8:"position";i:41;}i:14;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:1:")";s:5:"value";s:1:")";s:7:"keyword";N;s:4:"type";i:2;s:5:"flags";i:16;s:8:"position";i:49;}i:15;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:1:";";s:5:"value";s:1:";";s:7:"keyword";N;s:4:"type";i:9;s:5:"flags";i:0;s:8:"position";i:50;}i:16;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";N;s:5:"value";N;s:7:"keyword";N;s:4:"type";i:9;s:5:"flags";i:0;s:8:"position";N;}}s:5:"count";i:17;s:3:"idx";i:17;}s:9:"delimiter";s:1:";";s:12:"delimiterLen";i:1;s:6:"strict";b:0;s:6:"errors";a:0:{}}s:6:"parser";O:27:"PhpMyAdmin\SqlParser\Parser":5:{s:4:"list";r:7;s:10:"statements";a:1:{i:0;O:46:"PhpMyAdmin\SqlParser\Statements\AlterStatement":5:{s:5:"table";O:42:"PhpMyAdmin\SqlParser\Components\Expression":7:{s:8:"database";N;s:5:"table";s:4:"demo";s:6:"column";N;s:4:"expr";s:6:"`demo`";s:5:"alias";N;s:8:"function";N;s:8:"subquery";N;}s:7:"altered";a:1:{i:0;O:46:"PhpMyAdmin\SqlParser\Components\AlterOperation":3:{s:7:"options";O:44:"PhpMyAdmin\SqlParser\Components\OptionsArray":1:{s:7:"options";a:2:{i:1;s:3:"ADD";i:2;s:3:"KEY";}}s:5:"field";O:42:"PhpMyAdmin\SqlParser\Components\Expression":7:{s:8:"database";N;s:5:"table";N;s:6:"column";s:10:"IDX_REPAIR";s:4:"expr";s:12:"`IDX_REPAIR`";s:5:"alias";N;s:8:"function";N;s:8:"subquery";N;}s:7:"unknown";a:3:{i:0;r:93;i:1;r:100;i:2;r:107;}}}s:7:"options";O:44:"PhpMyAdmin\SqlParser\Components\OptionsArray":1:{s:7:"options";a:1:{i:3;s:5:"TABLE";}}s:5:"first";i:0;s:4:"last";i:15;}}s:8:"brackets";i:0;s:6:"strict";b:0;s:6:"errors";a:0:{}}s:6:"errors";a:2:{s:5:"lexer";a:0:{}s:6:"parser";a:0:{}}}

0 commit comments

Comments
 (0)