Skip to content

Commit

Permalink
Driver::getColumns() removed case convert for 'nativetype' and keys i…
Browse files Browse the repository at this point in the history
…n 'vendor' (BC break)
  • Loading branch information
dg committed May 7, 2024
1 parent b154ea7 commit f31f487
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/Database/Drivers/MsSqlDriver.php
Expand Up @@ -102,7 +102,7 @@ public function getColumns(string $table): array
$columns[] = [
'name' => $row['COLUMN_NAME'],
'table' => $table,
'nativetype' => strtoupper($row['DATA_TYPE']),
'nativetype' => $row['DATA_TYPE'],
'size' => $row['CHARACTER_MAXIMUM_LENGTH'] ?? ($row['NUMERIC_PRECISION'] ?? null),
'unsigned' => false,
'nullable' => $row['IS_NULLABLE'] === 'YES',
Expand Down
15 changes: 7 additions & 8 deletions src/Database/Drivers/MySqlDriver.php
Expand Up @@ -139,17 +139,16 @@ public function getColumns(string $table): array
{
$columns = [];
foreach ($this->pdo->query('SHOW FULL COLUMNS FROM ' . $this->delimite($table), \PDO::FETCH_ASSOC) as $row) {
$row = array_change_key_case($row, CASE_LOWER);
$type = explode('(', $row['type']);
$type = explode('(', $row['Type']);
$columns[] = [
'name' => $row['field'],
'name' => $row['Field'],
'table' => $table,
'nativetype' => strtoupper($type[0]),
'nativetype' => $type[0],
'size' => isset($type[1]) ? (int) $type[1] : null,
'nullable' => $row['null'] === 'YES',
'default' => $row['default'],
'autoincrement' => $row['extra'] === 'auto_increment',
'primary' => $row['key'] === 'PRI',
'nullable' => $row['Null'] === 'YES',
'default' => $row['Default'],
'autoincrement' => $row['Extra'] === 'auto_increment',
'primary' => $row['Key'] === 'PRI',
'vendor' => $row,
];
}
Expand Down
2 changes: 1 addition & 1 deletion src/Database/Drivers/PgSqlDriver.php
Expand Up @@ -117,7 +117,7 @@ public function getColumns(string $table): array
SELECT
a.attname::varchar AS name,
c.relname::varchar AS table,
upper(t.typname) AS nativetype,
t.typname AS nativetype,
CASE WHEN a.atttypmod = -1 THEN NULL ELSE a.atttypmod -4 END AS size,
NOT (a.attnotnull OR t.typtype = 'd' AND t.typnotnull) AS nullable,
pg_catalog.pg_get_expr(ad.adbin, 'pg_catalog.pg_attrdef'::regclass)::varchar AS default,
Expand Down
2 changes: 1 addition & 1 deletion src/Database/Drivers/SqlsrvDriver.php
Expand Up @@ -122,7 +122,7 @@ public function getColumns(string $table): array
SELECT
c.name AS name,
o.name AS [table],
UPPER(t.name) AS nativetype,
t.name AS nativetype,
NULL AS size,
c.is_nullable AS nullable,
OBJECT_DEFINITION(c.default_object_id) AS [default],
Expand Down
11 changes: 6 additions & 5 deletions tests/Database/Reflection.driver.phpt
Expand Up @@ -50,7 +50,7 @@ $expectedColumns = [
[
'name' => 'id',
'table' => 'author',
'nativetype' => 'INT',
'nativetype' => 'int',
'size' => 11,
'nullable' => false,
'default' => null,
Expand All @@ -60,7 +60,7 @@ $expectedColumns = [
[
'name' => 'name',
'table' => 'author',
'nativetype' => 'VARCHAR',
'nativetype' => 'varchar',
'size' => 30,
'nullable' => false,
'default' => null,
Expand All @@ -70,7 +70,7 @@ $expectedColumns = [
[
'name' => 'web',
'table' => 'author',
'nativetype' => 'VARCHAR',
'nativetype' => 'varchar',
'size' => 100,
'nullable' => false,
'default' => null,
Expand All @@ -80,7 +80,7 @@ $expectedColumns = [
[
'name' => 'born',
'table' => 'author',
'nativetype' => 'DATE',
'nativetype' => 'date',
'size' => null,
'nullable' => true,
'default' => null,
Expand All @@ -97,7 +97,7 @@ switch ($driverName) {
}
break;
case 'pgsql':
$expectedColumns[0]['nativetype'] = 'INT4';
$expectedColumns[0]['nativetype'] = 'int4';
$expectedColumns[0]['default'] = "nextval('author_id_seq'::regclass)";
$expectedColumns[0]['size'] = null;
break;
Expand All @@ -108,6 +108,7 @@ switch ($driverName) {
$expectedColumns[1]['size'] = null;
$expectedColumns[2]['nativetype'] = 'TEXT';
$expectedColumns[2]['size'] = null;
$expectedColumns[3]['nativetype'] = 'DATE';
break;
case 'sqlsrv':
$expectedColumns[0]['size'] = null;
Expand Down
9 changes: 5 additions & 4 deletions tests/Database/Reflection.phpt
Expand Up @@ -72,7 +72,7 @@ $expectedColumns = [
'id' => [
'name' => 'id',
'table' => 'author',
'nativeType' => 'INT',
'nativeType' => 'int',
'size' => 11,
'nullable' => false,
'default' => null,
Expand All @@ -82,7 +82,7 @@ $expectedColumns = [
'name' => [
'name' => 'name',
'table' => 'author',
'nativeType' => 'VARCHAR',
'nativeType' => 'varchar',
'size' => 30,
'nullable' => false,
'default' => null,
Expand All @@ -92,7 +92,7 @@ $expectedColumns = [
'web' => [
'name' => 'web',
'table' => 'author',
'nativeType' => 'VARCHAR',
'nativeType' => 'varchar',
'size' => 100,
'nullable' => false,
'default' => null,
Expand All @@ -102,7 +102,7 @@ $expectedColumns = [
'born' => [
'name' => 'born',
'table' => 'author',
'nativeType' => 'DATE',
'nativeType' => 'date',
'size' => null,
'nullable' => true,
'default' => null,
Expand Down Expand Up @@ -130,6 +130,7 @@ switch ($driverName) {
$expectedColumns['name']['size'] = null;
$expectedColumns['web']['nativeType'] = 'TEXT';
$expectedColumns['web']['size'] = null;
$expectedColumns['born']['nativeType'] = 'DATE';
break;
case 'sqlsrv':
$expectedColumns['id']['size'] = null;
Expand Down

0 comments on commit f31f487

Please sign in to comment.