From d90d8021088de41a347b4f070af795dd0e850601 Mon Sep 17 00:00:00 2001 From: Maxim Smakouz Date: Thu, 21 Dec 2023 18:39:56 +0200 Subject: [PATCH 1/3] Add a test with escaping leftJoin with an underscore at the beginning --- .../Driver/Common/Query/SelectQueryTest.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/Database/Functional/Driver/Common/Query/SelectQueryTest.php b/tests/Database/Functional/Driver/Common/Query/SelectQueryTest.php index 90f69101..72f12f1f 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 + ); + } } From 73c1f2b7d6dcb186000f534f33332306f1c63520 Mon Sep 17 00:00:00 2001 From: Maxim Smakouz Date: Thu, 21 Dec 2023 18:55:58 +0200 Subject: [PATCH 2/3] Fix preg_replace_callback pattern --- src/Driver/Quoter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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]; From b8911ea53f128d5c17edfce3f15704e88f2f43b3 Mon Sep 17 00:00:00 2001 From: Maxim Smakouz Date: Thu, 21 Dec 2023 18:57:28 +0200 Subject: [PATCH 3/3] Fix test --- .../Database/Functional/Driver/Common/Query/SelectQueryTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Database/Functional/Driver/Common/Query/SelectQueryTest.php b/tests/Database/Functional/Driver/Common/Query/SelectQueryTest.php index 72f12f1f..f9ac955b 100644 --- a/tests/Database/Functional/Driver/Common/Query/SelectQueryTest.php +++ b/tests/Database/Functional/Driver/Common/Query/SelectQueryTest.php @@ -2280,7 +2280,7 @@ public function testLeftJoinQuoting(): void ->on('SC3271.ID', '=', '_1SCONST2.OBJID'); $this->assertSameQuery( - 'SELECT * FROM {users} LEFT JOIN {_1SCONST} _1SCONST2([NOLOCK]) ON {SC3271}.{ID} = {_1SCONST2}.{OBJID}', + 'SELECT * FROM {users} LEFT JOIN {_1SCONST} _1SCONST2({NOLOCK}) ON {SC3271}.{ID} = {_1SCONST2}.{OBJID}', $select ); }