Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6e04525

Browse files
authoredMay 29, 2025
Add alias in DQLQueryBuilder::selectExists() method for consistency (#326)
1 parent b0a8e0a commit 6e04525

File tree

4 files changed

+11
-15
lines changed

4 files changed

+11
-15
lines changed
 

‎CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
- New #316: Realize `Schema::loadResultColumn()` method (@Tigrov)
4747
- New #323: Use `DateTimeColumn` class for datetime column types (@Tigrov)
4848
- Enh #324: Refactor `Command::insertWithReturningPks()` method (@Tigrov)
49+
- Chg #326: Add alias in `DQLQueryBuilder::selectExists()` method for consistency with other DBMS (@Tigrov)
4950

5051
## 1.3.0 March 21, 2024
5152

‎src/DQLQueryBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function buildOrderByAndLimit(
5757

5858
public function selectExists(string $rawSql): string
5959
{
60-
return 'SELECT CASE WHEN EXISTS(' . $rawSql . ') THEN 1 ELSE 0 END FROM DUAL';
60+
return 'SELECT CASE WHEN EXISTS(' . $rawSql . ') THEN 1 ELSE 0 END AS "0" FROM DUAL';
6161
}
6262

6363
public function buildFrom(array|null $tables, array &$params): string

‎tests/Provider/QueryBuilderProvider.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -119,17 +119,6 @@ public static function insert(): array
119119
return $insert;
120120
}
121121

122-
public static function selectExist(): array
123-
{
124-
$selectExist = parent::selectExist();
125-
126-
$selectExist[0][1] = <<<SQL
127-
SELECT CASE WHEN EXISTS(SELECT 1 FROM `table` WHERE `id` = 1) THEN 1 ELSE 0 END FROM DUAL
128-
SQL;
129-
130-
return $selectExist;
131-
}
132-
133122
public static function upsert(): array
134123
{
135124
$concreteData = [

‎tests/QueryBuilderTest.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -451,10 +451,16 @@ public function testResetSequenceCompositeException(): void
451451
$db->close();
452452
}
453453

454-
#[DataProviderExternal(QueryBuilderProvider::class, 'selectExist')]
455-
public function testSelectExists(string $sql, string $expected): void
454+
public function testSelectExists(): void
456455
{
457-
parent::testSelectExists($sql, $expected);
456+
$db = $this->getConnection();
457+
$qb = $db->getQueryBuilder();
458+
459+
$sql = 'SELECT 1 FROM "customer" WHERE "id" = 1';
460+
// Alias is not required in Oracle, but it is added for consistency with other DBMS.
461+
$expected = 'SELECT CASE WHEN EXISTS(SELECT 1 FROM "customer" WHERE "id" = 1) THEN 1 ELSE 0 END AS "0" FROM DUAL';
462+
463+
$this->assertSame($expected, $qb->selectExists($sql));
458464
}
459465

460466
#[DataProviderExternal(QueryBuilderProvider::class, 'update')]

0 commit comments

Comments
 (0)