3838/**
3939 * Implements the Oracle Server specific schema, supporting Oracle Server 11C and above.
4040 *
41- * @psalm-type ColumnInfoArray = array{
41+ * @psalm-type ColumnArray = array{
4242 * column_name: string,
4343 * data_type: string,
4444 * data_scale: string|null,
45+ * identity_column: string,
4546 * size: string|null,
4647 * nullable: string,
4748 * data_default: string|null,
48- * is_pk: string|null,
49- * identity_column: string,
50- * column_comment: string|null
49+ * constraint_type: string|null,
50+ * column_comment: string|null,
51+ * schema: string,
52+ * table: string
5153 * }
5254 *
5355 * @psalm-type ConstraintArray = array<
@@ -334,6 +336,9 @@ protected function loadTableDefaultValues(string $tableName): array
334336 */
335337 protected function findColumns (TableSchemaInterface $ table ): bool
336338 {
339+ $ schemaName = $ table ->getSchemaName ();
340+ $ tableName = $ table ->getName ();
341+
337342 $ sql = <<<SQL
338343 SELECT
339344 A.COLUMN_NAME,
@@ -343,30 +348,45 @@ protected function findColumns(TableSchemaInterface $table): bool
343348 (CASE WHEN A.CHAR_LENGTH > 0 THEN A.CHAR_LENGTH ELSE A.DATA_PRECISION END) AS "size",
344349 A.NULLABLE,
345350 A.DATA_DEFAULT,
346- (
347- SELECT COUNT(*)
348- FROM ALL_CONSTRAINTS AC
349- INNER JOIN ALL_CONS_COLUMNS ACC ON ACC.CONSTRAINT_NAME=AC.CONSTRAINT_NAME
350- WHERE
351- AC.OWNER = A.OWNER
352- AND AC.TABLE_NAME = B.OBJECT_NAME
353- AND ACC.COLUMN_NAME = A.COLUMN_NAME
354- AND AC.CONSTRAINT_TYPE = 'P'
355- ) AS IS_PK,
351+ AC.CONSTRAINT_TYPE,
356352 COM.COMMENTS AS COLUMN_COMMENT
357353 FROM ALL_TAB_COLUMNS A
358- INNER JOIN ALL_OBJECTS B ON B.OWNER = A.OWNER AND LTRIM(B.OBJECT_NAME) = LTRIM(A.TABLE_NAME)
359- LEFT JOIN ALL_COL_COMMENTS COM ON (A.OWNER = COM.OWNER AND A.TABLE_NAME = COM.TABLE_NAME AND A.COLUMN_NAME = COM.COLUMN_NAME)
360- WHERE
361- A.OWNER = :schemaName
354+ INNER JOIN ALL_OBJECTS B
355+ ON B.OWNER = A.OWNER
356+ AND B.OBJECT_NAME = A.TABLE_NAME
357+ LEFT JOIN ALL_COL_COMMENTS COM
358+ ON COM.OWNER = A.OWNER
359+ AND COM.TABLE_NAME = A.TABLE_NAME
360+ AND COM.COLUMN_NAME = A.COLUMN_NAME
361+ LEFT JOIN ALL_CONSTRAINTS AC
362+ ON AC.OWNER = A.OWNER
363+ AND AC.TABLE_NAME = A.TABLE_NAME
364+ AND (AC.CONSTRAINT_TYPE = 'P'
365+ OR AC.CONSTRAINT_TYPE = 'U'
366+ AND (
367+ SELECT COUNT(*)
368+ FROM ALL_CONS_COLUMNS UCC
369+ WHERE UCC.CONSTRAINT_NAME = AC.CONSTRAINT_NAME
370+ AND UCC.TABLE_NAME = AC.TABLE_NAME
371+ AND UCC.OWNER = AC.OWNER
372+ ) = 1
373+ )
374+ AND AC.CONSTRAINT_NAME IN (
375+ SELECT ACC.CONSTRAINT_NAME
376+ FROM ALL_CONS_COLUMNS ACC
377+ WHERE ACC.OWNER = A.OWNER
378+ AND ACC.TABLE_NAME = A.TABLE_NAME
379+ AND ACC.COLUMN_NAME = A.COLUMN_NAME
380+ )
381+ WHERE A.OWNER = :schemaName
382+ AND A.TABLE_NAME = :tableName
362383 AND B.OBJECT_TYPE IN ('TABLE', 'VIEW', 'MATERIALIZED VIEW')
363- AND B.OBJECT_NAME = :tableName
364384 ORDER BY A.COLUMN_ID
365385 SQL ;
366386
367387 $ columns = $ this ->db ->createCommand ($ sql , [
368- ':tableName ' => $ table -> getName () ,
369- ':schemaName ' => $ table -> getSchemaName () ,
388+ ':schemaName ' => $ schemaName ,
389+ ':tableName ' => $ tableName ,
370390 ])->queryAll ();
371391
372392 if ($ columns === []) {
@@ -375,9 +395,12 @@ protected function findColumns(TableSchemaInterface $table): bool
375395
376396 /** @psalm-var string[][] $info */
377397 foreach ($ columns as $ info ) {
378- /** @psalm-var ColumnInfoArray $info */
379398 $ info = array_change_key_case ($ info );
380399
400+ $ info ['schema ' ] = $ schemaName ;
401+ $ info ['table ' ] = $ tableName ;
402+
403+ /** @psalm-var ColumnArray $info */
381404 $ column = $ this ->loadColumnSchema ($ info );
382405
383406 $ table ->column ($ info ['column_name ' ], $ column );
@@ -422,26 +445,24 @@ protected function getTableSequenceName(string $tableName): string|null
422445 *
423446 * @return ColumnSchemaInterface The column schema object.
424447 *
425- * @psalm-param ColumnInfoArray $info The column information.
448+ * @psalm-param ColumnArray $info The column information.
426449 */
427450 private function loadColumnSchema (array $ info ): ColumnSchemaInterface
428451 {
429- $ columnFactory = $ this ->db ->getSchema ()->getColumnFactory ();
430-
431- $ dbType = $ info ['data_type ' ];
432- $ column = $ columnFactory ->fromDbType ($ dbType , [
452+ $ column = $ this ->getColumnFactory ()->fromDbType ($ info ['data_type ' ], [
453+ 'autoIncrement ' => $ info ['identity_column ' ] === 'YES ' ,
454+ 'comment ' => $ info ['column_comment ' ],
455+ 'name ' => $ info ['column_name ' ],
456+ 'notNull ' => $ info ['nullable ' ] !== 'Y ' ,
457+ 'primaryKey ' => $ info ['constraint_type ' ] === 'P ' ,
433458 'scale ' => $ info ['data_scale ' ] !== null ? (int ) $ info ['data_scale ' ] : null ,
459+ 'schema ' => $ info ['schema ' ],
434460 'size ' => $ info ['size ' ] !== null ? (int ) $ info ['size ' ] : null ,
461+ 'table ' => $ info ['table ' ],
462+ 'unique ' => $ info ['constraint_type ' ] === 'U ' ,
435463 ]);
436- /** @psalm-suppress DeprecatedMethod */
437- $ column ->name ($ info ['column_name ' ]);
438- $ column ->notNull ($ info ['nullable ' ] !== 'Y ' );
439- $ column ->comment ($ info ['column_comment ' ]);
440- $ column ->primaryKey ((bool ) $ info ['is_pk ' ]);
441- $ column ->autoIncrement ($ info ['identity_column ' ] === 'YES ' );
442- $ column ->defaultValue ($ this ->normalizeDefaultValue ($ info ['data_default ' ], $ column ));
443-
444- return $ column ;
464+
465+ return $ column ->defaultValue ($ this ->normalizeDefaultValue ($ info ['data_default ' ], $ column ));
445466 }
446467
447468 /**
0 commit comments