Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Allow SqlServer to execute procs correctly.

Both SELECT and EXECUTE statements should go through
the parent method as they could fetch results.

Fixes #2558
  • Loading branch information...
commit 0cfec525b226436361ad9d0ca2802ba7af30ae14 1 parent bf700c8
Mark Story markstory authored
2  lib/Cake/Model/Datasource/Database/Sqlserver.php
View
@@ -745,7 +745,7 @@ public function lastAffected($source = null) {
*/
protected function _execute($sql, $params = array(), $prepareOptions = array()) {
$this->_lastAffected = false;
- if (strncasecmp($sql, 'SELECT', 6) == 0) {
+ if (strncasecmp($sql, 'SELECT', 6) == 0 || preg_match('/^EXEC(?:UCUTE)?\s/m', $sql) > 0) {
José Lorenzo Rodríguez Owner
lorenzo added a note

EXECUCUTE?

Andy Dawson Collaborator
AD7six added a note

with a valley-girl accent? "Exec. u CUTE!"

José Lorenzo Rodríguez Owner
lorenzo added a note

hahahaha

Mark Story Owner

Bloody hell, I'm a fool. Sorry about that.

Mark Story Owner

Un-derped in [9c1fa28]

Thomas Ploch
tPl0ch added a note

lol

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
$prepareOptions += array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL);
return parent::_execute($sql, $params, $prepareOptions);
}
27 lib/Cake/Test/Case/Model/Datasource/Database/SqlserverTest.php
View
@@ -633,4 +633,31 @@ public function testLimitOffsetHack() {
$this->assertEquals('nate', $results[1]['User']['user']);
}
+/**
+ * Test that the return of stored procedures is honoured
+ *
+ * @return void
+ */
+ public function testStoredProcedureReturn() {
+ $sql = <<<SQL
+CREATE PROCEDURE cake_test_procedure
+AS
+BEGIN
+RETURN 2;
+END
+SQL;
+ $this->Dbo->execute($sql);
+
+ $sql = <<<SQL
+DECLARE @return_value int
+EXEC @return_value = [cake_test_procedure]
+SELECT 'value' = @return_value
+SQL;
+ $query = $this->Dbo->execute($sql);
+ $this->Dbo->execute('DROP PROC cake_test_procedure');
+
+ $result = $query->fetch();
+ $this->assertEquals(2, $result['value']);
+ }
+
}
Please sign in to comment.
Something went wrong with that request. Please try again.