Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: [OCI8][Postgre][SQLSRV][SQLite3] change order of properties returned by getFieldData() #8481

Merged
merged 1 commit into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion system/Database/OCI8/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,8 @@ protected function _fieldData(string $table): array

$retval[$i]->max_length = $length;

$retval[$i]->default = $query[$i]->DATA_DEFAULT;
$retval[$i]->nullable = $query[$i]->NULLABLE === 'Y';
$retval[$i]->default = $query[$i]->DATA_DEFAULT;
}

return $retval;
Expand Down
2 changes: 1 addition & 1 deletion system/Database/Postgre/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,9 @@ protected function _fieldData(string $table): array

$retVal[$i]->name = $query[$i]->column_name;
$retVal[$i]->type = $query[$i]->data_type;
$retVal[$i]->max_length = $query[$i]->character_maximum_length > 0 ? $query[$i]->character_maximum_length : $query[$i]->numeric_precision;
$retVal[$i]->nullable = $query[$i]->is_nullable === 'YES';
$retVal[$i]->default = $query[$i]->column_default;
$retVal[$i]->max_length = $query[$i]->character_maximum_length > 0 ? $query[$i]->character_maximum_length : $query[$i]->numeric_precision;
}

return $retVal;
Expand Down
6 changes: 3 additions & 3 deletions system/Database/SQLSRV/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -357,15 +357,15 @@ protected function _fieldData(string $table): array
for ($i = 0, $c = count($query); $i < $c; $i++) {
$retVal[$i] = new stdClass();

$retVal[$i]->name = $query[$i]->COLUMN_NAME;
$retVal[$i]->type = $query[$i]->DATA_TYPE;
$retVal[$i]->default = $query[$i]->COLUMN_DEFAULT;
$retVal[$i]->name = $query[$i]->COLUMN_NAME;
$retVal[$i]->type = $query[$i]->DATA_TYPE;

$retVal[$i]->max_length = $query[$i]->CHARACTER_MAXIMUM_LENGTH > 0
? $query[$i]->CHARACTER_MAXIMUM_LENGTH
: $query[$i]->NUMERIC_PRECISION;

$retVal[$i]->nullable = $query[$i]->IS_NULLABLE !== 'NO';
$retVal[$i]->default = $query[$i]->COLUMN_DEFAULT;
}

return $retVal;
Expand Down
2 changes: 1 addition & 1 deletion system/Database/SQLite3/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,12 +272,12 @@ protected function _fieldData(string $table): array
$retVal[$i]->name = $query[$i]->name;
$retVal[$i]->type = $query[$i]->type;
$retVal[$i]->max_length = null;
$retVal[$i]->nullable = isset($query[$i]->notnull) && ! (bool) $query[$i]->notnull;
$retVal[$i]->default = $query[$i]->dflt_value;
// "pk" (either zero for columns that are not part of the primary key,
// or the 1-based index of the column within the primary key).
// https://www.sqlite.org/pragma.html#pragma_table_info
$retVal[$i]->primary_key = ($query[$i]->pk === 0) ? 0 : 1;
$retVal[$i]->nullable = isset($query[$i]->notnull) && ! (bool) $query[$i]->notnull;
}

return $retVal;
Expand Down
32 changes: 16 additions & 16 deletions tests/system/Database/Live/ForgeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@
$this->forge->createTable('forge_test_table');
}

public function testRenameTable(): void

Check warning on line 387 in tests/system/Database/Live/ForgeTest.php

View workflow job for this annotation

GitHub Actions / DatabaseLive (8.1, SQLSRV, 8.0) / tests

Took 0.55s from 0.50s limit to run CodeIgniter\\Database\\Live\\ForgeTest::testRenameTable
{
$this->forge->dropTable('forge_test_table_dummy', true);

Expand Down Expand Up @@ -440,7 +440,7 @@
$this->forge->dropTable('', true);
}

public function testForeignKey(): void

Check warning on line 443 in tests/system/Database/Live/ForgeTest.php

View workflow job for this annotation

GitHub Actions / DatabaseLive (8.1, OCI8, 8.0) / tests

Took 3.17s from 0.50s limit to run CodeIgniter\\Database\\Live\\ForgeTest::testForeignKey

Check warning on line 443 in tests/system/Database/Live/ForgeTest.php

View workflow job for this annotation

GitHub Actions / DatabaseLive (8.1, SQLSRV, 8.0) / tests

