1717use Yiisoft \Db \Exception \NotSupportedException ;
1818use Yiisoft \Db \Expression \Expression ;
1919use Yiisoft \Db \Helper \DbArrayHelper ;
20+ use Yiisoft \Db \Oracle \Column \BinaryColumnSchema ;
2021use Yiisoft \Db \Schema \Builder \ColumnInterface ;
21- use Yiisoft \Db \Schema \ColumnSchemaInterface ;
22+ use Yiisoft \Db \Schema \Column \ ColumnSchemaInterface ;
2223use Yiisoft \Db \Schema \TableSchemaInterface ;
2324
2425use function array_change_key_case ;
@@ -405,14 +406,14 @@ protected function findColumns(TableSchemaInterface $table): bool
405406 return false ;
406407 }
407408
408- /** @psalm-var string[][] $columns */
409- foreach ($ columns as $ column ) {
410- /** @psalm-var ColumnInfoArray $column */
411- $ column = array_change_key_case ($ column );
409+ /** @psalm-var string[][] $info */
410+ foreach ($ columns as $ info ) {
411+ /** @psalm-var ColumnInfoArray $info */
412+ $ info = array_change_key_case ($ info );
412413
413- $ c = $ this ->createColumnSchema ( $ column );
414+ $ column = $ this ->loadColumnSchema ( $ info );
414415
415- $ table ->column ($ c -> getName () , $ c );
416+ $ table ->column ($ info [ ' column_name ' ] , $ column );
416417 }
417418
418419 return true ;
@@ -448,28 +449,43 @@ protected function getTableSequenceName(string $tableName): string|null
448449 }
449450
450451 /**
451- * Creates ColumnSchema instance .
452+ * Loads the column information into a {@see ColumnSchemaInterface} object .
452453 *
453- * @psalm-param ColumnInfoArray $info
454+ * @param array $info The column information.
455+ *
456+ * @return ColumnSchemaInterface The column schema object.
457+ *
458+ * @psalm-param ColumnInfoArray $info The column information.
454459 */
455- protected function createColumnSchema (array $ info ): ColumnSchemaInterface
460+ private function loadColumnSchema (array $ info ): ColumnSchemaInterface
456461 {
457- $ column = new ColumnSchema ($ info ['column_name ' ]);
462+ $ dbType = $ info ['data_type ' ];
463+ $ type = $ this ->extractColumnType ($ dbType , $ info );
464+
465+ $ column = $ this ->createColumnSchema ($ type );
466+ $ column ->name ($ info ['column_name ' ]);
458467 $ column ->allowNull ($ info ['nullable ' ] === 'Y ' );
459468 $ column ->comment ($ info ['column_comment ' ]);
460469 $ column ->primaryKey ((bool ) $ info ['is_pk ' ]);
461470 $ column ->autoIncrement ($ info ['identity_column ' ] === 'YES ' );
462471 $ column ->size ((int ) $ info ['data_length ' ]);
463472 $ column ->precision ($ info ['data_precision ' ] !== null ? (int ) $ info ['data_precision ' ] : null );
464473 $ column ->scale ($ info ['data_scale ' ] !== null ? (int ) $ info ['data_scale ' ] : null );
465- $ column ->dbType ($ info ['data_type ' ]);
466- $ column ->type ($ this ->extractColumnType ($ column ));
467- $ column ->phpType ($ this ->getColumnPhpType ($ column ));
474+ $ column ->dbType ($ dbType );
468475 $ column ->defaultValue ($ this ->normalizeDefaultValue ($ info ['data_default ' ], $ column ));
469476
470477 return $ column ;
471478 }
472479
480+ protected function createColumnSchemaFromPhpType (string $ phpType , string $ type ): ColumnSchemaInterface
481+ {
482+ if ($ phpType === self ::PHP_TYPE_RESOURCE ) {
483+ return new BinaryColumnSchema ($ type , $ phpType );
484+ }
485+
486+ return parent ::createColumnSchemaFromPhpType ($ phpType , $ type );
487+ }
488+
473489 /**
474490 * Converts column's default value according to {@see ColumnSchema::phpType} after retrieval from the database.
475491 *
@@ -645,16 +661,20 @@ public function findUniqueIndexes(TableSchemaInterface $table): array
645661 /**
646662 * Extracts the data type for the given column.
647663 *
648- * @param ColumnSchemaInterface $column The column schema object.
664+ * @param string $dbType The database data type
665+ * @param array $info Column information.
666+ * @psalm-param ColumnInfoArray $info
649667 *
650668 * @return string The abstract column type.
651669 */
652- private function extractColumnType (ColumnSchemaInterface $ column ): string
670+ private function extractColumnType (string $ dbType , array $ info ): string
653671 {
654- $ dbType = strtolower (( string ) $ column -> getDbType () );
672+ $ dbType = strtolower ($ dbType );
655673
656674 if ($ dbType === 'number ' ) {
657- return match ($ column ->getScale ()) {
675+ $ scale = $ info ['data_scale ' ] !== null ? (int ) $ info ['data_scale ' ] : null ;
676+
677+ return match ($ scale ) {
658678 null => self ::TYPE_DOUBLE ,
659679 0 => self ::TYPE_INTEGER ,
660680 default => self ::TYPE_DECIMAL ,
@@ -663,7 +683,7 @@ private function extractColumnType(ColumnSchemaInterface $column): string
663683
664684 $ dbType = preg_replace ('/\([^)]+\)/ ' , '' , $ dbType );
665685
666- if ($ dbType === 'interval day to second ' && $ column -> getPrecision () > 0 ) {
686+ if ($ dbType === 'interval day to second ' && $ info [ ' data_precision ' ] > 0 ) {
667687 return self ::TYPE_STRING ;
668688 }
669689
0 commit comments