Skip to content

Commit 0e9ad55

Browse files
committed
fix(database): classify OCI8 prepared execution errors
- Capture native OCI8 statement errors during prepared execution - Route OCI8 prepared failures through shared exception classification Signed-off-by: memleakd <121398829+memleakd@users.noreply.github.com>
1 parent 7646fbd commit 0e9ad55

1 file changed

Lines changed: 27 additions & 7 deletions

File tree

system/Database/OCI8/PreparedQuery.php

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
use CodeIgniter\Database\BasePreparedQuery;
1717
use CodeIgniter\Exceptions\BadMethodCallException;
18+
use ErrorException;
1819
use OCILob;
1920

2021
/**
@@ -85,19 +86,27 @@ public function _execute(array $data): bool
8586
}
8687
}
8788

88-
$result = oci_execute($this->statement, $this->db->commitMode);
89+
try {
90+
$result = oci_execute($this->statement, $this->db->commitMode);
91+
} catch (ErrorException $e) {
92+
$this->setDatabaseExceptionFromStatement($e);
8993

90-
if ($binaryData instanceof OCILob) {
91-
$binaryData->free();
94+
if ($this->db->DBDebug) {
95+
throw $this->databaseException;
96+
}
97+
98+
return false;
99+
} finally {
100+
if ($binaryData instanceof OCILob) {
101+
$binaryData->free();
102+
}
92103
}
93104

94105
if ($result === false) {
95-
$error = oci_error($this->statement);
96-
$this->errorCode = $error['code'] ?? 0;
97-
$this->errorString = $error['message'] ?? '';
106+
$this->setDatabaseExceptionFromStatement();
98107

99108
if ($this->db->DBDebug) {
100-
throw $this->db->createDatabaseException($this->errorString, $this->errorCode);
109+
throw $this->databaseException;
101110
}
102111
}
103112

@@ -126,6 +135,17 @@ protected function _close(): bool
126135
return oci_free_statement($this->statement);
127136
}
128137

138+
/**
139+
* Captures the native OCI statement error for shared database exception classification.
140+
*/
141+
private function setDatabaseExceptionFromStatement(?ErrorException $previous = null): void
142+
{
143+
$error = oci_error($this->statement);
144+
$this->errorCode = $error['code'] ?? 0;
145+
$this->errorString = $error['message'] ?? $previous?->getMessage() ?? '';
146+
$this->databaseException = $this->db->createDatabaseException($this->errorString, $this->errorCode, $previous);
147+
}
148+
129149
/**
130150
* Replaces the ? placeholders with :0, :1, etc parameters for use
131151
* within the prepared query.

0 commit comments

Comments
 (0)