1717use Yiisoft \Db \Exception \NotSupportedException ;
1818use Yiisoft \Db \Expression \Expression ;
1919use Yiisoft \Db \Helper \DbArrayHelper ;
20- use Yiisoft \Db \Oracle \Column \BinaryColumnSchema ;
20+ use Yiisoft \Db \Oracle \Column \ColumnFactory ;
2121use Yiisoft \Db \Schema \Builder \ColumnInterface ;
22+ use Yiisoft \Db \Schema \Column \ColumnFactoryInterface ;
2223use Yiisoft \Db \Schema \Column \ColumnSchemaInterface ;
2324use Yiisoft \Db \Schema \TableSchemaInterface ;
2425
2930use function is_array ;
3031use function md5 ;
3132use function preg_match ;
32- use function preg_replace ;
3333use function serialize ;
3434use function str_replace ;
35- use function strtolower ;
3635use function trim ;
3736
3837/**
6867 */
6968final class Schema extends AbstractPdoSchema
7069{
71- /**
72- * The mapping from physical column types (keys) to abstract column types (values).
73- *
74- * @link https://docs.oracle.com/en/database/oracle/oracle-database/23/sqlrf/Data-Types.html
75- *
76- * @var string[]
77- */
78- private const TYPE_MAP = [
79- 'char ' => self ::TYPE_CHAR ,
80- 'nchar ' => self ::TYPE_CHAR ,
81- 'varchar2 ' => self ::TYPE_STRING ,
82- 'nvarchar2 ' => self ::TYPE_STRING ,
83- 'clob ' => self ::TYPE_TEXT ,
84- 'nclob ' => self ::TYPE_TEXT ,
85- 'blob ' => self ::TYPE_BINARY ,
86- 'bfile ' => self ::TYPE_BINARY ,
87- 'long raw ' => self ::TYPE_BINARY ,
88- 'raw ' => self ::TYPE_BINARY ,
89- 'number ' => self ::TYPE_DECIMAL ,
90- 'binary_float ' => self ::TYPE_FLOAT , // 32 bit
91- 'binary_double ' => self ::TYPE_DOUBLE , // 64 bit
92- 'float ' => self ::TYPE_DOUBLE , // 126 bit
93- 'timestamp ' => self ::TYPE_TIMESTAMP ,
94- 'timestamp with time zone ' => self ::TYPE_TIMESTAMP ,
95- 'timestamp with local time zone ' => self ::TYPE_TIMESTAMP ,
96- 'date ' => self ::TYPE_DATE ,
97- 'interval day to second ' => self ::TYPE_TIME ,
98-
99- /** Deprecated */
100- 'long ' => self ::TYPE_TEXT ,
101- ];
102-
10370 public function __construct (protected ConnectionInterface $ db , SchemaCache $ schemaCache , string $ defaultSchema )
10471 {
10572 $ this ->defaultSchema = $ defaultSchema ;
@@ -111,6 +78,11 @@ public function createColumn(string $type, array|int|string $length = null): Col
11178 return new Column ($ type , $ length );
11279 }
11380
81+ public function getColumnFactory (): ColumnFactoryInterface
82+ {
83+ return new ColumnFactory ();
84+ }
85+
11486 protected function resolveTableName (string $ name ): TableSchemaInterface
11587 {
11688 $ resolvedName = new TableSchema ();
@@ -459,32 +431,22 @@ protected function getTableSequenceName(string $tableName): string|null
459431 private function loadColumnSchema (array $ info ): ColumnSchemaInterface
460432 {
461433 $ dbType = $ info ['data_type ' ];
462- $ type = $ this ->extractColumnType ($ dbType , $ info );
463-
464- $ column = $ this ->createColumnSchema ($ type );
434+ $ column = $ this ->getColumnFactory ()->fromDbType ($ dbType , [
435+ 'scale ' => $ info ['data_scale ' ],
436+ 'precision ' => $ info ['data_precision ' ],
437+ ]);
465438 $ column ->name ($ info ['column_name ' ]);
466439 $ column ->allowNull ($ info ['nullable ' ] === 'Y ' );
467440 $ column ->comment ($ info ['column_comment ' ]);
468441 $ column ->primaryKey ((bool ) $ info ['is_pk ' ]);
469442 $ column ->autoIncrement ($ info ['identity_column ' ] === 'YES ' );
470443 $ column ->size ((int ) $ info ['data_length ' ]);
471- $ column ->precision ($ info ['data_precision ' ] !== null ? (int ) $ info ['data_precision ' ] : null );
472- $ column ->scale ($ info ['data_scale ' ] !== null ? (int ) $ info ['data_scale ' ] : null );
473444 $ column ->dbType ($ dbType );
474445 $ column ->defaultValue ($ this ->normalizeDefaultValue ($ info ['data_default ' ], $ column ));
475446
476447 return $ column ;
477448 }
478449
479- protected function createColumnSchemaFromType (string $ type , bool $ isUnsigned = false ): ColumnSchemaInterface
480- {
481- if ($ type === self ::TYPE_BINARY ) {
482- return new BinaryColumnSchema ($ type );
483- }
484-
485- return parent ::createColumnSchemaFromType ($ type , $ isUnsigned );
486- }
487-
488450 /**
489451 * Converts column's default value according to {@see ColumnSchema::phpType} after retrieval from the database.
490452 *
@@ -657,38 +619,6 @@ public function findUniqueIndexes(TableSchemaInterface $table): array
657619 return $ result ;
658620 }
659621
660- /**
661- * Extracts the data type for the given column.
662- *
663- * @param string $dbType The database data type
664- * @param array $info Column information.
665- * @psalm-param ColumnInfoArray $info
666- *
667- * @return string The abstract column type.
668- */
669- private function extractColumnType (string $ dbType , array $ info ): string
670- {
671- $ dbType = strtolower ($ dbType );
672-
673- if ($ dbType === 'number ' ) {
674- $ scale = $ info ['data_scale ' ] !== null ? (int ) $ info ['data_scale ' ] : null ;
675-
676- return match ($ scale ) {
677- null => self ::TYPE_DOUBLE ,
678- 0 => self ::TYPE_INTEGER ,
679- default => self ::TYPE_DECIMAL ,
680- };
681- }
682-
683- $ dbType = preg_replace ('/\([^)]+\)/ ' , '' , $ dbType );
684-
685- if ($ dbType === 'interval day to second ' && $ info ['data_precision ' ] > 0 ) {
686- return self ::TYPE_STRING ;
687- }
688-
689- return self ::TYPE_MAP [$ dbType ] ?? self ::TYPE_STRING ;
690- }
691-
692622 /**
693623 * Loads multiple types of constraints and returns the specified ones.
694624 *
0 commit comments