Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/Parsers/OptionsArrays.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use PhpMyAdmin\SqlParser\Components\OptionsArray;
use PhpMyAdmin\SqlParser\Parseable;
use PhpMyAdmin\SqlParser\Parser;
use PhpMyAdmin\SqlParser\Token;
use PhpMyAdmin\SqlParser\TokensList;
use PhpMyAdmin\SqlParser\TokenType;
use PhpMyAdmin\SqlParser\Translator;
Expand Down Expand Up @@ -86,7 +87,24 @@ public static function parse(Parser $parser, TokensList $list, array $options =
}

if ($lastOption === null) {
$upper = strtoupper($token->token);
// Backtick-enclosed option names (e.g. `PAGE_COMPRESSED`=1) are
// produced by MariaDB. We accept them only when followed by '='
// so that regular quoted identifiers are not mistaken for options.
if ($token->type === TokenType::Symbol && $token->flags === Token::FLAG_SYMBOL_BACKTICK) {
$nextIdx = $list->idx + 1;
while ($nextIdx < $list->count && $list->tokens[$nextIdx]->type === TokenType::Whitespace) {
++$nextIdx;
}

if ($nextIdx >= $list->count || $list->tokens[$nextIdx]->token !== '=') {
break;
}

$upper = strtoupper((string) $token->value);
} else {
$upper = strtoupper($token->token);
}

if (! isset($options[$upper])) {
// There is no option to be processed.
break;
Expand Down
12 changes: 12 additions & 0 deletions tests/Builder/CreateStatementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,18 @@ public function testBuilderCompressed(): void
);
}

public function testBuilderCompressedBackticks(): void
{
$parser = new Parser(
'CREATE TABLE users ( user_id int ) `PAGE_COMPRESSED`=1 `PAGE_COMPRESSION_LEVEL`=9;',
);
$stmt = $parser->statements[0];
$this->assertEquals(
"CREATE TABLE users (\n `user_id` int\n) PAGE_COMPRESSED=1 PAGE_COMPRESSION_LEVEL=9",
$stmt->build(),
);
}

public function testBuilderCollate(): void
{
$parser = new Parser(
Expand Down