Skip to content

Commit

Permalink
Update according changes in ColumnSchemaInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
Tigrov committed Sep 20, 2024
1 parent 1b2b7ba commit ddec2ec
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 69 deletions.
2 changes: 1 addition & 1 deletion src/Column/ColumnFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected function getType(string $dbType, array $info = []): string

$dbType = preg_replace('/\([^)]+\)/', '', $dbType);

if ($dbType === 'interval day to second' && isset($info['precision']) && $info['precision'] > 0) {
if ($dbType === 'interval day to second' && isset($info['size']) && $info['size'] > 0) {
return ColumnType::STRING;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function insertWithReturningPks(string $table, array $columns): bool|arra
$returnParams[$phName]['dataType'] = PDO::PARAM_INT;
}

$returnParams[$phName]['size'] = isset($columnSchemas[$name]) ? $columnSchemas[$name]->getSize() : -1;
$returnParams[$phName]['size'] = $columnSchemas[$name]?->getSize() ?? 4000;

$returning[] = $this->db->getQuoter()->quoteColumnName($name);
}
Expand Down
16 changes: 5 additions & 11 deletions src/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@
* @psalm-type ColumnInfoArray = array{
* column_name: string,
* data_type: string,
* data_precision: string|null,
* data_scale: string|null,
* data_length: string,
* size: string,
* nullable: string,
* data_default: string|null,
* is_pk: string|null,
Expand Down Expand Up @@ -331,14 +330,9 @@ protected function findColumns(TableSchemaInterface $table): bool
SELECT
A.COLUMN_NAME,
A.DATA_TYPE,
A.DATA_PRECISION,
A.DATA_SCALE,
A.IDENTITY_COLUMN,
(
CASE A.CHAR_USED WHEN 'C' THEN A.CHAR_LENGTH
ELSE A.DATA_LENGTH
END
) AS DATA_LENGTH,
(CASE WHEN A.CHAR_LENGTH > 0 THEN A.CHAR_LENGTH ELSE A.DATA_PRECISION END) AS "size",
A.NULLABLE,
A.DATA_DEFAULT,
(
Expand Down Expand Up @@ -429,14 +423,14 @@ private function loadColumnSchema(array $info): ColumnSchemaInterface
$dbType = $info['data_type'];
$column = $columnFactory->fromDbType($dbType, [
'scale' => $info['data_scale'],
'precision' => $info['data_precision'],
'size' => $info['size'],
]);
/** @psalm-suppress DeprecatedMethod */
$column->name($info['column_name']);
$column->allowNull($info['nullable'] === 'Y');
$column->notNull($info['nullable'] !== 'Y');
$column->comment($info['column_comment']);
$column->primaryKey((bool) $info['is_pk']);
$column->autoIncrement($info['identity_column'] === 'YES');
$column->size((int) $info['data_length']);
$column->defaultValue($this->normalizeDefaultValue($info['data_default'], $column));

return $column;
Expand Down
91 changes: 35 additions & 56 deletions tests/Provider/SchemaProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ public static function columns(): array
'dbType' => 'NUMBER',
'phpType' => 'int',
'primaryKey' => false,
'allowNull' => false,
'notNull' => true,
'autoIncrement' => false,
'enumValues' => null,
'size' => 22,
'precision' => null,
'size' => null,
'scale' => 0,
'defaultValue' => null,
],
Expand All @@ -33,11 +32,10 @@ public static function columns(): array
'dbType' => 'NUMBER',
'phpType' => 'int',
'primaryKey' => false,
'allowNull' => true,
'notNull' => false,
'autoIncrement' => false,
'enumValues' => null,
'size' => 22,
'precision' => null,
'size' => null,
'scale' => 0,
'defaultValue' => 1,
],
Expand All @@ -46,11 +44,10 @@ public static function columns(): array
'dbType' => 'NUMBER',
'phpType' => 'int',
'primaryKey' => false,
'allowNull' => true,
'notNull' => false,
'autoIncrement' => false,
'enumValues' => null,
'size' => 22,
'precision' => 3,
'size' => 3,
'scale' => 0,
'defaultValue' => 1,
],
Expand All @@ -59,11 +56,10 @@ public static function columns(): array
'dbType' => 'NUMBER',
'phpType' => 'int',
'primaryKey' => false,
'allowNull' => true,
'notNull' => false,
'autoIncrement' => false,
'enumValues' => null,
'size' => 22,
'precision' => null,
'size' => null,
'scale' => 0,
'defaultValue' => 1,
],
Expand All @@ -72,11 +68,10 @@ public static function columns(): array
'dbType' => 'CHAR',
'phpType' => 'string',
'primaryKey' => false,
'allowNull' => false,
'notNull' => true,
'autoIncrement' => false,
'enumValues' => null,
'size' => 100,
'precision' => null,
'scale' => null,
'defaultValue' => null,
],
Expand All @@ -85,11 +80,10 @@ public static function columns(): array
'dbType' => 'VARCHAR2',
'phpType' => 'string',
'primaryKey' => false,
'allowNull' => true,
'notNull' => false,
'autoIncrement' => false,
'enumValues' => null,
'size' => 100,
'precision' => null,
'scale' => null,
'defaultValue' => 'some\'thing',
],
Expand All @@ -98,11 +92,10 @@ public static function columns(): array
'dbType' => 'VARCHAR2',
'phpType' => 'string',
'primaryKey' => false,
'allowNull' => true,
'notNull' => false,
'autoIncrement' => false,
'enumValues' => null,
'size' => 4000,
'precision' => null,
'scale' => null,
'defaultValue' => null,
],
Expand All @@ -111,11 +104,10 @@ public static function columns(): array
'dbType' => 'NVARCHAR2',
'phpType' => 'string',
'primaryKey' => false,
'allowNull' => true,
'notNull' => false,
'autoIncrement' => false,
'enumValues' => null,
'size' => 100,
'precision' => null,
'scale' => null,
'defaultValue' => '',
],
Expand All @@ -124,11 +116,10 @@ public static function columns(): array
'dbType' => 'FLOAT',
'phpType' => 'float',
'primaryKey' => false,
'allowNull' => false,
'notNull' => true,
'autoIncrement' => false,
'enumValues' => null,
'size' => 22,
'precision' => 126,
'size' => 126,
'scale' => null,
'defaultValue' => null,
],
Expand All @@ -137,11 +128,10 @@ public static function columns(): array
'dbType' => 'FLOAT',
'phpType' => 'float',
'primaryKey' => false,
'allowNull' => true,
'notNull' => false,
'autoIncrement' => false,
'enumValues' => null,
'size' => 22,
'precision' => 126,
'size' => 126,
'scale' => null,
'defaultValue' => 1.23,
],
Expand All @@ -150,11 +140,10 @@ public static function columns(): array
'dbType' => 'BLOB',
'phpType' => 'mixed',
'primaryKey' => false,
'allowNull' => true,
'notNull' => false,
'autoIncrement' => false,
'enumValues' => null,
'size' => 4000,
'precision' => null,
'size' => null,
'scale' => null,
'defaultValue' => null,
],
Expand All @@ -163,11 +152,10 @@ public static function columns(): array
'dbType' => 'NUMBER',
'phpType' => 'float',
'primaryKey' => false,
'allowNull' => true,
'notNull' => false,
'autoIncrement' => false,
'enumValues' => null,
'size' => 22,
'precision' => 5,
'size' => 5,
'scale' => 2,
'defaultValue' => 33.22,
],
Expand All @@ -176,11 +164,10 @@ public static function columns(): array
'dbType' => 'TIMESTAMP(6)',
'phpType' => 'string',
'primaryKey' => false,
'allowNull' => false,
'notNull' => true,
'autoIncrement' => false,
'enumValues' => null,
'size' => 11,
'precision' => null,
'size' => null,
'scale' => 6,
'defaultValue' => "to_timestamp('2002-01-01 00:00:00', 'yyyy-mm-dd hh24:mi:ss')",
],
Expand All @@ -189,11 +176,10 @@ public static function columns(): array
'dbType' => 'INTERVAL DAY(0) TO SECOND(0)',
'phpType' => 'string',
'primaryKey' => false,
'allowNull' => true,
'notNull' => false,
'autoIncrement' => false,
'enumValues' => null,
'size' => 11,
'precision' => 0,
'size' => 0,
'scale' => 0,
'defaultValue' => "INTERVAL '0 10:33:21' DAY(0) TO SECOND(0)",
],
Expand All @@ -202,11 +188,10 @@ public static function columns(): array
'dbType' => 'INTERVAL DAY(1) TO SECOND(0)',
'phpType' => 'string',
'primaryKey' => false,
'allowNull' => true,
'notNull' => false,
'autoIncrement' => false,
'enumValues' => null,
'size' => 11,
'precision' => 1,
'size' => 1,
'scale' => 0,
'defaultValue' => "INTERVAL '2 04:56:12' DAY(1) TO SECOND(0)",
],
Expand All @@ -215,11 +200,10 @@ public static function columns(): array
'dbType' => 'CHAR',
'phpType' => 'string',
'primaryKey' => false,
'allowNull' => false,
'notNull' => true,
'autoIncrement' => false,
'enumValues' => null,
'size' => 1,
'precision' => null,
'scale' => null,
'defaultValue' => null,
],
Expand All @@ -228,11 +212,10 @@ public static function columns(): array
'dbType' => 'CHAR',
'phpType' => 'string',
'primaryKey' => false,
'allowNull' => true,
'notNull' => false,
'autoIncrement' => false,
'enumValues' => null,
'size' => 1,
'precision' => null,
'scale' => null,
'defaultValue' => '1',
],
Expand All @@ -241,11 +224,10 @@ public static function columns(): array
'dbType' => 'TIMESTAMP(6)',
'phpType' => 'string',
'primaryKey' => false,
'allowNull' => false,
'notNull' => true,
'autoIncrement' => false,
'enumValues' => null,
'size' => 11,
'precision' => null,
'size' => null,
'scale' => 6,
'defaultValue' => new Expression('CURRENT_TIMESTAMP'),
],
Expand All @@ -254,11 +236,10 @@ public static function columns(): array
'dbType' => 'NUMBER',
'phpType' => 'int',
'primaryKey' => false,
'allowNull' => false,
'notNull' => true,
'autoIncrement' => false,
'enumValues' => null,
'size' => 22,
'precision' => 3,
'size' => 3,
'scale' => 0,
'defaultValue' => 130, // b'10000010'
],
Expand All @@ -272,11 +253,10 @@ public static function columns(): array
'dbType' => 'NUMBER',
'phpType' => 'int',
'primaryKey' => true,
'allowNull' => false,
'notNull' => true,
'autoIncrement' => true,
'enumValues' => null,
'size' => 22,
'precision' => null,
'size' => null,
'scale' => 0,
'defaultValue' => null,
],
Expand All @@ -285,11 +265,10 @@ public static function columns(): array
'dbType' => 'VARCHAR2',
'phpType' => 'string',
'primaryKey' => false,
'allowNull' => false,
'notNull' => true,
'autoIncrement' => false,
'enumValues' => null,
'size' => 255,
'precision' => null,
'scale' => null,
'defaultValue' => null,
],
Expand Down

0 comments on commit ddec2ec

Please sign in to comment.