Skip to content

Commit a14f388

Browse files
committed
- MySQLExceptionInterpreter::throwMoreConcreteException now handles SQL-Error-Codes 1452
1 parent 5a0aba2 commit a14f388

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/Databases/MySQL/MySQLExceptionInterpreter.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ class MySQLExceptionInterpreter {
1515
* @throw PDOException
1616
*/
1717
public function throwMoreConcreteException(PDOException $exception) {
18-
$code = $exception->getCode();
18+
$errorInfo = $exception->errorInfo;
19+
$code = is_array($errorInfo) && isset($errorInfo[1]) ? ((int) $errorInfo[1]) : ((int) $exception->getCode());
1920
$message = (string) $exception->getMessage();
2021
switch($code) {
2122
case 2006: throw new DatabaseHasGoneAwayException($message, $code, $exception);
@@ -26,7 +27,8 @@ public function throwMoreConcreteException(PDOException $exception) {
2627
case 1169:
2728
case 1586: throw new DuplicateUniqueKeyException($message, $code, $exception);
2829
case 1216:
29-
case 1217: throw new IntegrityConstraintViolationException($message, (int) $code, $exception);
30+
case 1217:
31+
case 1452: throw new IntegrityConstraintViolationException($message, (int) $code, $exception);
3032
}
3133
/** @link http://php.net/manual/en/class.exception.php#Hcom115813 (cHao's comment) */
3234
if(!is_string($message) || !is_int($code)) {

0 commit comments

Comments
 (0)