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] getFieldData() returns incorrect default value #8459

Merged
merged 4 commits 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
6 changes: 1 addition & 5 deletions system/Database/OCI8/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,11 +315,7 @@ protected function _fieldData(string $table): array

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

$default = $query[$i]->DATA_DEFAULT;
if ($default === null && $query[$i]->NULLABLE === 'N') {
$default = '';
}
$retval[$i]->default = $default;
$retval[$i]->default = $query[$i]->DATA_DEFAULT;
$retval[$i]->nullable = $query[$i]->NULLABLE === 'Y';
}

Expand Down
2 changes: 1 addition & 1 deletion tests/system/Database/Live/ForgeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
$this->assertTrue($databaseCreateIfNotExists);
}

public function testCreateDatabaseIfNotExistsWithDb(): void

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

View workflow job for this annotation

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

Took 0.52s from 0.50s limit to run CodeIgniter\\Database\\Live\\ForgeTest::testCreateDatabaseIfNotExistsWithDb
{
if ($this->db->DBDriver === 'OCI8') {
$this->markTestSkipped('OCI8 does not support create database.');
Expand Down 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.53s 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.12s 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.54s 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.52s 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 @@ -1058,7 +1058,7 @@
'name' => 'username',
'type' => 'VARCHAR2',
'max_length' => '255',
'default' => '',
'default' => null,
'nullable' => false,
],
2 => [
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.36s 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.19s 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.72s 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.53s from 0.50s limit to run CodeIgniter\\Database\\Live\\ForgeTest::testProcessIndexes
{
// make sure tables don't exist
$this->forge->dropTable('actions', true);
Expand Down
115 changes: 115 additions & 0 deletions tests/system/Database/Live/OCI8/GetFieldDataTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<?php

declare(strict_types=1);

/**
* This file is part of CodeIgniter 4 framework.
*
* (c) CodeIgniter Foundation <admin@codeigniter.com>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/

namespace CodeIgniter\Database\Live\OCI8;

use CodeIgniter\Database\Live\AbstractGetFieldDataTest;
use Config\Database;

/**
* @group DatabaseLive
*
* @internal
*/
final class GetFieldDataTest extends AbstractGetFieldDataTest
{
protected function createForge(): void
{
if ($this->db->DBDriver !== 'OCI8') {
$this->markTestSkipped('This test is only for OCI8.');
}

$this->forge = Database::forge($this->db);
}

public function testGetFieldData(): void
{
$fields = $this->db->getFieldData('test1');

$data = [];

foreach ($fields as $obj) {
$data[$obj->name] = $obj;
}

$idDefault = $data['id']->default;
$this->assertMatchesRegularExpression('/"ORACLE"."ISEQ\$\$_[0-9]+".nextval/', $idDefault);

$expected = json_decode(json_encode([
(object) [
'name' => 'id',
'type' => 'NUMBER',
'max_length' => '11',
'default' => $idDefault, // The default value is not defined.
// 'primary_key' => 1,
'nullable' => false,
],
(object) [
'name' => 'text_not_null',
'type' => 'VARCHAR2',
'max_length' => '64',
'default' => null, // The default value is not defined.
// 'primary_key' => 0,
'nullable' => false,
],
(object) [
'name' => 'text_null',
'type' => 'VARCHAR2',
'max_length' => '64',
'default' => null, // The default value is not defined.
// 'primary_key' => 0,
'nullable' => true,
],
(object) [
'name' => 'int_default_0',
'type' => 'NUMBER',
'max_length' => '11',
'default' => '0 ', // int 0
// 'primary_key' => 0,
'nullable' => false,
],
(object) [
'name' => 'text_default_null',
'type' => 'VARCHAR2',
'max_length' => '64',
'default' => 'NULL ', // NULL value
// 'primary_key' => 0,
'nullable' => true,
],
(object) [
'name' => 'text_default_text_null',
'type' => 'VARCHAR2',
'max_length' => '64',
'default' => "'null' ", // string "null"
// 'primary_key' => 0,
'nullable' => false,
],
(object) [
'name' => 'text_default_abc',
'type' => 'VARCHAR2',
'max_length' => '64',
'default' => "'abc' ", // string "abc"
// 'primary_key' => 0,
'nullable' => false,
],
]), true);
$names = array_column($expected, 'name');
array_multisort($names, SORT_ASC, $expected);

$fields = json_decode(json_encode($fields), true);
$names = array_column($fields, 'name');
array_multisort($names, SORT_ASC, $fields);

$this->assertSame($expected, $fields);
}
}
Loading