1
1
<?php
2
2
namespace Kir \MySQL \Databases ;
3
3
4
+ use PDO ;
5
+ use PDOException ;
6
+ use UnexpectedValueException ;
7
+ use Kir \MySQL \Builder \RunnableSelect ;
4
8
use Kir \MySQL \Builder ;
5
9
use Kir \MySQL \Builder \Exception ;
6
10
use Kir \MySQL \Builder \QueryStatement ;
7
11
use Kir \MySQL \Database ;
12
+ use Kir \MySQL \Databases \MySQL \MySQLExceptionInterpreter ;
8
13
use Kir \MySQL \QueryLogger \QueryLoggers ;
9
14
use Kir \MySQL \Tools \AliasRegistry ;
10
- use PDO ;
11
- use UnexpectedValueException ;
12
- use Kir \MySQL \Builder \RunnableSelect ;
13
15
14
16
/**
15
17
*/
@@ -32,6 +34,7 @@ public function __construct(PDO $pdo) {
32
34
$ this ->pdo = $ pdo ;
33
35
$ this ->aliasRegistry = new AliasRegistry ();
34
36
$ this ->queryLoggers = new QueryLoggers ();
37
+ $ this ->exceptionInterpreter = new MySQLExceptionInterpreter ($ pdo );
35
38
}
36
39
37
40
/**
@@ -84,7 +87,11 @@ public function prepare($query) {
84
87
public function exec ($ query , array $ params = array ()) {
85
88
$ stmt = $ this ->pdo ->prepare ($ query );
86
89
$ timer = microtime (true );
87
- $ stmt ->execute ($ params );
90
+ try {
91
+ $ stmt ->execute ($ params );
92
+ } catch (PDOException $ e ) {
93
+ $ this ->exceptionInterpreter ->throwMoreConcreteException ($ e );
94
+ }
88
95
$ this ->queryLoggers ->log ($ query , microtime (true ) - $ timer );
89
96
$ result = $ stmt ->rowCount ();
90
97
$ stmt ->closeCursor ();
@@ -216,12 +223,12 @@ public function transactionStart() {
216
223
217
224
/**
218
225
* @return $this
219
- * @throws Exception
226
+ * @throws \ Exception
220
227
*/
221
228
public function transactionCommit () {
222
229
$ this ->transactionLevel --;
223
230
if ($ this ->transactionLevel < 0 ) {
224
- throw new Exception ("Transaction-Nesting-Problem: Trying to invoke commit on a already closed transaction " );
231
+ throw new \ Exception ("Transaction-Nesting-Problem: Trying to invoke commit on a already closed transaction " );
225
232
}
226
233
if ((int ) $ this ->transactionLevel === 0 ) {
227
234
$ this ->pdo ->commit ();
@@ -231,12 +238,12 @@ public function transactionCommit() {
231
238
232
239
/**
233
240
* @return $this
234
- * @throws Exception
241
+ * @throws \ Exception
235
242
*/
236
243
public function transactionRollback () {
237
244
$ this ->transactionLevel --;
238
245
if ($ this ->transactionLevel < 0 ) {
239
- throw new Exception ("Transaction-Nesting-Problem: Trying to invoke rollback on a already closed transaction " );
246
+ throw new \ Exception ("Transaction-Nesting-Problem: Trying to invoke rollback on a already closed transaction " );
240
247
}
241
248
if ((int ) $ this ->transactionLevel === 0 ) {
242
249
$ this ->pdo ->rollBack ();
@@ -249,6 +256,7 @@ public function transactionRollback() {
249
256
* @param callable|null $callback
250
257
* @return mixed
251
258
* @throws \Exception
259
+ * @throws null
252
260
*/
253
261
public function transaction ($ tries = 1 , $ callback = null ) {
254
262
if (is_callable ($ tries )) {
0 commit comments