File tree Expand file tree Collapse file tree 3 files changed +52
-3
lines changed Expand file tree Collapse file tree 3 files changed +52
-3
lines changed Original file line number Diff line number Diff line change 2
2
3
3
namespace Doctrine \DBAL \Driver \PDO ;
4
4
5
+ use Doctrine \DBAL \Driver \PDO \PDOException as DriverPDOException ;
5
6
use Doctrine \DBAL \Driver \Result as ResultInterface ;
6
7
use Doctrine \DBAL \Driver \ServerInfoAwareConnection ;
7
8
use Doctrine \DBAL \Driver \Statement as StatementInterface ;
@@ -107,17 +108,29 @@ public function lastInsertId($name = null)
107
108
108
109
public function beginTransaction (): bool
109
110
{
110
- return $ this ->connection ->beginTransaction ();
111
+ try {
112
+ return $ this ->connection ->beginTransaction ();
113
+ } catch (PDOException $ exception ) {
114
+ throw DriverPDOException::new ($ exception );
115
+ }
111
116
}
112
117
113
118
public function commit (): bool
114
119
{
115
- return $ this ->connection ->commit ();
120
+ try {
121
+ return $ this ->connection ->commit ();
122
+ } catch (PDOException $ exception ) {
123
+ throw DriverPDOException::new ($ exception );
124
+ }
116
125
}
117
126
118
127
public function rollBack (): bool
119
128
{
120
- return $ this ->connection ->rollBack ();
129
+ try {
130
+ return $ this ->connection ->rollBack ();
131
+ } catch (PDOException $ exception ) {
132
+ throw DriverPDOException::new ($ exception );
133
+ }
121
134
}
122
135
123
136
public function getNativeConnection (): PDO
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ namespace Doctrine \DBAL \Driver \PDO ;
6
+
7
+ use Doctrine \DBAL \Driver \Exception as DriverException ;
8
+
9
+ /**
10
+ * @internal
11
+ *
12
+ * @psalm-immutable
13
+ */
14
+ final class PDOException extends \PDOException implements DriverException
15
+ {
16
+ private ?string $ sqlState = null ;
17
+
18
+ public static function new (\PDOException $ previous ): self
19
+ {
20
+ $ exception = new self ($ previous ->message , 0 , $ previous );
21
+
22
+ $ exception ->errorInfo = $ previous ->errorInfo ;
23
+ $ exception ->code = $ previous ->code ;
24
+ $ exception ->sqlState = $ previous ->errorInfo [0 ] ?? null ;
25
+
26
+ return $ exception ;
27
+ }
28
+
29
+ public function getSQLState (): ?string
30
+ {
31
+ return $ this ->sqlState ;
32
+ }
33
+ }
Original file line number Diff line number Diff line change 2
2
3
3
namespace Doctrine \DBAL \Tests \Functional ;
4
4
5
+ use Doctrine \DBAL \Driver \Exception as DriverException ;
5
6
use Doctrine \DBAL \Platforms \AbstractMySQLPlatform ;
6
7
use Doctrine \DBAL \Tests \FunctionalTestCase ;
7
8
use PDOException ;
@@ -30,6 +31,8 @@ public function testCommitFalse(): void
30
31
try {
31
32
self ::assertFalse (@$ this ->connection ->commit ()); // we will ignore `MySQL server has gone away` warnings
32
33
} catch (PDOException $ e ) {
34
+ self ::assertInstanceOf (DriverException::class, $ e );
35
+
33
36
/* For PDO, we are using ERRMODE EXCEPTION, so this catch should be
34
37
* necessary as the equivalent of the error control operator above.
35
38
* This seems to be the case only since PHP 8 */
You can’t perform that action at this time.
0 commit comments