Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
- New #316: Realize `Schema::loadResultColumn()` method (@Tigrov)
- New #323: Use `DateTimeColumn` class for datetime column types (@Tigrov)
- Enh #324: Refactor `Command::insertWithReturningPks()` method (@Tigrov)
- Chg #326: Add alias in `DQLQueryBuilder::selectExists()` method for consistency with other DBMS (@Tigrov)

## 1.3.0 March 21, 2024

Expand Down
2 changes: 1 addition & 1 deletion src/DQLQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function buildOrderByAndLimit(

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

public function buildFrom(array|null $tables, array &$params): string
Expand Down
11 changes: 0 additions & 11 deletions tests/Provider/QueryBuilderProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,17 +119,6 @@ public static function insert(): array
return $insert;
}

public static function selectExist(): array
{
$selectExist = parent::selectExist();

$selectExist[0][1] = <<<SQL
SELECT CASE WHEN EXISTS(SELECT 1 FROM `table` WHERE `id` = 1) THEN 1 ELSE 0 END FROM DUAL
SQL;

return $selectExist;
}

public static function upsert(): array
{
$concreteData = [
Expand Down
12 changes: 9 additions & 3 deletions tests/QueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -451,10 +451,16 @@ public function testResetSequenceCompositeException(): void
$db->close();
}

#[DataProviderExternal(QueryBuilderProvider::class, 'selectExist')]
public function testSelectExists(string $sql, string $expected): void
public function testSelectExists(): void
{
parent::testSelectExists($sql, $expected);
$db = $this->getConnection();
$qb = $db->getQueryBuilder();

$sql = 'SELECT 1 FROM "customer" WHERE "id" = 1';
// Alias is not required in Oracle, but it is added for consistency with other DBMS.
$expected = 'SELECT CASE WHEN EXISTS(SELECT 1 FROM "customer" WHERE "id" = 1) THEN 1 ELSE 0 END AS "0" FROM DUAL';

$this->assertSame($expected, $qb->selectExists($sql));
}

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