Skip to content

Commit

Permalink
Fix bug with sub-query with alias as table name
Browse files Browse the repository at this point in the history
  • Loading branch information
Tigrov committed Sep 25, 2023
1 parent b259119 commit d9d1ee2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Schema/Quoter.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ function ($matches) {

public function quoteTableName(string $name): string
{
if (str_starts_with($name, '(') && str_ends_with($name, ')')) {
if (str_starts_with($name, '(')) {
return $name;
}

Expand Down
8 changes: 8 additions & 0 deletions tests/Db/Schema/QuoterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,12 @@ public function testQuoteSqlWithTablePrefix(): void

$this->assertSame('SELECT * FROM `prefix_table`', $quoter->quoteSql($sql));
}

public function testQuoteTableNameWithQueryAlias()
{
$quoter = new Quoter('`', '`', 'prefix_');
$name = '(SELECT * FROM table) alias';

$this->assertSame($name, $quoter->quoteTableName($name));
}
}

0 comments on commit d9d1ee2

Please sign in to comment.