Skip to content

Commit a0c46da

Browse files
committed
refactor: remove unneeded changes in OCI8, Forge, and BaseConnection
1 parent e34428a commit a0c46da

5 files changed

Lines changed: 7 additions & 52 deletions

File tree

‎system/Database/BaseConnection.php‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1726,13 +1726,7 @@ public function listTables(bool $constrainByPrefix = false)
17261726
public function tableExists(string $tableName, bool $cached = true): bool
17271727
{
17281728
if ($cached) {
1729-
$tableName = $this->protectIdentifiers($tableName, true, false, false);
1730-
1731-
return in_array(
1732-
strtolower($tableName),
1733-
array_map(strtolower(...), $this->listTables()),
1734-
true,
1735-
);
1729+
return in_array($this->protectIdentifiers($tableName, true, false, false), $this->listTables(), true);
17361730
}
17371731

17381732
if (false === ($sql = $this->_listTables(false, $tableName))) {

‎system/Database/Forge.php‎

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -572,16 +572,8 @@ public function createTable(string $table, bool $ifNotExists = false, array $att
572572
$sql = $this->_createTable($table, false, $attributes);
573573

574574
if (($result = $this->db->query($sql)) !== false) {
575-
if (isset($this->db->dataCache['table_names'])) {
576-
$exists = in_array(
577-
strtolower($table),
578-
array_map(strtolower(...), $this->db->dataCache['table_names']),
579-
true,
580-
);
581-
582-
if (! $exists) {
583-
$this->db->dataCache['table_names'][] = $table;
584-
}
575+
if (isset($this->db->dataCache['table_names']) && ! in_array($table, $this->db->dataCache['table_names'], true)) {
576+
$this->db->dataCache['table_names'][] = $table;
585577
}
586578

587579
// Most databases don't support creating indexes from within the CREATE TABLE statement

‎system/Database/OCI8/Connection.php‎

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
use ErrorException;
2121
use stdClass;
2222

23-
defined('OCI_COMMIT_ON_SUCCESS') || define('OCI_COMMIT_ON_SUCCESS', 32);
24-
2523
/**
2624
* Connection for OCI8
2725
*
@@ -157,22 +155,6 @@ public function connect(bool $persistent = false)
157155
: $func($this->username, $this->password, $this->DSN, $this->charset);
158156
}
159157

160-
public function initialize()
161-
{
162-
parent::initialize();
163-
164-
if ($this->connID) {
165-
$this->simpleQuery("ALTER SESSION SET NLS_DATE_FORMAT='YYYY-MM-DD HH24:MI:SS'");
166-
$this->simpleQuery("ALTER SESSION SET NLS_TIMESTAMP_FORMAT='YYYY-MM-DD HH24:MI:SS'");
167-
$this->simpleQuery("ALTER SESSION SET NLS_TIMESTAMP_TZ_FORMAT='YYYY-MM-DD HH24:MI:SS'");
168-
}
169-
}
170-
171-
/**
172-
* Close the database connection.
173-
*
174-
* @return void
175-
*/
176158
protected function _close()
177159
{
178160
if (is_resource($this->cursorId)) {
@@ -282,7 +264,7 @@ public function parseInsertTableName(string $sql): string
282264
return '';
283265
}
284266

285-
preg_match('/(?is)\b(?:into)\s+(?:\"?\w+\"?\.)?(\"?\w+\"?)/', $commentStrippedSql, $match);
267+
preg_match('/(?is)\b(?:into)\s+("?\w+"?)/', $commentStrippedSql, $match);
286268
$tableName = $match[1] ?? '';
287269

288270
return str_starts_with($tableName, '"') ? trim($tableName, '"') : strtoupper($tableName);
@@ -422,7 +404,7 @@ protected function _indexData(string $table): array
422404
$retVal[$row->INDEX_NAME] = new stdClass();
423405
$retVal[$row->INDEX_NAME]->name = $row->INDEX_NAME;
424406
$retVal[$row->INDEX_NAME]->fields = [$row->COLUMN_NAME];
425-
$retVal[$row->INDEX_NAME]->type = $constraintTypes[$row->CONSTRAINT_TYPE ?? ''] ?? 'INDEX';
407+
$retVal[$row->INDEX_NAME]->type = $constraintTypes[$row->CONSTRAINT_TYPE] ?? 'INDEX';
426408
}
427409

428410
return $retVal;
@@ -638,7 +620,7 @@ public function insertID(): int
638620
}
639621

640622
$primaryColumnName = $this->protectIdentifiers($index->fields[0], false, false);
641-
$primaryColumnType = $columnTypeList[$primaryColumnName] ?? $columnTypeList[strtoupper($primaryColumnName)] ?? null;
623+
$primaryColumnType = $columnTypeList[$primaryColumnName];
642624

643625
if ($primaryColumnType !== 'NUMBER') {
644626
$primaryColumnName = '';

‎tests/system/Database/BaseConnectionTest.php‎

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -530,18 +530,4 @@ protected function getDriverFunctionPrefix(): string
530530

531531
$this->assertTrue($db->callFunction('contains', 'CodeIgniter', 'Ignite'));
532532
}
533-
534-
public function testTableExistsIsCaseInsensitiveForCachedTables(): void
535-
{
536-
$db = new class ($this->options) extends MockConnection {
537-
public function listTables(bool $constrainByPrefix = false): array
538-
{
539-
return ['test_USER', 'test_JOB'];
540-
}
541-
};
542-
543-
$this->assertTrue($db->tableExists('user', true));
544-
$this->assertTrue($db->tableExists('USER', true));
545-
$this->assertTrue($db->tableExists('test_user', true));
546-
}
547533
}

‎tests/system/Database/Live/WorkerModeTest.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ final class WorkerModeTest extends CIUnitTestCase
3030
protected function tearDown(): void
3131
{
3232
parent::tearDown();
33+
3334
$this->setPrivateProperty(Config::class, 'instances', []);
3435
}
3536

0 commit comments

Comments
 (0)