Permalink
Browse files

Included an option to configure the prepate statement. SQL Server req…

…uires the cursor option to return the affected rows.
  • Loading branch information...
1 parent 11d249e commit 968fa1d5ef4e4da72340a10abe47f10fa22556c5 @jrbasso jrbasso committed May 22, 2011
Showing with 18 additions and 2 deletions.
  1. +15 −0 lib/Cake/Model/Datasource/Database/Mssql.php
  2. +3 −2 lib/Cake/Model/Datasource/DboSource.php
@@ -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);
+ }
+
}
@@ -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));
@@ -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;

0 comments on commit 968fa1d

Please sign in to comment.