Skip to content

Commit

Permalink
Included an option to configure the prepate statement. SQL Server req…
Browse files Browse the repository at this point in the history
…uires the cursor option to return the affected rows.
  • Loading branch information
jrbasso committed May 22, 2011
1 parent 11d249e commit 968fa1d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
15 changes: 15 additions & 0 deletions lib/Cake/Model/Datasource/Database/Mssql.php
Expand Up @@ -689,4 +689,19 @@ protected function _getPrimaryKey($model) {
}
return null;
}

/**
* Executes given SQL statement.
*
* @param string $sql SQL statement
* @param array $params list of params to be bound to query
* @param array $prepareOptions Options to be used in the prepare statement
* @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(), $prepareOptions = array()) {
$prepareOptions += array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL);
return parent::_execute($sql, $params, $prepareOptions);
}

}
5 changes: 3 additions & 2 deletions lib/Cake/Model/Datasource/DboSource.php
Expand Up @@ -450,10 +450,11 @@ public function execute($sql, $options = array(), $params = array()) {
*
* @param string $sql SQL statement
* @param array $params list of params to be bound to query
* @param array $prepareOptions Options to be used in the prepare statement
* @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()) {
protected function _execute($sql, $params = array(), $prepareOptions = array()) {
$sql = trim($sql);
if (preg_match('/^(?:CREATE|ALTER|DROP)/i', $sql)) {
$statements = array_filter(explode(';', $sql));
Expand All @@ -464,7 +465,7 @@ protected function _execute($sql, $params = array()) {
}

try {
$query = $this->_connection->prepare($sql);
$query = $this->_connection->prepare($sql, $prepareOptions);
$query->setFetchMode(PDO::FETCH_LAZY);
if (!$query->execute($params)) {
$this->_results = $query;
Expand Down

0 comments on commit 968fa1d

Please sign in to comment.