Skip to content

Commit 7646fbd

Browse files
committed
fix(database): normalize OCI8 exception codes
- Classify OCI8 unique and retryable transaction errors from string codes - Add coverage for OCI8 string-code exception classification Signed-off-by: memleakd <121398829+memleakd@users.noreply.github.com>
1 parent 0adb17c commit 7646fbd

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

system/Database/OCI8/Connection.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,15 @@ class Connection extends BaseConnection
120120
protected function isUniqueConstraintViolation(int|string $code, string $message): bool
121121
{
122122
// ORA-00001: unique constraint violated.
123-
return $code === 1;
123+
return (int) $code === 1;
124124
}
125125

126126
/**
127127
* Checks whether the native database code represents a retryable transaction failure.
128128
*/
129129
protected function isRetryableTransactionErrorCode(int|string $code): bool
130130
{
131-
return in_array($code, [60, 8177], true);
131+
return in_array((int) $code, [60, 8177], true);
132132
}
133133

134134
/**

tests/system/Database/RetryableTransactionExceptionTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ public static function provideCreatesUniqueConstraintViolationExceptions(): iter
9494
1,
9595
'Unique constraint violated.',
9696
];
97+
98+
yield 'OCI8 unique constraint string code' => [
99+
self::connection(OCI8Connection::class, 'OCI8'),
100+
'1',
101+
'Unique constraint violated.',
102+
];
97103
}
98104
}
99105

@@ -128,7 +134,11 @@ public static function provideCreatesRetryableTransactionExceptions(): iterable
128134
if (defined('OCI_COMMIT_ON_SUCCESS')) {
129135
yield 'OCI8 deadlock' => [self::connection(OCI8Connection::class, 'OCI8'), 60];
130136

137+
yield 'OCI8 deadlock string code' => [self::connection(OCI8Connection::class, 'OCI8'), '60'];
138+
131139
yield 'OCI8 serialization failure' => [self::connection(OCI8Connection::class, 'OCI8'), 8177];
140+
141+
yield 'OCI8 serialization failure string code' => [self::connection(OCI8Connection::class, 'OCI8'), '8177'];
132142
}
133143
}
134144

0 commit comments

Comments
 (0)