|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Doctrine\DBAL\Driver; |
|
4
|
|
|
|
|
5
|
|
|
use Exception; |
|
6
|
|
|
use Throwable; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* A driver exception. |
|
10
|
|
|
* |
|
11
|
|
|
* Driver exceptions provide the SQLSTATE of the driver |
|
12
|
|
|
* and the driver specific error code at the time the error occurred. |
|
13
|
|
|
*/ |
|
14
|
|
|
class DriverException extends Exception |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* The driver specific error code. |
|
18
|
|
|
* |
|
19
|
|
|
* @var int|string|null |
|
20
|
|
|
*/ |
|
21
|
|
|
private $errorCode; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* The SQLSTATE of the driver. |
|
25
|
|
|
* |
|
26
|
|
|
* @var string|null |
|
27
|
|
|
*/ |
|
28
|
|
|
private $sqlState; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @param string $message The driver error message. |
|
32
|
|
|
* @param string|null $sqlState The SQLSTATE the driver is in at the time the error occurred, if any. |
|
33
|
|
|
* @param int|string|null $errorCode The driver specific error code if any. |
|
34
|
|
|
* @param Throwable|null $previous The previous throwable used for the exception chaining. |
|
35
|
|
|
*/ |
|
36
|
3502 |
|
public function __construct(string $message, ?string $sqlState = null, $errorCode = null, ?Throwable $previous = null) |
|
37
|
|
|
{ |
|
38
|
3502 |
|
parent::__construct($message, 0, $previous); |
|
39
|
|
|
|
|
40
|
3502 |
|
$this->errorCode = $errorCode; |
|
41
|
3502 |
|
$this->sqlState = $sqlState; |
|
42
|
3502 |
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @return DriverException |
|
46
|
|
|
*/ |
|
47
|
16 |
|
public static function noInsertId() : self |
|
48
|
|
|
{ |
|
49
|
16 |
|
return new self('No identity value was generated by the last statement.'); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @param string $name The sequence name. |
|
54
|
|
|
* |
|
55
|
|
|
* @return DriverException |
|
56
|
|
|
*/ |
|
57
|
8 |
|
public static function noSuchSequence(string $name) : self |
|
58
|
|
|
{ |
|
59
|
8 |
|
return new self('No sequence with name "' . $name . '" found.'); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Returns the driver specific error code if available. |
|
64
|
|
|
* |
|
65
|
|
|
* Returns null if no driver specific error code is available |
|
66
|
|
|
* for the error raised by the driver. |
|
67
|
|
|
* |
|
68
|
|
|
* @return int|string|null The error code. |
|
69
|
|
|
*/ |
|
70
|
2012 |
|
public function getErrorCode() |
|
71
|
|
|
{ |
|
72
|
2012 |
|
return $this->errorCode; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Returns the SQLSTATE the driver was in at the time the error occurred. |
|
77
|
|
|
* |
|
78
|
|
|
* Returns null if the driver does not provide a SQLSTATE for the error occurred. |
|
79
|
|
|
* |
|
80
|
|
|
* @return string|null The SQLSTATE, or null if not available. |
|
81
|
|
|
*/ |
|
82
|
1156 |
|
public function getSQLState() : ?string |
|
83
|
|
|
{ |
|
84
|
1156 |
|
return $this->sqlState; |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|