diff --git a/CHANGELOG.md b/CHANGELOG.md index cff751e..b8321f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - Enh #248: Change property `Schema::$typeMap` to constant `Schema::TYPE_MAP` (@Tigrov) - Bug #250: Fix `Command::insertWithReturningPks()` method for table without primary keys (@Tigrov) - Enh #251: Allow to use `DMLQueryBuilderInterface::batchInsert()` method with empty columns (@Tigrov) +- Bug #238: Fix execution `Query` without table(s) to select from (@Tigrov) ## 1.2.0 November 12, 2023 diff --git a/src/DQLQueryBuilder.php b/src/DQLQueryBuilder.php index d8ce2d3..c2a95cd 100644 --- a/src/DQLQueryBuilder.php +++ b/src/DQLQueryBuilder.php @@ -61,6 +61,15 @@ public function selectExists(string $rawSql): string return 'SELECT CASE WHEN EXISTS(' . $rawSql . ') THEN 1 ELSE 0 END FROM DUAL'; } + public function buildFrom(array|null $tables, array &$params): string + { + if (empty($tables)) { + return 'FROM DUAL'; + } + + return parent::buildFrom($tables, $params); + } + public function buildWithQueries(array $withs, array &$params): string { /** @psalm-var array{query:string|Query, alias:ExpressionInterface|string, recursive:bool}[] $withs */ diff --git a/tests/QueryBuilderTest.php b/tests/QueryBuilderTest.php index 45dff5a..e4ce2c6 100644 --- a/tests/QueryBuilderTest.php +++ b/tests/QueryBuilderTest.php @@ -230,7 +230,7 @@ public function testBuildWithLimit(): void $this->assertSame( <<assertSame( << 10 SQL, $sql,