Skip to content

Commit

Permalink
Fix quoting with an underscore at the beginning (#151)
Browse files Browse the repository at this point in the history
  • Loading branch information
msmakouz authored Dec 21, 2023
1 parent d33b9c2 commit f68dd1b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Driver/Quoter.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public function quote(string $identifier, bool $isTable = false): string
private function expression(string $identifier): string
{
return preg_replace_callback(
'/([a-z][0-9_a-z\.]*\(?)/i',
'/([_a-z][0-9_a-z\.]*\(?)/i',
function ($match) {
$identifier = $match[1];

Expand Down
17 changes: 17 additions & 0 deletions tests/Database/Functional/Driver/Common/Query/SelectQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2267,4 +2267,21 @@ public function testFragmentInWhereInClause(): void
$select
);
}

/**
* Issue https://github.com/cycle/database/issues/49
*/
public function testLeftJoinQuoting(): void
{
$select = $this->database
->select()
->from(['users'])
->leftJoin('_1SCONST _1SCONST2(NOLOCK)')
->on('SC3271.ID', '=', '_1SCONST2.OBJID');

$this->assertSameQuery(
'SELECT * FROM {users} LEFT JOIN {_1SCONST} _1SCONST2({NOLOCK}) ON {SC3271}.{ID} = {_1SCONST2}.{OBJID}',
$select
);
}
}

0 comments on commit f68dd1b

Please sign in to comment.