Took 0.53s from 0.50s limit to run CodeIgniter\\Database\\Live\\ForgeTest::testForeignKey
{
$this->forge->dropTable('forge_test_invoices', true);
$this->forge->dropTable('forge_test_users', true);
Expand Down Expand Up @@ -730,7 +730,7 @@
$this->forge->createTable('forge_test_invoices', true, $attributes);
}

public function testDropForeignKey(): void

Check warning on line 733 in tests/system/Database/Live/ForgeTest.php

View workflow job for this annotation

GitHub Actions / DatabaseLive (8.1, SQLSRV, 8.0) / tests

Took 0.53s from 0.50s limit to run CodeIgniter\\Database\\Live\\ForgeTest::testDropForeignKey
{
$this->forge->dropTable('forge_test_invoices', true);
$this->forge->dropTable('forge_test_users', true);
Expand Down Expand Up @@ -953,30 +953,30 @@
0 => [
'name' => 'id',
'type' => 'integer',
'max_length' => '32',
'nullable' => false,
'default' => "nextval('db_forge_test_fields_id_seq'::regclass)",
'max_length' => '32',
],
1 => [
'name' => 'username',
'type' => 'character varying',
'max_length' => '255',
'nullable' => false,
'default' => null,
'max_length' => '255',
],
2 => [
'name' => 'name',
'type' => 'character varying',
'max_length' => '255',
'nullable' => true,
'default' => null,
'max_length' => '255',
],
3 => [
'name' => 'active',
'type' => 'integer',
'max_length' => '32',
'nullable' => false,
'default' => '0',
'max_length' => '32',
],
];
} elseif ($this->db->DBDriver === 'SQLite3') {
Expand All @@ -985,64 +985,64 @@
'name' => 'id',
'type' => 'INTEGER',
'max_length' => null,
'nullable' => true,
'default' => null,
'primary_key' => 1,
'nullable' => true,
],
1 => [
'name' => 'username',
'type' => 'VARCHAR',
'max_length' => null,
'nullable' => false,
'default' => null,
'primary_key' => 0,
'nullable' => false,
],
2 => [
'name' => 'name',
'type' => 'VARCHAR',
'max_length' => null,
'nullable' => true,
'default' => null,
'primary_key' => 0,
'nullable' => true,
],
3 => [
'name' => 'active',
'type' => 'INTEGER',
'max_length' => null,
'nullable' => false,
'default' => '0',
'primary_key' => 0,
'nullable' => false,
],
];
} elseif ($this->db->DBDriver === 'SQLSRV') {
$expected = [
0 => [
'name' => 'id',
'type' => 'int',
'default' => null,
'max_length' => 10,
'nullable' => false,
'default' => null,
],
1 => [
'name' => 'username',
'type' => 'varchar',
'default' => null,
'max_length' => 255,
'nullable' => false,
'default' => null,
],
2 => [
'name' => 'name',
'type' => 'varchar',
'default' => null,
'max_length' => 255,
'nullable' => true,
'default' => null,
],
3 => [
'name' => 'active',
'type' => 'int',
'default' => '((0))', // Why?
'max_length' => 10,
'nullable' => false,
'default' => '((0))', // Why?
],
];
} elseif ($this->db->DBDriver === 'OCI8') {
Expand All @@ -1051,29 +1051,29 @@
'name' => 'id',
'type' => 'NUMBER',
'max_length' => '11',
'default' => '"ORACLE"."ISEQ$$_80229".nextval', // Sequence id may change
'nullable' => false,
'default' => '"ORACLE"."ISEQ$$_80229".nextval', // Sequence id may change
],
1 => [
'name' => 'username',
'type' => 'VARCHAR2',
'max_length' => '255',
'default' => null,
'nullable' => false,
'default' => null,
],
2 => [
'name' => 'name',
'type' => 'VARCHAR2',
'max_length' => '255',
'default' => null,
'nullable' => true,
'default' => null,
],
3 => [
'name' => 'active',
'type' => 'NUMBER',
'max_length' => '11',
'default' => '0 ', // Why?
'nullable' => false,
'default' => '0 ', // Why?
],
];

Expand Down Expand Up @@ -1182,7 +1182,7 @@
$this->forge->dropTable('forge_test_1', true);
}

public function testSetKeyNames(): void

Check warning on line 1185 in tests/system/Database/Live/ForgeTest.php

View workflow job for this annotation

GitHub Actions / DatabaseLive (8.1, OCI8, 8.0) / tests

Took 1.38s from 0.50s limit to run CodeIgniter\\Database\\Live\\ForgeTest::testSetKeyNames
{
$this->forge->dropTable('forge_test_1', true);

Expand Down Expand Up @@ -1278,7 +1278,7 @@
$this->forge->dropTable('forge_test_two', true);
}

