|
15 | 15 |
|
16 | 16 | use CodeIgniter\Database\BasePreparedQuery; |
17 | 17 | use CodeIgniter\Exceptions\BadMethodCallException; |
| 18 | +use ErrorException; |
18 | 19 | use OCILob; |
19 | 20 |
|
20 | 21 | /** |
@@ -85,19 +86,27 @@ public function _execute(array $data): bool |
85 | 86 | } |
86 | 87 | } |
87 | 88 |
|
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); |
89 | 93 |
|
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 | + } |
92 | 103 | } |
93 | 104 |
|
94 | 105 | if ($result === false) { |
95 | | - $error = oci_error($this->statement); |
96 | | - $this->errorCode = $error['code'] ?? 0; |
97 | | - $this->errorString = $error['message'] ?? ''; |
| 106 | + $this->setDatabaseExceptionFromStatement(); |
98 | 107 |
|
99 | 108 | if ($this->db->DBDebug) { |
100 | | - throw $this->db->createDatabaseException($this->errorString, $this->errorCode); |
| 109 | + throw $this->databaseException; |
101 | 110 | } |
102 | 111 | } |
103 | 112 |
|
@@ -126,6 +135,17 @@ protected function _close(): bool |
126 | 135 | return oci_free_statement($this->statement); |
127 | 136 | } |
128 | 137 |
|
| 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 | + |
129 | 149 | /** |
130 | 150 | * Replaces the ? placeholders with :0, :1, etc parameters for use |
131 | 151 | * within the prepared query. |
|
0 commit comments