2323
2424namespace Crate \DBAL \Platforms ;
2525
26+ use Crate \DBAL \Platforms \Keywords \CrateKeywords ;
27+ use Crate \DBAL \Schema \CrateSchemaManager ;
28+ use Crate \DBAL \Types \ArrayType ;
2629use Crate \DBAL \Types \MapType ;
2730use Crate \DBAL \Types \TimestampType ;
28- use Doctrine \DBAL \Event \SchemaCreateTableColumnEventArgs ;
29- use Doctrine \DBAL \Event \SchemaCreateTableEventArgs ;
30- use Doctrine \DBAL \Events ;
31- use Doctrine \DBAL \Exception as DBALException ;
31+ use Doctrine \DBAL \Connection ;
3232use Doctrine \DBAL \Platforms \AbstractPlatform ;
33+ use Doctrine \DBAL \Platforms \DateIntervalUnit ;
34+ use Doctrine \DBAL \Platforms \Exception \NoColumnsSpecifiedForTable ;
35+ use Doctrine \DBAL \Platforms \Keywords \KeywordList ;
36+ use Doctrine \DBAL \Schema \AbstractSchemaManager ;
3337use Doctrine \DBAL \Schema \ForeignKeyConstraint ;
3438use Doctrine \DBAL \Schema \Identifier ;
3539use Doctrine \DBAL \Schema \Index ;
@@ -52,18 +56,22 @@ public function __construct()
5256 {
5357 $ this ->initializeDoctrineTypeMappings ();
5458 if (!Type::hasType (MapType::NAME )) {
55- Type::addType (MapType::NAME , 'Crate\DBAL\Types\MapType ' );
59+ Type::addType (MapType::NAME , MapType::class);
60+ $ this ->registerDoctrineTypeMapping (10 , MapType::NAME );
5661 }
5762 if (!Type::hasType (TimestampType::NAME )) {
58- Type::addType (TimestampType::NAME , 'Crate\DBAL\Types\TimestampType ' );
63+ Type::addType (TimestampType::NAME , TimestampType::class);
64+ }
65+ if (!Type::hasType (ArrayType::NAME )) {
66+ Type::addType (ArrayType::NAME , ArrayType::class);
67+ $ this ->registerDoctrineTypeMapping (9 , ArrayType::NAME );
5968 }
60- Type::overrideType ('array ' , 'Crate\DBAL\Types\ArrayType ' );
6169 }
6270
6371 /**
6472 * {@inheritDoc}
6573 */
66- public function getDefaultTransactionIsolationLevel ()
74+ public function getDefaultTransactionIsolationLevel (): TransactionIsolationLevel
6775 {
6876 // CrateDB provides `READ_UNCOMMITTED` isolation levels.
6977 // https://github.com/crate/crate/blob/master/server/src/main/java/io/crate/analyze/ShowStatementAnalyzer.java#L69-L85
@@ -268,26 +276,26 @@ public function getAlterTableSQL(TableDiff $diff): array
268276 $ commentsSQL = array ();
269277 $ columnSql = array ();
270278
271- foreach ($ diff ->addedColumns as $ column ) {
279+ foreach ($ diff ->getAddedColumns () as $ column ) {
272280 if ($ this ->onSchemaAlterTableAddColumn ($ column , $ diff , $ columnSql )) {
273281 continue ;
274282 }
275283
276284 $ query = 'ADD ' . $ this ->getColumnDeclarationSQL ($ column ->getQuotedName ($ this ), $ column ->toArray ());
277285 $ sql [] = 'ALTER TABLE ' . $ diff ->name . ' ' . $ query ;
278- if ($ comment = $ this -> getColumnComment ( $ column )) {
286+ if ($ comment = $ column -> getComment ( )) {
279287 $ commentsSQL [] = $ this ->getCommentOnColumnSQL ($ diff ->name , $ column ->getName (), $ comment );
280288 }
281289 }
282290
283- if (count ($ diff ->removedColumns ) > 0 ) {
284- throw DBALException ::notSupported ("Alter Table: drop columns " );
291+ if (count ($ diff ->getDroppedColumns () ) > 0 ) {
292+ throw Exception ::notSupported ("Alter Table: drop columns " );
285293 }
286- if (count ($ diff ->changedColumns ) > 0 ) {
287- throw DBALException ::notSupported ("Alter Table: change column options " );
294+ if (count ($ diff ->getChangedColumns () ) > 0 ) {
295+ throw Exception ::notSupported ("Alter Table: change column options " );
288296 }
289- if (count ($ diff ->renamedColumns ) > 0 ) {
290- throw DBALException ::notSupported ("Alter Table: rename columns " );
297+ if (count ($ diff ->getRenamedColumns () ) > 0 ) {
298+ throw Exception ::notSupported ("Alter Table: rename columns " );
291299 }
292300
293301 $ tableSql = array ();
@@ -309,7 +317,7 @@ public function getAlterTableSQL(TableDiff $diff): array
309317 public function getColumnDeclarationSQL ($ name , array $ column ): string
310318 {
311319 if (isset ($ column ['columnDefinition ' ])) {
312- $ columnDef = $ this -> getCustomTypeDeclarationSQL ( $ column) ;
320+ $ columnDef = $ column[ ' columnDefinition ' ] ;
313321 } else {
314322 $ typeDecl = $ column ['type ' ]->getSqlDeclaration ($ column , $ this );
315323 $ columnDef = $ typeDecl ;
@@ -324,10 +332,10 @@ public function getColumnDeclarationSQL($name, array $column): string
324332 * @param Index $index
325333 * @codeCoverageIgnore
326334 */
327- public function getIndexDeclarationSQL ($ name , Index $ index ): string
335+ public function getIndexDeclarationSQL (Index $ index ): string
328336 {
329337 $ columns = $ index ->getQuotedColumns ($ this );
330- $ name = new Identifier ($ name );
338+ $ name = new Identifier ($ index -> getName () );
331339
332340 if (count ($ columns ) == 0 ) {
333341 throw new \InvalidArgumentException ("Incomplete definition. 'columns' required. " );
@@ -457,7 +465,7 @@ protected function _getCommonIntegerTypeDeclarationSQL(array $columnDef): string
457465 * @param false|int $length
458466 * @param $fixed
459467 */
460- protected function getVarcharTypeDeclarationSQLSnippet ($ length, $ fixed ): string
468+ protected function getVarcharTypeDeclarationSQLSnippet ($ length ): string
461469 {
462470 return 'STRING ' ;
463471 }
@@ -612,7 +620,7 @@ public function getCreateTableSQL(Table $table, $createFlags = self::CREATE_INDE
612620 }
613621
614622 if (count ($ table ->getColumns ()) === 0 ) {
615- throw DBALException:: noColumnsSpecifiedForTable ($ table ->getName ());
623+ throw NoColumnsSpecifiedForTable:: new ($ table ->getName ());
616624 }
617625
618626 $ tableName = $ table ->getQuotedName ($ this );
@@ -644,30 +652,9 @@ public function getCreateTableSQL(Table $table, $createFlags = self::CREATE_INDE
644652 $ columns = array ();
645653
646654 foreach ($ table ->getColumns () as $ column ) {
647- if (null !== $ this ->_eventManager &&
648- $ this ->_eventManager ->hasListeners (Events::onSchemaCreateTableColumn)
649- ) {
650- $ eventArgs = new SchemaCreateTableColumnEventArgs ($ column , $ table , $ this );
651- $ this ->_eventManager ->dispatchEvent (Events::onSchemaCreateTableColumn, $ eventArgs );
652-
653- $ columnSql = array_merge ($ columnSql , $ eventArgs ->getSql ());
654-
655- if ($ eventArgs ->isDefaultPrevented ()) {
656- continue ;
657- }
658- }
659655 $ columns [$ column ->getQuotedName ($ this )] = self ::prepareColumnData ($ this , $ column , $ options ['primary ' ]);
660656 }
661657
662- if (null !== $ this ->_eventManager && $ this ->_eventManager ->hasListeners (Events::onSchemaCreateTable)) {
663- $ eventArgs = new SchemaCreateTableEventArgs ($ table , $ columns , $ options , $ this );
664- $ this ->_eventManager ->dispatchEvent (Events::onSchemaCreateTable, $ eventArgs );
665-
666- if ($ eventArgs ->isDefaultPrevented ()) {
667- return array_merge ($ eventArgs ->getSql (), $ columnSql );
668- }
669- }
670-
671658 $ sql = $ this ->_getCreateTableSQL ($ tableName , $ columns , $ options );
672659 if ($ this ->supportsCommentOnStatement ()) {
673660 foreach ($ table ->getColumns () as $ column ) {
@@ -699,7 +686,7 @@ protected function _getCreateTableSQL($name, array $columns, array $options = ar
699686
700687 if (isset ($ options ['indexes ' ]) && ! empty ($ options ['indexes ' ])) {
701688 foreach ($ options ['indexes ' ] as $ index => $ definition ) {
702- $ columnListSql .= ', ' . $ this ->getIndexDeclarationSQL ($ index , $ definition );
689+ $ columnListSql .= ', ' . $ this ->getIndexDeclarationSQL ($ definition );
703690 }
704691 }
705692
@@ -798,8 +785,8 @@ private function buildPartitionOptions(array $options)
798785 */
799786 public static function prepareColumnData (AbstractPlatform $ platform , $ column , $ primaries = array ())
800787 {
801- if ($ column ->hasCustomSchemaOption ("unique " ) ? $ column ->getCustomSchemaOption ("unique " ) : false ) {
802- throw DBALException ::notSupported ("Unique constraints are not supported. Use `primary key` instead " );
788+ if ($ column ->hasPlatformOption ("unique " ) ? $ column ->hasPlatformOption ("unique " ) : false ) {
789+ throw Exception ::notSupported ("Unique constraints are not supported. Use `primary key` instead " );
803790 }
804791
805792 $ columnData = array ();
@@ -811,8 +798,7 @@ public static function prepareColumnData(AbstractPlatform $platform, $column, $p
811798 $ columnData ['unique ' ] = false ;
812799 $ columnData ['version ' ] = $ column ->hasPlatformOption ("version " ) ? $ column ->getPlatformOption ("version " ) : false ;
813800
814- if (strtolower ($ columnData ['type ' ]->getName ()) ==
815- strtolower ($ platform ->getVarcharTypeDeclarationSQLSnippet (0 , false ))
801+ if ($ columnData ['type ' ] == $ platform ->getVarcharTypeDeclarationSQLSnippet (0 , false )
816802 && $ columnData ['length ' ] === null ) {
817803 $ columnData ['length ' ] = 255 ;
818804 }
@@ -823,7 +809,7 @@ public static function prepareColumnData(AbstractPlatform $platform, $column, $p
823809 $ columnData ['default ' ] = $ column ->getDefault ();
824810 $ columnData ['columnDefinition ' ] = $ column ->getColumnDefinition ();
825811 $ columnData ['autoincrement ' ] = $ column ->getAutoincrement ();
826- $ columnData ['comment ' ] = $ platform -> getColumnComment ( $ column );
812+ $ columnData ['comment ' ] = $ column -> getComment ( );
827813 $ columnData ['platformOptions ' ] = $ column ->getPlatformOptions ();
828814
829815 if (in_array ($ column ->getName (), $ primaries )) {
@@ -885,4 +871,49 @@ public function getCurrentDatabaseExpression(): string
885871 // Added by Doctrine 3.
886872 return 'CURRENT_DATABASE() ' ;
887873 }
874+
875+ /**
876+ * Obtains DBMS specific SQL code portion needed to set an index
877+ * declaration to be used in statements like CREATE TABLE.
878+ *
879+ * @deprecated
880+ */
881+ public function getIndexFieldDeclarationListSQL (Index $ index ): string
882+ {
883+ return implode (', ' , $ index ->getQuotedColumns ($ this ));
884+ }
885+
886+ public function createSchemaManager (Connection $ connection ): AbstractSchemaManager
887+ {
888+ return new CrateSchemaManager ($ connection , $ this );
889+ }
890+
891+ public function getLocateExpression (string $ string , string $ substring , ?string $ start = null ): string
892+ {
893+ throw Exception::notSupported (__METHOD__ );
894+ }
895+
896+ protected function getDateArithmeticIntervalExpression (
897+ string $ date ,
898+ string $ operator ,
899+ string $ interval ,
900+ DateIntervalUnit $ unit ,
901+ ): string {
902+ throw Exception::notSupported (__METHOD__ );
903+ }
904+
905+ public function getListViewsSQL (string $ database ): string
906+ {
907+ throw Exception::notSupported (__METHOD__ );
908+ }
909+
910+ public function getSetTransactionIsolationSQL (TransactionIsolationLevel $ level ): string
911+ {
912+ throw Exception::notSupported (__METHOD__ );
913+ }
914+
915+ protected function createReservedKeywordsList (): KeywordList
916+ {
917+ return new CrateKeywords ();
918+ }
888919}
0 commit comments