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 \Connection ;
3132use 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 ;
3237use Doctrine \DBAL \Schema \ForeignKeyConstraint ;
3338use Doctrine \DBAL \Schema \Identifier ;
3439use Doctrine \DBAL \Schema \Index ;
3540use Doctrine \DBAL \Schema \Table ;
3641use Doctrine \DBAL \Schema \TableDiff ;
42+ use Doctrine \DBAL \TransactionIsolationLevel ;
3743use Doctrine \DBAL \Types \Type ;
3844use InvalidArgumentException ;
3945
@@ -50,12 +56,16 @@ public function __construct()
5056 {
5157 $ this ->initializeDoctrineTypeMappings ();
5258 if (!Type::hasType (MapType::NAME )) {
53- Type::addType (MapType::NAME , 'Crate\DBAL\Types\MapType ' );
59+ Type::addType (MapType::NAME , MapType::class);
60+ $ this ->registerDoctrineTypeMapping (10 , MapType::NAME );
5461 }
5562 if (!Type::hasType (TimestampType::NAME )) {
56- 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 );
5768 }
58- Type::overrideType ('array ' , 'Crate\DBAL\Types\ArrayType ' );
5969 }
6070
6171 /**
@@ -256,25 +266,25 @@ public function getAlterTableSQL(TableDiff $diff): array
256266 $ commentsSQL = array ();
257267 $ columnSql = array ();
258268
259- foreach ($ diff ->addedColumns as $ column ) {
269+ foreach ($ diff ->getAddedColumns () as $ column ) {
260270 if ($ this ->onSchemaAlterTableAddColumn ($ column , $ diff , $ columnSql )) {
261271 continue ;
262272 }
263273
264274 $ query = 'ADD ' . $ this ->getColumnDeclarationSQL ($ column ->getQuotedName ($ this ), $ column ->toArray ());
265275 $ sql [] = 'ALTER TABLE ' . $ diff ->name . ' ' . $ query ;
266- if ($ comment = $ this -> getColumnComment ( $ column )) {
276+ if ($ comment = $ column -> getComment ( )) {
267277 $ commentsSQL [] = $ this ->getCommentOnColumnSQL ($ diff ->name , $ column ->getName (), $ comment );
268278 }
269279 }
270280
271- if (count ($ diff ->removedColumns ) > 0 ) {
281+ if (count ($ diff ->getDroppedColumns () ) > 0 ) {
272282 throw Exception::notSupported ("Alter Table: drop columns " );
273283 }
274- if (count ($ diff ->changedColumns ) > 0 ) {
284+ if (count ($ diff ->getChangedColumns () ) > 0 ) {
275285 throw Exception::notSupported ("Alter Table: change column options " );
276286 }
277- if (count ($ diff ->renamedColumns ) > 0 ) {
287+ if (count ($ diff ->getRenamedColumns () ) > 0 ) {
278288 throw Exception::notSupported ("Alter Table: rename columns " );
279289 }
280290
@@ -297,7 +307,7 @@ public function getAlterTableSQL(TableDiff $diff): array
297307 public function getColumnDeclarationSQL ($ name , array $ column ): string
298308 {
299309 if (isset ($ column ['columnDefinition ' ])) {
300- $ columnDef = $ this -> getCustomTypeDeclarationSQL ( $ column) ;
310+ $ columnDef = $ column[ ' columnDefinition ' ] ;
301311 } else {
302312 $ typeDecl = $ column ['type ' ]->getSqlDeclaration ($ column , $ this );
303313 $ columnDef = $ typeDecl ;
@@ -312,10 +322,10 @@ public function getColumnDeclarationSQL($name, array $column): string
312322 * @param Index $index
313323 * @codeCoverageIgnore
314324 */
315- public function getIndexDeclarationSQL ($ name , Index $ index ): string
325+ public function getIndexDeclarationSQL (Index $ index ): string
316326 {
317327 $ columns = $ index ->getQuotedColumns ($ this );
318- $ name = new Identifier ($ name );
328+ $ name = new Identifier ($ index -> getName () );
319329
320330 if (count ($ columns ) == 0 ) {
321331 throw new \InvalidArgumentException ("Incomplete definition. 'columns' required. " );
@@ -445,7 +455,7 @@ protected function _getCommonIntegerTypeDeclarationSQL(array $columnDef): string
445455 * @param false|int $length
446456 * @param $fixed
447457 */
448- protected function getVarcharTypeDeclarationSQLSnippet ($ length, $ fixed ): string
458+ protected function getVarcharTypeDeclarationSQLSnippet ($ length ): string
449459 {
450460 return 'STRING ' ;
451461 }
@@ -600,7 +610,7 @@ public function getCreateTableSQL(Table $table, $createFlags = self::CREATE_INDE
600610 }
601611
602612 if (count ($ table ->getColumns ()) === 0 ) {
603- throw DBALException:: noColumnsSpecifiedForTable ($ table ->getName ());
613+ throw NoColumnsSpecifiedForTable:: new ($ table ->getName ());
604614 }
605615
606616 $ tableName = $ table ->getQuotedName ($ this );
@@ -632,30 +642,9 @@ public function getCreateTableSQL(Table $table, $createFlags = self::CREATE_INDE
632642 $ columns = array ();
633643
634644 foreach ($ table ->getColumns () as $ column ) {
635- if (null !== $ this ->_eventManager &&
636- $ this ->_eventManager ->hasListeners (Events::onSchemaCreateTableColumn)
637- ) {
638- $ eventArgs = new SchemaCreateTableColumnEventArgs ($ column , $ table , $ this );
639- $ this ->_eventManager ->dispatchEvent (Events::onSchemaCreateTableColumn, $ eventArgs );
640-
641- $ columnSql = array_merge ($ columnSql , $ eventArgs ->getSql ());
642-
643- if ($ eventArgs ->isDefaultPrevented ()) {
644- continue ;
645- }
646- }
647645 $ columns [$ column ->getQuotedName ($ this )] = self ::prepareColumnData ($ this , $ column , $ options ['primary ' ]);
648646 }
649647
650- if (null !== $ this ->_eventManager && $ this ->_eventManager ->hasListeners (Events::onSchemaCreateTable)) {
651- $ eventArgs = new SchemaCreateTableEventArgs ($ table , $ columns , $ options , $ this );
652- $ this ->_eventManager ->dispatchEvent (Events::onSchemaCreateTable, $ eventArgs );
653-
654- if ($ eventArgs ->isDefaultPrevented ()) {
655- return array_merge ($ eventArgs ->getSql (), $ columnSql );
656- }
657- }
658-
659648 $ sql = $ this ->_getCreateTableSQL ($ tableName , $ columns , $ options );
660649 if ($ this ->supportsCommentOnStatement ()) {
661650 foreach ($ table ->getColumns () as $ column ) {
@@ -687,7 +676,7 @@ protected function _getCreateTableSQL($name, array $columns, array $options = ar
687676
688677 if (isset ($ options ['indexes ' ]) && ! empty ($ options ['indexes ' ])) {
689678 foreach ($ options ['indexes ' ] as $ index => $ definition ) {
690- $ columnListSql .= ', ' . $ this ->getIndexDeclarationSQL ($ index , $ definition );
679+ $ columnListSql .= ', ' . $ this ->getIndexDeclarationSQL ($ definition );
691680 }
692681 }
693682
@@ -786,7 +775,7 @@ private function buildPartitionOptions(array $options)
786775 */
787776 public static function prepareColumnData (AbstractPlatform $ platform , $ column , $ primaries = array ())
788777 {
789- if ($ column ->hasCustomSchemaOption ("unique " ) ? $ column ->getCustomSchemaOption ("unique " ) : false ) {
778+ if ($ column ->hasPlatformOption ("unique " ) ? $ column ->hasPlatformOption ("unique " ) : false ) {
790779 throw Exception::notSupported ("Unique constraints are not supported. Use `primary key` instead " );
791780 }
792781
@@ -799,8 +788,7 @@ public static function prepareColumnData(AbstractPlatform $platform, $column, $p
799788 $ columnData ['unique ' ] = false ;
800789 $ columnData ['version ' ] = $ column ->hasPlatformOption ("version " ) ? $ column ->getPlatformOption ("version " ) : false ;
801790
802- if (strtolower ($ columnData ['type ' ]->getName ()) ==
803- strtolower ($ platform ->getVarcharTypeDeclarationSQLSnippet (0 , false ))
791+ if ($ columnData ['type ' ] == $ platform ->getVarcharTypeDeclarationSQLSnippet (0 , false )
804792 && $ columnData ['length ' ] === null ) {
805793 $ columnData ['length ' ] = 255 ;
806794 }
@@ -811,7 +799,7 @@ public static function prepareColumnData(AbstractPlatform $platform, $column, $p
811799 $ columnData ['default ' ] = $ column ->getDefault ();
812800 $ columnData ['columnDefinition ' ] = $ column ->getColumnDefinition ();
813801 $ columnData ['autoincrement ' ] = $ column ->getAutoincrement ();
814- $ columnData ['comment ' ] = $ platform -> getColumnComment ( $ column );
802+ $ columnData ['comment ' ] = $ column -> getComment ( );
815803 $ columnData ['platformOptions ' ] = $ column ->getPlatformOptions ();
816804
817805 if (in_array ($ column ->getName (), $ primaries )) {
@@ -873,4 +861,49 @@ public function getCurrentDatabaseExpression(): string
873861 // Added by Doctrine 3.
874862 return 'CURRENT_DATABASE() ' ;
875863 }
864+
865+ /**
866+ * Obtains DBMS specific SQL code portion needed to set an index
867+ * declaration to be used in statements like CREATE TABLE.
868+ *
869+ * @deprecated
870+ */
871+ public function getIndexFieldDeclarationListSQL (Index $ index ): string
872+ {
873+ return implode (', ' , $ index ->getQuotedColumns ($ this ));
874+ }
875+
876+ public function createSchemaManager (Connection $ connection ): AbstractSchemaManager
877+ {
878+ return new CrateSchemaManager ($ connection , $ this );
879+ }
880+
881+ public function getLocateExpression (string $ string , string $ substring , ?string $ start = null ): string
882+ {
883+ throw Exception::notSupported (__METHOD__ );
884+ }
885+
886+ protected function getDateArithmeticIntervalExpression (
887+ string $ date ,
888+ string $ operator ,
889+ string $ interval ,
890+ DateIntervalUnit $ unit ,
891+ ): string {
892+ throw Exception::notSupported (__METHOD__ );
893+ }
894+
895+ public function getListViewsSQL (string $ database ): string
896+ {
897+ throw Exception::notSupported (__METHOD__ );
898+ }
899+
900+ public function getSetTransactionIsolationSQL (TransactionIsolationLevel $ level ): string
901+ {
902+ throw Exception::notSupported (__METHOD__ );
903+ }
904+
905+ protected function createReservedKeywordsList (): KeywordList
906+ {
907+ return new CrateKeywords ();
908+ }
876909}
0 commit comments