11<?php
22namespace Kir \MySQL \Databases ;
33
4+ use PDO ;
5+ use PDOException ;
6+ use UnexpectedValueException ;
7+ use Kir \MySQL \Builder \RunnableSelect ;
48use Kir \MySQL \Builder ;
59use Kir \MySQL \Builder \Exception ;
610use Kir \MySQL \Builder \QueryStatement ;
711use Kir \MySQL \Database ;
12+ use Kir \MySQL \Databases \MySQL \MySQLExceptionInterpreter ;
813use Kir \MySQL \QueryLogger \QueryLoggers ;
914use Kir \MySQL \Tools \AliasRegistry ;
10- use PDO ;
11- use UnexpectedValueException ;
12- use Kir \MySQL \Builder \RunnableSelect ;
1315
1416/**
1517 */
@@ -32,6 +34,7 @@ public function __construct(PDO $pdo) {
3234 $ this ->pdo = $ pdo ;
3335 $ this ->aliasRegistry = new AliasRegistry ();
3436 $ this ->queryLoggers = new QueryLoggers ();
37+ $ this ->exceptionInterpreter = new MySQLExceptionInterpreter ($ pdo );
3538 }
3639
3740 /**
@@ -84,7 +87,11 @@ public function prepare($query) {
8487 public function exec ($ query , array $ params = array ()) {
8588 $ stmt = $ this ->pdo ->prepare ($ query );
8689 $ timer = microtime (true );
87- $ stmt ->execute ($ params );
90+ try {
91+ $ stmt ->execute ($ params );
92+ } catch (PDOException $ e ) {
93+ $ this ->exceptionInterpreter ->throwMoreConcreteException ($ e );
94+ }
8895 $ this ->queryLoggers ->log ($ query , microtime (true ) - $ timer );
8996 $ result = $ stmt ->rowCount ();
9097 $ stmt ->closeCursor ();
@@ -216,12 +223,12 @@ public function transactionStart() {
216223
217224 /**
218225 * @return $this
219- * @throws Exception
226+ * @throws \ Exception
220227 */
221228 public function transactionCommit () {
222229 $ this ->transactionLevel --;
223230 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 " );
225232 }
226233 if ((int ) $ this ->transactionLevel === 0 ) {
227234 $ this ->pdo ->commit ();
@@ -231,12 +238,12 @@ public function transactionCommit() {
231238
232239 /**
233240 * @return $this
234- * @throws Exception
241+ * @throws \ Exception
235242 */
236243 public function transactionRollback () {
237244 $ this ->transactionLevel --;
238245 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 " );
240247 }
241248 if ((int ) $ this ->transactionLevel === 0 ) {
242249 $ this ->pdo ->rollBack ();
@@ -249,6 +256,7 @@ public function transactionRollback() {
249256 * @param callable|null $callback
250257 * @return mixed
251258 * @throws \Exception
259+ * @throws null
252260 */
253261 public function transaction ($ tries = 1 , $ callback = null ) {
254262 if (is_callable ($ tries )) {
0 commit comments