File tree Expand file tree Collapse file tree 5 files changed +61
-1
lines changed
Expand file tree Collapse file tree 5 files changed +61
-1
lines changed Original file line number Diff line number Diff line change 44
55- Enh #477 , #478 : Improve performance of ` ArrayParser::parse() ` method (@Tigrov )
66- Enh #478 : Improve performance of ` StructuredParser::parse() ` method (@Tigrov )
7+ - Bug #481 : Fix quoting array column names (@Tigrov )
78- Enh #479 : Explicitly import functions and constants in "use" section (@mspirkov )
89- Enh #480 : Remove unnecessary files from Composer package (@mspirkov )
910
Original file line number Diff line number Diff line change 1111use Yiisoft \Db \Pgsql \Column \ColumnFactory ;
1212use Yiisoft \Db \QueryBuilder \QueryBuilderInterface ;
1313use Yiisoft \Db \Schema \Column \ColumnFactoryInterface ;
14- use Yiisoft \Db \Schema \Quoter ;
1514use Yiisoft \Db \Schema \QuoterInterface ;
1615use Yiisoft \Db \Schema \SchemaInterface ;
1716use Yiisoft \Db \Transaction \TransactionInterface ;
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Yiisoft \Db \Pgsql ;
6+
7+ use function str_contains ;
8+ use function strpos ;
9+ use function strrpos ;
10+ use function substr ;
11+
12+ final class Quoter extends \Yiisoft \Db \Schema \Quoter
13+ {
14+ public function quoteColumnName (string $ name ): string
15+ {
16+ if (str_contains ($ name , '( ' ) || str_contains ($ name , '[[ ' )) {
17+ return $ name ;
18+ }
19+
20+ $ dotPos = strrpos ($ name , '. ' );
21+ if ($ dotPos !== false ) {
22+ $ prefix = $ this ->quoteTableName (substr ($ name , 0 , $ dotPos )) . '. ' ;
23+ $ name = substr ($ name , $ dotPos + 1 );
24+ } else {
25+ $ prefix = '' ;
26+ }
27+
28+ if (str_contains ($ name , '{{ ' )) {
29+ return $ name ;
30+ }
31+
32+ $ bracketPos = strpos ($ name , '[ ' );
33+ if ($ bracketPos !== false ) {
34+ $ suffix = substr ($ name , $ bracketPos );
35+ $ name = substr ($ name , 0 , $ bracketPos );
36+ } else {
37+ $ suffix = '' ;
38+ }
39+
40+ return $ prefix . $ this ->quoteSimpleColumnName ($ name ) . $ suffix ;
41+ }
42+ }
Original file line number Diff line number Diff line change 66
77final class QuoterProvider extends \Yiisoft \Db \Tests \Provider \QuoterProvider
88{
9+ public static function columnNames (): array
10+ {
11+ return [
12+ ...parent ::columnNames (),
13+ ['array_col[1] ' , '"array_col"[1] ' ],
14+ ['multi_array_col[1][2] ' , '"multi_array_col"[1][2] ' ],
15+ ['table_name.array_col[1] ' , '"table_name"."array_col"[1] ' ],
16+ ['[[array_col]][1] ' , '[[array_col]][1] ' ],
17+ ['(array_col[1]) ' , '(array_col[1]) ' ],
18+ ];
19+ }
20+
921 public static function tableNameParts (): array
1022 {
1123 return [
Original file line number Diff line number Diff line change @@ -16,6 +16,12 @@ final class QuoterTest extends CommonQuoterTest
1616{
1717 use IntegrationTestTrait;
1818
19+ #[DataProviderExternal(QuoterProvider::class, 'columnNames ' )]
20+ public function testQuoteColumnName (string $ columnName , string $ expected ): void
21+ {
22+ parent ::testQuoteColumnName ($ columnName , $ expected );
23+ }
24+
1925 #[DataProviderExternal(QuoterProvider::class, 'tableNameParts ' )]
2026 public function testGetTableNameParts (string $ tableName , array $ expected ): void
2127 {
You can’t perform that action at this time.
0 commit comments