diff --git a/CHANGELOG.md b/CHANGELOG.md index 36e211f..b40e537 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ - Enh #288: Refactor `Schema::findColumns()` method (@Tigrov) - Enh #289: Refactor `Schema::normalizeDefaultValue()` method and move it to `ColumnFactory` class (@Tigrov) - New #292: Override `QueryBuilder::prepareBinary()` method (@Tigrov) +- Chg #294: Update `QueryBuilder` constructor (@Tigrov) ## 1.3.0 March 21, 2024 diff --git a/src/Connection.php b/src/Connection.php index 144dd7d..ac512cd 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -73,11 +73,11 @@ public function getLastInsertID(string $sequenceName = null): string public function getQueryBuilder(): QueryBuilderInterface { - if ($this->queryBuilder === null) { - $this->queryBuilder = new QueryBuilder($this->getQuoter(), $this->getSchema()); - } - - return $this->queryBuilder; + return $this->queryBuilder ??= new QueryBuilder( + $this->getQuoter(), + $this->getSchema(), + $this->getServerInfo(), + ); } public function getQuoter(): QuoterInterface diff --git a/src/QueryBuilder.php b/src/QueryBuilder.php index 72b579f..3492582 100644 --- a/src/QueryBuilder.php +++ b/src/QueryBuilder.php @@ -4,6 +4,7 @@ namespace Yiisoft\Db\Oracle; +use Yiisoft\Db\Connection\ServerInfoInterface; use Yiisoft\Db\Constant\ColumnType; use Yiisoft\Db\Constant\PseudoType; use Yiisoft\Db\Oracle\Column\ColumnDefinitionBuilder; @@ -47,14 +48,17 @@ final class QueryBuilder extends AbstractQueryBuilder PseudoType::UUID_PK => 'RAW(16) DEFAULT SYS_GUID() PRIMARY KEY', ]; - public function __construct(QuoterInterface $quoter, SchemaInterface $schema) + public function __construct(QuoterInterface $quoter, SchemaInterface $schema, ServerInfoInterface $serverInfo) { - $ddlBuilder = new DDLQueryBuilder($this, $quoter, $schema); - $dmlBuilder = new DMLQueryBuilder($this, $quoter, $schema); - $dqlBuilder = new DQLQueryBuilder($this, $quoter); - $columnDefinitionBuilder = new ColumnDefinitionBuilder($this); - - parent::__construct($quoter, $schema, $ddlBuilder, $dmlBuilder, $dqlBuilder, $columnDefinitionBuilder); + parent::__construct( + $quoter, + $schema, + $serverInfo, + new DDLQueryBuilder($this, $quoter, $schema), + new DMLQueryBuilder($this, $quoter, $schema), + new DQLQueryBuilder($this, $quoter), + new ColumnDefinitionBuilder($this), + ); } protected function prepareBinary(string $binary): string diff --git a/tests/SchemaTest.php b/tests/SchemaTest.php index a95e978..8a28a7e 100644 --- a/tests/SchemaTest.php +++ b/tests/SchemaTest.php @@ -92,7 +92,7 @@ public function testGetSchemaNames(): void $schema = $db->getSchema(); - if (version_compare($db->getServerVersion(), '12', '>')) { + if (version_compare($db->getServerInfo()->getVersion(), '12', '>')) { $this->assertContains('SYSBACKUP', $schema->getSchemaNames()); } else { $this->assertEmpty($schema->getSchemaNames());