diff --git a/CHANGELOG.md b/CHANGELOG.md index ba126669..b510d266 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ - Enh #327: Refactor `Schema::findColumns()` method (@Tigrov) - Enh #328: Refactor `Schema::normalizeDefaultValue()` method and move it to `ColumnFactory` class (@Tigrov) - Enh #331: Refactor according to changes #902 in `yiisoft/db` package (@Tigrov) +- Chg #333: Update `QueryBuilder` constructor (@Tigrov) ## 1.2.0 March 21, 2024 diff --git a/src/Connection.php b/src/Connection.php index 79cca8b6..be8c297c 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -51,14 +51,11 @@ public function createTransaction(): TransactionInterface 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 f52d0dfe..2e174d55 100644 --- a/src/QueryBuilder.php +++ b/src/QueryBuilder.php @@ -4,6 +4,7 @@ namespace Yiisoft\Db\Mssql; +use Yiisoft\Db\Connection\ServerInfoInterface; use Yiisoft\Db\Constant\ColumnType; use Yiisoft\Db\Constant\PseudoType; use Yiisoft\Db\Mssql\Column\ColumnDefinitionBuilder; @@ -52,14 +53,17 @@ final class QueryBuilder extends AbstractQueryBuilder PseudoType::UUID_PK => 'UNIQUEIDENTIFIER 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), + ); } /** @deprecated Use {@see buildColumnDefinition()}. Will be removed in version 2.0. */