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: [SQLite3] getFieldData() returns incorrect primary_key values #8460

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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/SQLite3/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ protected function _fieldData(string $table): array
$retVal[$i]->type = $query[$i]->type;
$retVal[$i]->max_length = null;
$retVal[$i]->default = $query[$i]->dflt_value;
$retVal[$i]->primary_key = isset($query[$i]->pk) && (bool) $query[$i]->pk;
$retVal[$i]->primary_key = $query[$i]->pk ?? false;
michalsn marked this conversation as resolved.
Show resolved Hide resolved
$retVal[$i]->nullable = isset($query[$i]->notnull) && ! (bool) $query[$i]->notnull;
}

Expand Down
8 changes: 4 additions & 4 deletions tests/system/Database/Live/ForgeTest.php
Original file line number Diff line number Diff line change
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.19s 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 @@ -986,31 +986,31 @@
'type' => 'INTEGER',
'max_length' => null,
'default' => null,
'primary_key' => true,
'primary_key' => 1,
'nullable' => true,
],
1 => [
'name' => 'username',
'type' => 'VARCHAR',
'max_length' => null,
'default' => null,
'primary_key' => false,
'primary_key' => 0,
'nullable' => false,
],
2 => [
'name' => 'name',
'type' => 'VARCHAR',
'max_length' => null,
'default' => null,
'primary_key' => false,
'primary_key' => 0,
'nullable' => true,
],
3 => [
'name' => 'active',
'type' => 'INTEGER',
'max_length' => null,
'default' => '0',
'primary_key' => false,
'primary_key' => 0,
'nullable' => false,
],
];
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.35s from 0.50s limit to run CodeIgniter\\Database\\Live\\ForgeTest::testSetKeyNames
{
$this->forge->dropTable('forge_test_1', 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.13s 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.73s 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/SQLite3/GetFieldDataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,55 +47,55 @@ public function testGetFieldData(): void
'type' => 'INTEGER',
'max_length' => null,
'default' => null, // The default value is not defined.
'primary_key' => true,
'primary_key' => 1,
'nullable' => true,
],
(object) [
'name' => 'text_not_null',
'type' => 'VARCHAR',
'max_length' => null,
'default' => null, // The default value is not defined.
'primary_key' => false,
'primary_key' => 0,
'nullable' => false,
],
(object) [
'name' => 'text_null',
'type' => 'VARCHAR',
'max_length' => null,
'default' => null, // The default value is not defined.
'primary_key' => false,
'primary_key' => 0,
'nullable' => true,
],
(object) [
'name' => 'int_default_0',
'type' => 'INT',
'max_length' => null,
'default' => '0', // int 0
'primary_key' => false,
'primary_key' => 0,
'nullable' => false,
],
(object) [
'name' => 'text_default_null',
'type' => 'VARCHAR',
'max_length' => null,
'default' => 'NULL', // NULL value
'primary_key' => false,
'primary_key' => 0,
'nullable' => true,
],
(object) [
'name' => 'text_default_text_null',
'type' => 'VARCHAR',
'max_length' => null,
'default' => "'null'", // string "null"
'primary_key' => false,
'primary_key' => 0,
'nullable' => false,
],
(object) [
'name' => 'text_default_abc',
'type' => 'VARCHAR',
'max_length' => null,
'default' => "'abc'", // string "abc"
'primary_key' => false,
'primary_key' => 0,
'nullable' => false,
],
]),
Expand Down
12 changes: 6 additions & 6 deletions user_guide_src/source/database/metadata.rst
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ supplying the table name:
The following data is available from this function if supported by your
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 MySQL and SQLite3)
- nullable - boolean ``true`` if the column is nullable, otherwise boolean ``false``
- default - the default value
- ``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

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

Expand Down
Loading