Skip to content

Commit a8b447f

Browse files
committed
- Throw more specific exception for "Integrity constraint violation: Duplicate entry"
1 parent 6f51a04 commit a8b447f

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

src/Databases/MySQL/MySQLExceptionInterpreter.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
namespace Kir\MySQL\Databases\MySQL;
33

4+
use Kir\MySQL\Exceptions\DuplicateUniqueKeyException;
45
use Kir\MySQL\Exceptions\LockWaitTimeoutExceededException;
56
use Kir\MySQL\Exceptions\SqlDeadLockException;
67
use PDO;
@@ -31,6 +32,9 @@ public function throwMoreConcreteException(PDOException $exception) {
3132
if($code === 1205) {
3233
throw new LockWaitTimeoutExceededException($message, $code, $exception);
3334
}
35+
if($code === 1062) {
36+
throw new DuplicateUniqueKeyException($message, $code, $exception);
37+
}
3438
throw $exception;
3539
}
3640
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
namespace Kir\MySQL\Exceptions;
3+
4+
class DuplicateUniqueKeyException extends IntegrityConstraintViolationException {
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
namespace Kir\MySQL\Exceptions;
3+
4+
class IntegrityConstraintViolationException extends SqlException {
5+
}

0 commit comments

Comments
 (0)