From 1e6b86ea38d2d3a5675fa5e82aab429dfc8bac01 Mon Sep 17 00:00:00 2001 From: Sergei Tigrov Date: Sun, 8 Dec 2024 15:08:22 +0700 Subject: [PATCH] Update according to changes in `db` (#333) --- CHANGELOG.md | 1 + src/Connection.php | 13 +++++-------- src/QueryBuilder.php | 18 +++++++++++------- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ba1266690..b510d266e 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 79cca8b61..be8c297c1 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 f52d0dfea..2e174d553 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. */