From dddc3dc2935c808ec9215f7f907b64e333b28dd2 Mon Sep 17 00:00:00 2001 From: Sergei Tigrov Date: Sun, 8 Dec 2024 15:08:15 +0700 Subject: [PATCH] Update according changes in `db` (#375) --- CHANGELOG.md | 1 + src/Connection.php | 13 +++++-------- src/QueryBuilder.php | 18 +++++++++++------- src/Schema.php | 2 +- tests/QueryBuilderTest.php | 2 +- tests/SchemaTest.php | 8 ++++---- 6 files changed, 23 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7860c5aa3..1730fb3b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ - Enh #366: Use constructor to create columns and initialize properties (@Tigrov) - Enh #370: Refactor `Schema::normalizeDefaultValue()` method and move it to `ColumnFactory` class (@Tigrov) - New #373: Override `QueryBuilder::prepareBinary()` method (@Tigrov) +- Chg #375: Update `QueryBuilder` constructor (@Tigrov) ## 1.3.0 March 21, 2024 diff --git a/src/Connection.php b/src/Connection.php index 46b57fc43..bacf9c587 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -55,14 +55,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 b46c021f9..a8a9b21be 100644 --- a/src/QueryBuilder.php +++ b/src/QueryBuilder.php @@ -4,6 +4,7 @@ namespace Yiisoft\Db\Pgsql; +use Yiisoft\Db\Connection\ServerInfoInterface; use Yiisoft\Db\Constant\ColumnType; use Yiisoft\Db\Constant\PseudoType; use Yiisoft\Db\Pgsql\Column\ColumnDefinitionBuilder; @@ -50,14 +51,17 @@ final class QueryBuilder extends AbstractQueryBuilder PseudoType::UUID_PK => 'uuid 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/src/Schema.php b/src/Schema.php index ad7a269ef..a2f6f1e73 100644 --- a/src/Schema.php +++ b/src/Schema.php @@ -611,7 +611,7 @@ protected function findColumns(TableSchemaInterface $table): bool { $orIdentity = ''; - if (version_compare($this->db->getServerVersion(), '12.0', '>=')) { + if (version_compare($this->db->getServerInfo()->getVersion(), '12.0', '>=')) { $orIdentity = 'OR a.attidentity != \'\''; } diff --git a/tests/QueryBuilderTest.php b/tests/QueryBuilderTest.php index a1c8e4856..acd6ce97c 100644 --- a/tests/QueryBuilderTest.php +++ b/tests/QueryBuilderTest.php @@ -583,7 +583,7 @@ public function testResetSequence(): void */ public function testResetSequencePgsql12(): void { - if (version_compare($this->getConnection()->getServerVersion(), '12.0', '<')) { + if (version_compare($this->getConnection()->getServerInfo()->getVersion(), '12.0', '<')) { $this->markTestSkipped('PostgreSQL < 12.0 does not support GENERATED AS IDENTITY columns.'); } diff --git a/tests/SchemaTest.php b/tests/SchemaTest.php index 07cf296c5..4c3762d28 100644 --- a/tests/SchemaTest.php +++ b/tests/SchemaTest.php @@ -65,7 +65,7 @@ public function testColumnSchema(array $columns, string $tableName): void { $db = $this->getConnection(); - if (version_compare($db->getServerVersion(), '10', '>')) { + if (version_compare($db->getServerInfo()->getVersion(), '10', '>')) { if ($tableName === 'type') { $columns['ts_default']['defaultValue'] = new Expression('CURRENT_TIMESTAMP'); } @@ -111,7 +111,7 @@ public function testGeneratedValues(): void { $this->fixture = 'pgsql12.sql'; - if (version_compare($this->getConnection()->getServerVersion(), '12.0', '<')) { + if (version_compare($this->getConnection()->getServerInfo()->getVersion(), '12.0', '<')) { $this->markTestSkipped('PostgresSQL < 12.0 does not support GENERATED AS IDENTITY columns.'); } @@ -251,7 +251,7 @@ public function testPartitionedTable(): void { $this->fixture = 'pgsql10.sql'; - if (version_compare($this->getConnection()->getServerVersion(), '10.0', '<')) { + if (version_compare($this->getConnection()->getServerInfo()->getVersion(), '10.0', '<')) { $this->markTestSkipped('PostgresSQL < 10.0 does not support PARTITION BY clause.'); } @@ -603,7 +603,7 @@ public function testTableIndexes(): void { $this->fixture = 'pgsql11.sql'; - if (version_compare($this->getConnection()->getServerVersion(), '11.0', '<')) { + if (version_compare($this->getConnection()->getServerInfo()->getVersion(), '11.0', '<')) { $this->markTestSkipped('PostgresSQL < 11.0 does not support INCLUDE clause.'); }