Adding try catch for pdo exception on DboSource::_execute

This commit is contained in:
José Lorenzo Rodríguez 2010-11-28 23:50:18 -04:30
parent 130fe603a7
commit a791687784
2 changed files with 18 additions and 25 deletions

View file

@ -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.
*

View file

@ -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;
}
/**