13
13
14
14
use Doctrine \DBAL \DBALException ;
15
15
16
+ use Doctrine \DBAL \Types \BlobType ;
16
17
use Doctrine \DBAL \Types \DecimalType ;
17
18
use Doctrine \DBAL \Types \FloatType ;
18
19
use Doctrine \DBAL \Types \StringType ;
@@ -72,8 +73,9 @@ public function getSmallIntTypeDeclarationSQL(array $columnDef)
72
73
*/
73
74
protected function _getCommonIntegerTypeDeclarationSQL (array $ columnDef )
74
75
{
75
- if (! empty ($ columnDef ['autoincrement ' ]))
76
+ if (!empty ($ columnDef ['autoincrement ' ])) {
76
77
throw new \Exception ('Clickhouse do not support AUTO_INCREMENT fields ' );
78
+ }
77
79
78
80
return empty ($ columnDef ['unsigned ' ]) ? '' : 'U ' ;
79
81
}
@@ -126,8 +128,8 @@ protected function initializeDoctrineTypeMappings()
126
128
protected function getVarcharTypeDeclarationSQLSnippet ($ length , $ fixed )
127
129
{
128
130
return $ fixed
129
- ? 'FixedString( ' . $ length . ') '
130
- : 'String ' ;
131
+ ? 'FixedString( ' . $ length . ') '
132
+ : 'String ' ;
131
133
}
132
134
133
135
/**
@@ -289,7 +291,7 @@ public function getNowExpression()
289
291
*/
290
292
public function getSubstringExpression ($ value , $ from , $ length = null )
291
293
{
292
- if ( null === $ length ) {
294
+ if (null === $ length ) {
293
295
throw new \InvalidArgumentException ("'length' argument must be a constant " );
294
296
}
295
297
@@ -528,18 +530,22 @@ protected function _getCreateTableSQL($tableName, array $columns, array $options
528
530
$ engine = !empty ($ options ['engine ' ]) ? $ options ['engine ' ] : 'ReplacingMergeTree ' ;
529
531
$ engineOptions = '' ;
530
532
531
- if (isset ($ options ['uniqueConstraints ' ]) && ! empty ($ options ['uniqueConstraints ' ])) {
533
+ if (isset ($ options ['uniqueConstraints ' ]) && !empty ($ options ['uniqueConstraints ' ])) {
532
534
throw DBALException::notSupported ('uniqueConstraints ' );
533
535
}
534
536
535
- if (isset ($ options ['indexes ' ]) && ! empty ($ options ['indexes ' ])) {
537
+ if (isset ($ options ['indexes ' ]) && !empty ($ options ['indexes ' ])) {
536
538
throw DBALException::notSupported ('uniqueConstraints ' );
537
539
}
538
540
539
541
/**
540
542
* MergeTree* specific section
541
543
*/
542
- if ( in_array ($ engine , ['MergeTree ' , 'CollapsingMergeTree ' , 'SummingMergeTree ' , 'AggregatingMergeTree ' , 'ReplacingMergeTree ' ], true ) ) {
544
+ if (in_array (
545
+ $ engine ,
546
+ ['MergeTree ' , 'CollapsingMergeTree ' , 'SummingMergeTree ' , 'AggregatingMergeTree ' , 'ReplacingMergeTree ' ],
547
+ true
548
+ )) {
543
549
$ indexGranularity = !empty ($ options ['indexGranularity ' ]) ? $ options ['indexGranularity ' ] : 8192 ;
544
550
545
551
/**
@@ -549,9 +555,9 @@ protected function _getCreateTableSQL($tableName, array $columns, array $options
549
555
'type ' => Type::getType ('date ' ),
550
556
'default ' => 'today() ' ,
551
557
];
552
- if (! empty ($ options ['eventDateProviderColumn ' ]) ) {
558
+ if (!empty ($ options ['eventDateProviderColumn ' ])) {
553
559
$ options ['eventDateProviderColumn ' ] = trim ($ options ['eventDateProviderColumn ' ]);
554
- if (! isset ($ columns [$ options ['eventDateProviderColumn ' ]]) ) {
560
+ if (!isset ($ columns [$ options ['eventDateProviderColumn ' ]])) {
555
561
throw new \Exception ('Table ` ' . $ tableName . '` has not column with name: ` ' . $ options ['eventDateProviderColumn ' ]);
556
562
}
557
563
@@ -566,7 +572,7 @@ protected function _getCreateTableSQL($tableName, array $columns, array $options
566
572
$ columns [$ options ['eventDateProviderColumn ' ]]['type ' ] instanceof DecimalType ||
567
573
(
568
574
$ columns [$ options ['eventDateProviderColumn ' ]]['type ' ] instanceof StringType &&
569
- ! $ columns [$ options ['eventDateProviderColumn ' ]]['fixed ' ]
575
+ !$ columns [$ options ['eventDateProviderColumn ' ]]['fixed ' ]
570
576
)
571
577
) {
572
578
$ dateColumnParams ['default ' ] =
@@ -576,21 +582,24 @@ protected function _getCreateTableSQL($tableName, array $columns, array $options
576
582
('toDate(toDateTime( ' . $ options ['eventDateProviderColumn ' ] . ')) ' ) :
577
583
('toDate( ' . $ options ['eventDateProviderColumn ' ] . ') ' );
578
584
} else {
579
- throw new \Exception ('Column ` ' . $ options ['eventDateProviderColumn ' ] . '` with type ` ' . $ columns [$ options ['eventDateProviderColumn ' ]]['type ' ]->getName (). '`, defined in `eventDateProviderColumn` option, has not valid DBAL Type ' );
585
+ throw new \Exception ('Column ` ' . $ options ['eventDateProviderColumn ' ] . '` with type ` ' . $ columns [$ options ['eventDateProviderColumn ' ]]['type ' ]->getName () . '`, defined in `eventDateProviderColumn` option, has not valid DBAL Type ' );
580
586
}
581
587
}
582
- if ( empty ($ options ['eventDateColumn ' ]) ) {
583
- $ dateColumns = array_filter ($ columns , function ($ column ) {
588
+ if (empty ($ options ['eventDateColumn ' ])) {
589
+ $ dateColumns = array_filter ($ columns , function ($ column ) {
584
590
return $ column ['type ' ] instanceof DateType;
585
591
});
586
592
587
593
if ($ dateColumns ) {
588
- throw new \Exception ('Table ` ' . $ tableName . '` has DateType columns: ` ' . implode ('`, ` ' , array_keys ($ dateColumns )) . '`, but no one of them is setted as `eventDateColumn` with $table->addOption("eventDateColumn", "%eventDateColumnName%") ' );
594
+ throw new \Exception ('Table ` ' . $ tableName . '` has DateType columns: ` ' . implode (
595
+ '`, ` ' ,
596
+ array_keys ($ dateColumns )
597
+ ) . '`, but no one of them is setted as `eventDateColumn` with $table->addOption("eventDateColumn", "%eventDateColumnName%") ' );
589
598
}
590
599
591
600
$ eventDateColumnName = 'EventDate ' ;
592
601
} else {
593
- if ( isset ($ columns [$ options ['eventDateColumn ' ]]) ) {
602
+ if (isset ($ columns [$ options ['eventDateColumn ' ]])) {
594
603
if ($ columns [$ options ['eventDateColumn ' ]]['type ' ] instanceof DateType) {
595
604
$ eventDateColumnName = $ options ['eventDateColumn ' ];
596
605
unset($ columns [$ options ['eventDateColumn ' ]]);
@@ -607,27 +616,30 @@ protected function _getCreateTableSQL($tableName, array $columns, array $options
607
616
/**
608
617
* Primary key section
609
618
*/
610
- if ( empty ($ options ['primary ' ]) ) {
619
+ if (empty ($ options ['primary ' ])) {
611
620
throw new \Exception ('You need specify PrimaryKey for MergeTree* tables ' );
612
621
}
613
622
614
- $ engineOptions = '( ' . $ eventDateColumnName . ', ( ' . implode (', ' , array_unique (array_values ($ options ['primary ' ]))) . '), ' . $ indexGranularity ;
623
+ $ engineOptions = '( ' . $ eventDateColumnName . ', ( ' . implode (
624
+ ', ' ,
625
+ array_unique (array_values ($ options ['primary ' ]))
626
+ ) . '), ' . $ indexGranularity ;
615
627
616
628
/**
617
629
* any specific MergeTree* table parameters
618
630
*/
619
631
if ('ReplacingMergeTree ' === $ engine ) {
620
- if (! empty ($ options ['versionColumn ' ])) {
621
- if (! isset ($ columns [$ options ['versionColumn ' ]]) ) {
632
+ if (!empty ($ options ['versionColumn ' ])) {
633
+ if (!isset ($ columns [$ options ['versionColumn ' ]])) {
622
634
throw new \Exception ('If you specify `versionColumn` for ReplacingMergeTree table -- you must add this column manually (any of UInt*, Date or DateTime types) ' );
623
635
}
624
636
625
637
if (
626
- ! $ columns [$ options ['versionColumn ' ]]['type ' ] instanceof IntegerType &&
627
- ! $ columns [$ options ['versionColumn ' ]]['type ' ] instanceof BigIntType &&
628
- ! $ columns [$ options ['versionColumn ' ]]['type ' ] instanceof SmallIntType &&
629
- ! $ columns [$ options ['versionColumn ' ]]['type ' ] instanceof DateType &&
630
- ! $ columns [$ options ['versionColumn ' ]]['type ' ] instanceof DateTimeType
638
+ !$ columns [$ options ['versionColumn ' ]]['type ' ] instanceof IntegerType &&
639
+ !$ columns [$ options ['versionColumn ' ]]['type ' ] instanceof BigIntType &&
640
+ !$ columns [$ options ['versionColumn ' ]]['type ' ] instanceof SmallIntType &&
641
+ !$ columns [$ options ['versionColumn ' ]]['type ' ] instanceof DateType &&
642
+ !$ columns [$ options ['versionColumn ' ]]['type ' ] instanceof DateTimeType
631
643
) {
632
644
throw new \Exception ('For ReplacingMergeTree tables `versionColumn` must be any of UInt* family, or Date, or DateTime types. ' . get_class ($ columns [$ options ['versionColumn ' ]]['type ' ]) . ' given. ' );
633
645
}
@@ -680,7 +692,7 @@ public function getAlterTableSQL(TableDiff $diff)
680
692
continue ;
681
693
}
682
694
683
- $ queryParts [] = 'DROP COLUMN ' . $ column ->getQuotedName ($ this );
695
+ $ queryParts [] = 'DROP COLUMN ' . $ column ->getQuotedName ($ this );
684
696
}
685
697
686
698
foreach ($ diff ->changedColumns as $ columnDiff ) {
@@ -694,13 +706,16 @@ public function getAlterTableSQL(TableDiff $diff)
694
706
695
707
// Don't propagate default value changes for unsupported column types.
696
708
if ($ columnDiff ->hasChanged ('default ' ) &&
697
- count ($ columnDiff ->changedProperties ) === 1 &&
709
+ \ count ($ columnDiff ->changedProperties ) === 1 &&
698
710
($ columnArray ['type ' ] instanceof TextType || $ columnArray ['type ' ] instanceof BlobType)
699
711
) {
700
712
continue ;
701
713
}
702
714
703
- $ queryParts [] = 'MODIFY COLUMN ' . $ this ->getColumnDeclarationSQL ($ column ->getQuotedName ($ this ), $ columnArray );
715
+ $ queryParts [] = 'MODIFY COLUMN ' . $ this ->getColumnDeclarationSQL (
716
+ $ column ->getQuotedName ($ this ),
717
+ $ columnArray
718
+ );
704
719
}
705
720
706
721
foreach ($ diff ->renamedColumns as $ oldColumnName => $ column ) {
@@ -710,9 +725,12 @@ public function getAlterTableSQL(TableDiff $diff)
710
725
$ sql = [];
711
726
$ tableSql = [];
712
727
713
- if ( ! $ this ->onSchemaAlterTable ($ diff , $ tableSql )) {
728
+ if (! $ this ->onSchemaAlterTable ($ diff , $ tableSql )) {
714
729
if (count ($ queryParts ) > 0 ) {
715
- $ sql [] = 'ALTER TABLE ' . $ diff ->getName ($ this )->getQuotedName ($ this ) . ' ' . implode (', ' , $ queryParts );
730
+ $ sql [] = 'ALTER TABLE ' . $ diff ->getName ($ this )->getQuotedName ($ this ) . ' ' . implode (
731
+ ', ' ,
732
+ $ queryParts
733
+ );
716
734
}
717
735
}
718
736
@@ -871,15 +889,15 @@ public function getCurrentTimestampSQL()
871
889
*/
872
890
public function getListDatabasesSQL ()
873
891
{
874
- return 'SHOW DATABASES FORMAT JSON ' ;
892
+ return 'SHOW DATABASES ' ;
875
893
}
876
894
877
895
/**
878
896
* {@inheritDoc}
879
897
*/
880
898
public function getListTableColumnsSQL ($ table , $ database = null )
881
899
{
882
- return 'DESCRIBE TABLE ' . ($ database ? $ this ->quoteSingleIdentifier ($ database ) . '. ' : '' ) . $ this ->quoteSingleIdentifier ($ table ) . ' FORMAT JSON ' ;
900
+ return 'DESCRIBE TABLE ' . ($ database ? $ this ->quoteSingleIdentifier ($ database ) . '. ' : '' ) . $ this ->quoteSingleIdentifier ($ table );
883
901
}
884
902
885
903
/**
@@ -1014,11 +1032,12 @@ public function supportsGettingAffectedRows()
1014
1032
*/
1015
1033
protected function doModifyLimitQuery ($ query , $ limit , $ offset )
1016
1034
{
1017
- if ( is_null ($ limit ) )
1035
+ if (is_null ($ limit )) {
1018
1036
return $ query ;
1037
+ }
1019
1038
1020
1039
$ query .= ' LIMIT ' ;
1021
- if (! is_null ($ offset )) {
1040
+ if (!is_null ($ offset )) {
1022
1041
$ query .= $ offset . ', ' ;
1023
1042
}
1024
1043
@@ -1086,17 +1105,24 @@ protected function getReservedKeywordsClass()
1086
1105
*/
1087
1106
public function getDefaultValueDeclarationSQL ($ field )
1088
1107
{
1089
- if (! isset ($ field ['default ' ])) {
1108
+ if (!isset ($ field ['default ' ])) {
1090
1109
return '' ;
1091
1110
}
1092
1111
1093
1112
$ default = " DEFAULT ' " . $ field ['default ' ] . "' " ;
1094
- if ( isset ($ field ['type ' ]) ) {
1095
- if (in_array ((string )$ field ['type ' ], ['Integer ' , 'SmallInt ' , 'Float ' ]) || ('BigInt ' === $ field ['type ' ] && \PDO ::PARAM_INT === Type::getType ('BigInt ' )->getBindingType ())) {
1113
+ if (isset ($ field ['type ' ])) {
1114
+ if (in_array ((string )$ field ['type ' ], [
1115
+ 'Integer ' ,
1116
+ 'SmallInt ' ,
1117
+ 'Float '
1118
+ ]) || ('BigInt ' === $ field ['type ' ] && \PDO ::PARAM_INT === Type::getType ('BigInt ' )->getBindingType ())) {
1096
1119
$ default = ' DEFAULT ' . $ field ['default ' ];
1097
- } else if (in_array ((string )$ field ['type ' ], ['DateTime ' ]) && $ field ['default ' ] == $ this ->getCurrentTimestampSQL ()) {
1120
+ } elseif (in_array (
1121
+ (string )$ field ['type ' ],
1122
+ ['DateTime ' ]
1123
+ ) && $ field ['default ' ] === $ this ->getCurrentTimestampSQL ()) {
1098
1124
$ default = ' DEFAULT ' . $ this ->getCurrentTimestampSQL ();
1099
- } else if ('Date ' == (string )$ field ['type ' ]) { // TODO check if string matches constant date like 'dddd-yy-mm' and quote it
1125
+ } elseif ('Date ' = == (string )$ field ['type ' ]) { // TODO check if string matches constant date like 'dddd-yy-mm' and quote it
1100
1126
$ default = ' DEFAULT ' . $ field ['default ' ];
1101
1127
}
1102
1128
}
@@ -1145,5 +1171,4 @@ public function quoteSingleIdentifier($str)
1145
1171
1146
1172
return $ c . addslashes ($ str ) . $ c ;
1147
1173
}
1148
-
1149
1174
}
0 commit comments