Skip to content

Commit

Permalink
Allow SqlServer to execute procs correctly.
Browse files Browse the repository at this point in the history
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 0cfec52
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Cake/Model/Datasource/Database/Sqlserver.php
Expand Up @@ -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

tPl0ch Feb 10, 2012

lol

$prepareOptions += array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL);
return parent::_execute($sql, $params, $prepareOptions);
}
Expand Down
27 changes: 27 additions & 0 deletions lib/Cake/Test/Case/Model/Datasource/Database/SqlserverTest.php
Expand Up @@ -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.