Skip to content

Commit

Permalink
Merge pull request #58 from skipperbent/v3-development
Browse files Browse the repository at this point in the history
Exception fixes
  • Loading branch information
skipperbent authored Jan 16, 2018
2 parents f419594 + 90b7113 commit bf3d210
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/Pecee/Pixie/ConnectionAdapters/Mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Pecee/Pixie/ConnectionAdapters/Pgsql.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Pecee/Pixie/ConnectionAdapters/Sqlite.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/Pecee/Pixie/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Pecee\Pixie;

use Pecee\Pixie\QueryBuilder\QueryObject;
use Throwable;

/**
* Class Exception
Expand All @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Pecee/Pixie/QueryBuilder/QueryBuilderHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/Pecee/Pixie/QueryBuilder/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
Expand All @@ -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.');
Expand All @@ -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];
Expand Down

0 comments on commit bf3d210

Please sign in to comment.