diff --git a/src/Driver/Quoter.php b/src/Driver/Quoter.php index 8f0dd0a8..2515f548 100644 --- a/src/Driver/Quoter.php +++ b/src/Driver/Quoter.php @@ -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]; diff --git a/tests/Database/Functional/Driver/Common/Query/SelectQueryTest.php b/tests/Database/Functional/Driver/Common/Query/SelectQueryTest.php index 90f69101..f9ac955b 100644 --- a/tests/Database/Functional/Driver/Common/Query/SelectQueryTest.php +++ b/tests/Database/Functional/Driver/Common/Query/SelectQueryTest.php @@ -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 + ); + } }