Skip to content

Commit fc9e325

Browse files
committed
fix(Database): essential OCI8 fixes for deterministic test execution
- Connection::initialize() sets NLS session formats via ALTER SESSION, preventing ORA-01843 when env vars are not set. - _indexData() handles null CONSTRAINT_TYPE to avoid deprecated null array offset error. - MetadataTest captures prefix before createExtraneousTable() to prevent prefix leak on exception. - ExecuteLogMessageFormatTest removes stale OCI8-specific array_slice.
1 parent 8cc20d3 commit fc9e325

3 files changed

Lines changed: 13 additions & 6 deletions

File tree

‎system/Database/OCI8/Connection.php‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,17 @@ public function connect(bool $persistent = false)
150150
: $func($this->username, $this->password, $this->DSN, $this->charset);
151151
}
152152

153+
public function initialize()
154+
{
155+
parent::initialize();
156+
157+
if ($this->connID) {
158+
$this->simpleQuery("ALTER SESSION SET NLS_DATE_FORMAT='YYYY-MM-DD HH24:MI:SS'");
159+
$this->simpleQuery("ALTER SESSION SET NLS_TIMESTAMP_FORMAT='YYYY-MM-DD HH24:MI:SS'");
160+
$this->simpleQuery("ALTER SESSION SET NLS_TIMESTAMP_TZ_FORMAT='YYYY-MM-DD HH24:MI:SS'");
161+
}
162+
}
163+
153164
/**
154165
* Close the database connection.
155166
*
@@ -422,7 +433,7 @@ protected function _indexData(string $table): array
422433
$retVal[$row->INDEX_NAME] = new stdClass();
423434
$retVal[$row->INDEX_NAME]->name = $row->INDEX_NAME;
424435
$retVal[$row->INDEX_NAME]->fields = [$row->COLUMN_NAME];
425-
$retVal[$row->INDEX_NAME]->type = $constraintTypes[$row->CONSTRAINT_TYPE] ?? 'INDEX';
436+
$retVal[$row->INDEX_NAME]->type = $constraintTypes[$row->CONSTRAINT_TYPE ?? ''] ?? 'INDEX';
426437
}
427438

428439
return $retVal;

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@ public function testLogMessageWhenExecuteFailsShowFullStructuredBacktrace(): voi
6060

6161
if ($db->DBDriver === 'Postgre') {
6262
$messageFromLogs = array_slice($messageFromLogs, 2);
63-
} elseif ($db->DBDriver === 'OCI8') {
64-
$messageFromLogs = array_slice($messageFromLogs, 1);
6563
}
6664

6765
$this->assertMatchesRegularExpression('/^in \S+ on line \d+\.$/', array_shift($messageFromLogs));

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,10 @@ public function testListTablesConstrainedByPrefixReturnsOnlyTablesWithMatchingPr
120120

121121
public function testListTablesConstrainedByExtraneousPrefixReturnsOnlyTheExtraneousTable(): void
122122
{
123-
$oldPrefix = '';
123+
$oldPrefix = $this->db->getPrefix();
124124

125125
try {
126126
$this->createExtraneousTable();
127-
128-
$oldPrefix = $this->db->getPrefix();
129127
$this->db->setPrefix('tmp_');
130128

131129
$tables = $this->db->listTables(true);

0 commit comments

Comments
 (0)