public function testModifyColumnRename(): void

Check warning on line 1281 in tests/system/Database/Live/ForgeTest.php

View workflow job for this annotation

GitHub Actions / DatabaseLive (8.1, SQLSRV, 8.0) / tests

Took 0.55s from 0.50s limit to run CodeIgniter\\Database\\Live\\ForgeTest::testModifyColumnRename
{
$this->forge->dropTable('forge_test_three', true);

Expand Down Expand Up @@ -1506,7 +1506,7 @@
$this->forge->dropTable('forge_test_four', true);
}

public function testDropKey(): void

Check warning on line 1509 in tests/system/Database/Live/ForgeTest.php

View workflow job for this annotation

GitHub Actions / DatabaseLive (8.1, OCI8, 8.0) / tests

Took 1.20s from 0.50s limit to run CodeIgniter\\Database\\Live\\ForgeTest::testDropKey
{
$this->forge->dropTable('key_test_users', true);
$keyName = 'key_test_users_id';
Expand Down Expand Up @@ -1593,7 +1593,7 @@
$this->forge->dropTable('forge_test_users', true);
}

public function testProcessIndexes(): void

Check warning on line 1596 in tests/system/Database/Live/ForgeTest.php

View workflow job for this annotation

GitHub Actions / DatabaseLive (8.1, OCI8, 8.0) / tests

Took 1.80s from 0.50s limit to run CodeIgniter\\Database\\Live\\ForgeTest::testProcessIndexes

Check warning on line 1596 in tests/system/Database/Live/ForgeTest.php

View workflow job for this annotation

GitHub Actions / DatabaseLive (8.1, SQLSRV, 8.0) / tests

Took 0.54s from 0.50s limit to run CodeIgniter\\Database\\Live\\ForgeTest::testProcessIndexes
{
// make sure tables don't exist
$this->forge->dropTable('actions', true);
Expand Down
14 changes: 7 additions & 7 deletions tests/system/Database/Live/OCI8/GetFieldDataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,57 +50,57 @@ public function testGetFieldData(): void
'name' => 'id',
'type' => 'NUMBER',
'max_length' => '11',
'nullable' => false,
'default' => $idDefault, // The default value is not defined.
// 'primary_key' => 1,
'nullable' => false,
],
(object) [
'name' => 'text_not_null',
'type' => 'VARCHAR2',
'max_length' => '64',
'nullable' => false,
'default' => null, // The default value is not defined.
// 'primary_key' => 0,
'nullable' => false,
],
(object) [
'name' => 'text_null',
'type' => 'VARCHAR2',
'max_length' => '64',
'nullable' => true,
'default' => null, // The default value is not defined.
// 'primary_key' => 0,
'nullable' => true,
],
(object) [
'name' => 'int_default_0',
'type' => 'NUMBER',
'max_length' => '11',
'nullable' => false,
'default' => '0 ', // int 0
// 'primary_key' => 0,
'nullable' => false,
],
(object) [
'name' => 'text_default_null',
'type' => 'VARCHAR2',
'max_length' => '64',
'nullable' => true,
'default' => 'NULL ', // NULL value
// 'primary_key' => 0,
'nullable' => true,
],
(object) [
'name' => 'text_default_text_null',
'type' => 'VARCHAR2',
'max_length' => '64',
'nullable' => false,
'default' => "'null' ", // string "null"
// 'primary_key' => 0,
'nullable' => false,
],
(object) [
'name' => 'text_default_abc',
'type' => 'VARCHAR2',
'max_length' => '64',
'nullable' => false,
'default' => "'abc' ", // string "abc"
// 'primary_key' => 0,
'nullable' => false,
],
]), true);
$names = array_column($expected, 'name');
Expand Down
2 changes: 1 addition & 1 deletion user_guide_src/source/database/metadata.rst
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ database:
- ``name`` - column name
- ``type`` - the type of the column
- ``max_length`` - maximum length of the column
- ``primary_key`` - integer ``1`` if the column is a primary key (all integer ``1``, even if there are multiple primary keys), otherwise integer ``0`` (This field is currently only available for ``MySQLi`` and ``SQLite3``)
- ``nullable`` - boolean ``true`` if the column is nullable, otherwise boolean ``false``
- ``default`` - the default value
- ``primary_key`` - integer ``1`` if the column is a primary key (all integer ``1``, even if there are multiple primary keys), otherwise integer ``0`` (This field is currently only available for ``MySQLi`` and ``SQLite3``)

.. note:: Since v4.4.0, SQLSRV supported ``nullable``.

Expand Down
Loading