From a79168778457bd6ee3c9bfab5458600c47152d05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Lorenzo=20Rodr=C3=ADguez?= Date: Sun, 28 Nov 2010 23:50:18 -0430 Subject: [PATCH] Adding try catch for pdo exception on DboSource::_execute --- .../libs/model/datasources/dbo/dbo_sqlite.php | 13 -------- cake/libs/model/datasources/dbo_source.php | 30 +++++++++++-------- 2 files changed, 18 insertions(+), 25 deletions(-) diff --git a/cake/libs/model/datasources/dbo/dbo_sqlite.php b/cake/libs/model/datasources/dbo/dbo_sqlite.php index c7e96e996..fb3ad0b4b 100644 --- a/cake/libs/model/datasources/dbo/dbo_sqlite.php +++ b/cake/libs/model/datasources/dbo/dbo_sqlite.php @@ -207,19 +207,6 @@ class DboSqlite extends DboSource { return $fields; } -/** - * Executes given SQL statement. - * - * @param string $sql SQL statement - * @param array $params list of params to be bound to query - * @return PDOStatement if query executes with no problem, true as the result of a succesfull - * query returning no rows, suchs as a CREATE statement, false otherwise - */ - protected function _execute($sql, $params = array()) { - $this->_result = parent::_execute($sql, $params); - return $this->_result; - } - /** * Generates and executes an SQL UPDATE statement for given model, fields, and values. * diff --git a/cake/libs/model/datasources/dbo_source.php b/cake/libs/model/datasources/dbo_source.php index 44e7c758d..5183447bc 100755 --- a/cake/libs/model/datasources/dbo_source.php +++ b/cake/libs/model/datasources/dbo_source.php @@ -344,19 +344,25 @@ class DboSource extends DataSource { } } - $query = $this->_connection->prepare($sql); - $query->setFetchMode(PDO::FETCH_LAZY); - if (!$query->execute($params)) { - $this->_results = $query; - $this->error = $this->lastError($query); - $query->closeCursor(); - return false; + try { + $query = $this->_connection->prepare($sql); + $query->setFetchMode(PDO::FETCH_LAZY); + if (!$query->execute($params)) { + $this->_results = $query; + $this->error = $this->lastError($query); + $query->closeCursor(); + return false; + } + if (!$query->columnCount()) { + $query->closeCursor(); + return true; + } + return $query; + } catch (PDOException $e) { + $this->_results = null; + $this->error = $e->getMessage(); } - if (!$query->columnCount()) { - $query->closeCursor(); - return true; - } - return $query; + } /**