From f24c1ad3d3cbcb428bc4adfb4cf7d8f9395f2d7a Mon Sep 17 00:00:00 2001 From: Tigrov Date: Fri, 6 Feb 2026 17:09:06 +0700 Subject: [PATCH 1/4] Fix quoting array column name --- src/Connection.php | 1 - src/Quoter.php | 40 +++++++++++++++++++++++++++++++ tests/Provider/QuoterProvider.php | 12 ++++++++++ tests/QuoterTest.php | 6 +++++ 4 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 src/Quoter.php diff --git a/src/Connection.php b/src/Connection.php index f008cbf7c..f7806f5ce 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -11,7 +11,6 @@ use Yiisoft\Db\Pgsql\Column\ColumnFactory; use Yiisoft\Db\QueryBuilder\QueryBuilderInterface; use Yiisoft\Db\Schema\Column\ColumnFactoryInterface; -use Yiisoft\Db\Schema\Quoter; use Yiisoft\Db\Schema\QuoterInterface; use Yiisoft\Db\Schema\SchemaInterface; use Yiisoft\Db\Transaction\TransactionInterface; diff --git a/src/Quoter.php b/src/Quoter.php new file mode 100644 index 000000000..437809e43 --- /dev/null +++ b/src/Quoter.php @@ -0,0 +1,40 @@ +quoteTableName(substr($name, 0, $dotPos)) . '.'; + $name = substr($name, $dotPos + 1); + } else { + $prefix = ''; + } + + if (str_contains($name, '{{')) { + return $name; + } + + $bracketPos = strpos($name, '['); + if ($bracketPos !== false) { + $suffix = substr($name, $bracketPos); + $name = substr($name, 0, $bracketPos); + } else { + $suffix = ''; + } + + return $prefix . $this->quoteSimpleColumnName($name) . $suffix; + } +} diff --git a/tests/Provider/QuoterProvider.php b/tests/Provider/QuoterProvider.php index 9f94835d2..b287107d1 100644 --- a/tests/Provider/QuoterProvider.php +++ b/tests/Provider/QuoterProvider.php @@ -6,6 +6,18 @@ final class QuoterProvider extends \Yiisoft\Db\Tests\Provider\QuoterProvider { + public static function columnNames(): array + { + return [ + ...parent::columnNames(), + ['array_col[1]', '"array_col"[1]'], + ['multi_array_col[1][2]', '"multi_array_col"[1][2]'], + ['table_name.array_col[1]', '"table_name"."array_col"[1]'], + ['[[array_col]][1]', '[[array_col]][1]'], + ['(array_col[1])', '(array_col[1])'], + ]; + } + public static function tableNameParts(): array { return [ diff --git a/tests/QuoterTest.php b/tests/QuoterTest.php index fe83c0cb2..5e3bbe4ea 100644 --- a/tests/QuoterTest.php +++ b/tests/QuoterTest.php @@ -16,6 +16,12 @@ final class QuoterTest extends CommonQuoterTest { use IntegrationTestTrait; + #[DataProviderExternal(QuoterProvider::class, 'columnNames')] + public function testQuoteColumnName(string $columnName, string $expected): void + { + parent::testQuoteColumnName($columnName, $expected); + } + #[DataProviderExternal(QuoterProvider::class, 'tableNameParts')] public function testGetTableNameParts(string $tableName, array $expected): void { From 017bd984040322c3aa829c077c6bd22536398c69 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Fri, 6 Feb 2026 17:15:29 +0700 Subject: [PATCH 2/4] Add line to CHANGELOG.md [skip ci] --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ab1cd132..496ea4c8f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Enh #477, #478: Improve performance of `ArrayParser::parse()` method (@Tigrov) - Enh #478: Improve performance of `StructuredParser::parse()` method (@Tigrov) +- Bug #481: Fix quoting array column names(@Tigrov) ## 2.0.0 December 05, 2025 From bf3b871d10a67056ba47730f9291f40c19db2387 Mon Sep 17 00:00:00 2001 From: Tigrov <8563175+Tigrov@users.noreply.github.com> Date: Fri, 6 Feb 2026 10:26:46 +0000 Subject: [PATCH 3/4] Apply PHP CS Fixer and Rector changes (CI) --- src/Quoter.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Quoter.php b/src/Quoter.php index 437809e43..df864f86d 100644 --- a/src/Quoter.php +++ b/src/Quoter.php @@ -1,5 +1,7 @@ Date: Fri, 6 Feb 2026 18:33:05 +0700 Subject: [PATCH 4/4] Update CHANGELOG.md Co-authored-by: Sergei Predvoditelev --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 882cea1e3..12e5e4201 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ - Enh #477, #478: Improve performance of `ArrayParser::parse()` method (@Tigrov) - Enh #478: Improve performance of `StructuredParser::parse()` method (@Tigrov) -- Bug #481: Fix quoting array column names(@Tigrov) +- Bug #481: Fix quoting array column names (@Tigrov) - Enh #479: Explicitly import functions and constants in "use" section (@mspirkov) - Enh #480: Remove unnecessary files from Composer package (@mspirkov)