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

This comment has been minimized.

Copy link
@lorenzo

lorenzo Feb 10, 2012

Member

EXECUCUTE?

This comment has been minimized.

Copy link
@AD7six

AD7six Feb 10, 2012

Member

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

This comment has been minimized.

Copy link
@lorenzo

lorenzo Feb 10, 2012

Member

hahahaha

This comment has been minimized.

Copy link
@markstory

markstory Feb 10, 2012

Author Member

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

This comment has been minimized.

Copy link
@markstory

markstory Feb 10, 2012

Author Member

Un-derped in [9c1fa28]

This comment has been minimized.

Copy link
@tPl0ch
$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.
You can’t perform that action at this time.