Skip to content

Commit 5e34787

Browse files
committed
Tiny improvement to handle the columns if backtick is used
Example: SELECT `test3`.`t1` is not null AS `is_not_null` FROM `test3` Signed-off-by: iifawzi <[email protected]>
1 parent 7dc4b80 commit 5e34787

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

src/Components/Expression.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -379,12 +379,15 @@ public static function parse(Parser $parser, TokensList $list, array $options =
379379
--$list->idx;
380380
$beforeToken = $list->getPrevious();
381381
$list->idx = $currIdx;
382-
// columns names tokens are of type NONE, and the columns options
382+
// columns names tokens are of type NONE, or SYMBOL (`col`), and the columns options
383383
// would start with a token of type KEYWORD, in that case, we want to have a space
384384
// between the tokens.
385385
if (
386-
$ret->expr !== null && $beforeToken &&
387-
$beforeToken->type === Token::TYPE_NONE && $token->type === Token::TYPE_KEYWORD
386+
$ret->expr !== null &&
387+
$beforeToken &&
388+
($beforeToken->type === Token::TYPE_NONE ||
389+
$beforeToken->type === Token::TYPE_SYMBOL) &&
390+
$token->type === Token::TYPE_KEYWORD
388391
) {
389392
$ret->expr = rtrim($ret->expr, ' ') . ' ';
390393
}

tests/Builder/SelectStatementTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ public function testBuilderUnion(): void
3737

3838
public function testBuilderWithIsNull(): void
3939
{
40-
$parser = new Parser('SELECT test3.t1 is not null AS `col1` FROM test3');
40+
$parser = new Parser('SELECT `test3`.`t1` is not null AS `is_not_null` FROM `test3` ;');
4141
$stmt = $parser->statements[0];
4242

43-
$this->assertEquals('SELECT test3.t1 is not null AS `col1` FROM test3', $stmt->build());
43+
$this->assertEquals('SELECT `test3`.`t1` is not null AS `is_not_null` FROM `test3`', $stmt->build());
4444

4545
$parser = new Parser('SELECT test3.t1 is null AS `col1` FROM test3');
4646
$stmt = $parser->statements[0];

0 commit comments

Comments
 (0)