From 924b6b55b7dfce672121d88dba678dc587f2c75d Mon Sep 17 00:00:00 2001 From: Andrey Pyzhikov <5071@mail.ru> Date: Tue, 17 May 2022 08:51:28 +0800 Subject: [PATCH 1/2] Changing the subquery builder for Oracle Signed-off-by: Andrey Pyzhikov <5071@mail.ru> --- system/Database/BaseBuilder.php | 2 +- tests/system/Database/Builder/FromTest.php | 8 ++++---- tests/system/Database/Builder/SelectTest.php | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/system/Database/BaseBuilder.php b/system/Database/BaseBuilder.php index be1aee7e1a60..b26b8484b13f 100644 --- a/system/Database/BaseBuilder.php +++ b/system/Database/BaseBuilder.php @@ -2846,7 +2846,7 @@ protected function buildSubquery($builder, bool $wrapped = false, string $alias $alias = trim($alias); if ($alias !== '') { - $subquery .= ' AS ' . ($this->db->protectIdentifiers ? $this->db->escapeIdentifiers($alias) : $alias); + $subquery .= ' ' . ($this->db->protectIdentifiers ? $this->db->escapeIdentifiers($alias) : $alias); } } diff --git a/tests/system/Database/Builder/FromTest.php b/tests/system/Database/Builder/FromTest.php index b0e3ee335035..05e24b05b3ff 100644 --- a/tests/system/Database/Builder/FromTest.php +++ b/tests/system/Database/Builder/FromTest.php @@ -103,19 +103,19 @@ public function testFromReset() public function testFromSubquery() { - $expectedSQL = 'SELECT * FROM (SELECT * FROM "users") AS "alias"'; + $expectedSQL = 'SELECT * FROM (SELECT * FROM "users") "alias"'; $subquery = new BaseBuilder('users', $this->db); $builder = $this->db->newQuery()->fromSubquery($subquery, 'alias'); $this->assertSame($expectedSQL, str_replace("\n", ' ', $builder->getCompiledSelect())); - $expectedSQL = 'SELECT * FROM (SELECT "id", "name" FROM "users") AS "users_1"'; + $expectedSQL = 'SELECT * FROM (SELECT "id", "name" FROM "users") "users_1"'; $subquery = (new BaseBuilder('users', $this->db))->select('id, name'); $builder = $this->db->newQuery()->fromSubquery($subquery, 'users_1'); $this->assertSame($expectedSQL, str_replace("\n", ' ', $builder->getCompiledSelect())); - $expectedSQL = 'SELECT * FROM (SELECT * FROM "users") AS "alias", "some_table"'; + $expectedSQL = 'SELECT * FROM (SELECT * FROM "users") "alias", "some_table"'; $subquery = new BaseBuilder('users', $this->db); $builder = $this->db->newQuery()->fromSubquery($subquery, 'alias')->from('some_table'); @@ -145,7 +145,7 @@ public function testFromSubqueryWithSQLSRV() $builder->fromSubquery($subquery, 'users_1'); - $expectedSQL = 'SELECT * FROM "test"."dbo"."jobs", (SELECT * FROM "test"."dbo"."users") AS "users_1"'; + $expectedSQL = 'SELECT * FROM "test"."dbo"."jobs", (SELECT * FROM "test"."dbo"."users") "users_1"'; $this->assertSame($expectedSQL, str_replace("\n", ' ', $builder->getCompiledSelect())); } diff --git a/tests/system/Database/Builder/SelectTest.php b/tests/system/Database/Builder/SelectTest.php index 808e581d6ce5..7c2c44bd246f 100644 --- a/tests/system/Database/Builder/SelectTest.php +++ b/tests/system/Database/Builder/SelectTest.php @@ -270,7 +270,7 @@ public function testSelectSubquery() $subquery->select('name')->where('id', 1); $builder->select('name')->selectSubquery($subquery, 'country'); - $expected = 'SELECT "name", (SELECT "name" FROM "countries" WHERE "id" = 1) AS "country" FROM "users"'; + $expected = 'SELECT "name", (SELECT "name" FROM "countries" WHERE "id" = 1) "country" FROM "users"'; $this->assertSame($expected, str_replace("\n", ' ', $builder->getCompiledSelect())); } From d21115993a5c3a761b02bb4d69364f6e8f439dab Mon Sep 17 00:00:00 2001 From: Andrey Pyzhikov <5071@mail.ru> Date: Tue, 17 May 2022 08:59:43 +0800 Subject: [PATCH 2/2] docs fix Signed-off-by: Andrey Pyzhikov <5071@mail.ru> --- user_guide_src/source/database/query_builder/015.php | 2 +- user_guide_src/source/database/query_builder/017.php | 2 +- user_guide_src/source/database/query_builder/018.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/user_guide_src/source/database/query_builder/015.php b/user_guide_src/source/database/query_builder/015.php index b3890e978005..b790e19e27d7 100644 --- a/user_guide_src/source/database/query_builder/015.php +++ b/user_guide_src/source/database/query_builder/015.php @@ -3,4 +3,4 @@ $subquery = $db->table('countries')->select('name')->where('id', 1); $builder = $db->table('users')->select('name')->selectSubquery($subquery, 'country'); $query = $builder->get(); -// Produces: SELECT `name`, (SELECT `name` FROM `countries` WHERE `id` = 1) AS `country` FROM `users` +// Produces: SELECT `name`, (SELECT `name` FROM `countries` WHERE `id` = 1) `country` FROM `users` diff --git a/user_guide_src/source/database/query_builder/017.php b/user_guide_src/source/database/query_builder/017.php index 1ad1c917ff57..d0487570b9bb 100644 --- a/user_guide_src/source/database/query_builder/017.php +++ b/user_guide_src/source/database/query_builder/017.php @@ -3,4 +3,4 @@ $subquery = $db->table('users'); $builder = $db->table('jobs')->fromSubquery($subquery, 'alias'); $query = $builder->get(); -// Produces: SELECT * FROM `jobs`, (SELECT * FROM `users`) AS `alias` +// Produces: SELECT * FROM `jobs`, (SELECT * FROM `users`) `alias` diff --git a/user_guide_src/source/database/query_builder/018.php b/user_guide_src/source/database/query_builder/018.php index b33dd475b6f8..26ee565a20c9 100644 --- a/user_guide_src/source/database/query_builder/018.php +++ b/user_guide_src/source/database/query_builder/018.php @@ -3,4 +3,4 @@ $subquery = $db->table('users')->select('id, name'); $builder = $db->newQuery()->fromSubquery($subquery, 't'); $query = $builder->get(); -// Produces: SELECT * FROM (SELECT `id`, `name` FROM users) AS `t` +// Produces: SELECT * FROM (SELECT `id`, `name` FROM users) `t`