From 90b71139b392125de9a3cad7f82df28cda58019f Mon Sep 17 00:00:00 2001 From: Simon Sessingo Date: Tue, 16 Jan 2018 14:13:32 +0100 Subject: [PATCH] Exception fixes --- src/Pecee/Pixie/ConnectionAdapters/Mysql.php | 2 +- src/Pecee/Pixie/ConnectionAdapters/Pgsql.php | 2 +- src/Pecee/Pixie/ConnectionAdapters/Sqlite.php | 2 +- src/Pecee/Pixie/Exception.php | 5 +++-- src/Pecee/Pixie/QueryBuilder/QueryBuilderHandler.php | 2 +- src/Pecee/Pixie/QueryBuilder/Transaction.php | 6 +++--- 6 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/Pecee/Pixie/ConnectionAdapters/Mysql.php b/src/Pecee/Pixie/ConnectionAdapters/Mysql.php index 585b63a..9ede841 100644 --- a/src/Pecee/Pixie/ConnectionAdapters/Mysql.php +++ b/src/Pecee/Pixie/ConnectionAdapters/Mysql.php @@ -47,7 +47,7 @@ protected function doConnect(array $config) } } catch (\PDOException $e) { - throw new Exception($e->getMessage(), $e->getCode()); + throw new Exception($e->getMessage(), $e->getCode(), $e->getPrevious()); } return $connection; diff --git a/src/Pecee/Pixie/ConnectionAdapters/Pgsql.php b/src/Pecee/Pixie/ConnectionAdapters/Pgsql.php index f9bb1a2..79c3964 100644 --- a/src/Pecee/Pixie/ConnectionAdapters/Pgsql.php +++ b/src/Pecee/Pixie/ConnectionAdapters/Pgsql.php @@ -46,7 +46,7 @@ protected function doConnect(array $config) } } catch (\PDOException $e) { - throw new Exception($e->getMessage(), $e->getCode()); + throw new Exception($e->getMessage(), $e->getCode(), $e->getPrevious()); } return $connection; diff --git a/src/Pecee/Pixie/ConnectionAdapters/Sqlite.php b/src/Pecee/Pixie/ConnectionAdapters/Sqlite.php index a37fff2..8134ce1 100644 --- a/src/Pecee/Pixie/ConnectionAdapters/Sqlite.php +++ b/src/Pecee/Pixie/ConnectionAdapters/Sqlite.php @@ -29,7 +29,7 @@ public function doConnect(array $config) try { return new PDO($connectionString, null, null, $config['options']); } catch (\PDOException $e) { - throw new Exception($e->getMessage(), $e->getCode()); + throw new Exception($e->getMessage(), $e->getCode(), $e->getPrevious()); } } diff --git a/src/Pecee/Pixie/Exception.php b/src/Pecee/Pixie/Exception.php index ab2473b..946d074 100644 --- a/src/Pecee/Pixie/Exception.php +++ b/src/Pecee/Pixie/Exception.php @@ -3,6 +3,7 @@ namespace Pecee\Pixie; use Pecee\Pixie\QueryBuilder\QueryObject; +use Throwable; /** * Class Exception @@ -14,9 +15,9 @@ class Exception extends \Exception protected $query; - public function __construct($message = '', $code = 0, $query = null) + public function __construct($message = "", $code = 0, Throwable $previous = null, QueryObject $query = null) { - parent::__construct($message, $code); + parent::__construct($message, $code, $previous); $this->query = $query; } diff --git a/src/Pecee/Pixie/QueryBuilder/QueryBuilderHandler.php b/src/Pecee/Pixie/QueryBuilder/QueryBuilderHandler.php index 74628fe..c3a5c4f 100644 --- a/src/Pecee/Pixie/QueryBuilder/QueryBuilderHandler.php +++ b/src/Pecee/Pixie/QueryBuilder/QueryBuilderHandler.php @@ -1200,7 +1200,7 @@ public function transaction(\Closure $callback) $this->pdo->rollBack(); } - throw new Exception($e->getMessage(), $e->getCode(), $this->connection->getLastQuery()); + throw new Exception($e->getMessage(), $e->getCode(), $e->getPrevious(), $this->connection->getLastQuery()); } return $queryTransaction; diff --git a/src/Pecee/Pixie/QueryBuilder/Transaction.php b/src/Pecee/Pixie/QueryBuilder/Transaction.php index 4eebb01..2633e5c 100644 --- a/src/Pecee/Pixie/QueryBuilder/Transaction.php +++ b/src/Pecee/Pixie/QueryBuilder/Transaction.php @@ -36,7 +36,7 @@ public function commit() try { $this->pdo->commit(); } catch (\PDOException $e) { - throw new Exception($e->getMessage(), $e->getCode(), $this->getConnection()->getLastQuery()); + throw new Exception($e->getMessage(), $e->getCode(), $e->getPrevious(), $this->getConnection()->getLastQuery()); } throw new TransactionHaltException('Commit triggered transaction-halt.'); @@ -52,7 +52,7 @@ public function rollBack() try { $this->pdo->rollBack(); } catch (\PDOException $e) { - throw new Exception($e->getMessage(), $e->getCode(), $this->getConnection()->getLastQuery()); + throw new Exception($e->getMessage(), $e->getCode(), $e->getPrevious(), $this->getConnection()->getLastQuery()); } throw new TransactionHaltException('Rollback triggered transaction-halt.'); @@ -79,7 +79,7 @@ public function statement($sql, array $bindings = []) $this->transactionStatement->execute($bindings); } catch(\PDOException $e) { - throw new Exception($e->getMessage(), $e->getCode(), $this->connection->getLastQuery()); + throw new Exception($e->getMessage(), $e->getCode(), $e->getPrevious(), $this->getConnection()->getLastQuery()); } return [$this->transactionStatement, microtime(true) - $start];