Permalink
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...
1 parent bf700c8 commit 0cfec525b226436361ad9d0ca2802ba7af30ae14 @markstory markstory committed Feb 10, 2012
@@ -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) {
@lorenzo

lorenzo Feb 10, 2012

Owner

EXECUCUTE?

@AD7six

AD7six Feb 10, 2012

Member

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

@lorenzo

lorenzo Feb 10, 2012

Owner

hahahaha

@markstory

markstory Feb 10, 2012

Owner

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

@markstory

markstory Feb 10, 2012

Owner

Un-derped in [9c1fa28]

$prepareOptions += array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL);
return parent::_execute($sql, $params, $prepareOptions);
}
@@ -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']);
+ }
+
}

0 comments on commit 0cfec52

Please sign in to comment.