Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing the subquery builder for the Oracle #5999

Merged
merged 2 commits into from
May 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion system/Database/BaseBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
8 changes: 4 additions & 4 deletions tests/system/Database/Builder/FromTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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()));
}
Expand Down
2 changes: 1 addition & 1 deletion tests/system/Database/Builder/SelectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
Expand Down
2 changes: 1 addition & 1 deletion user_guide_src/source/database/query_builder/015.php
Original file line number Diff line number Diff line change
Expand Up @@ -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`
2 changes: 1 addition & 1 deletion user_guide_src/source/database/query_builder/017.php
Original file line number Diff line number Diff line change
Expand Up @@ -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`
2 changes: 1 addition & 1 deletion user_guide_src/source/database/query_builder/018.php
Original file line number Diff line number Diff line change
Expand Up @@ -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`