Skip to content

Commit

Permalink
Merge pull request #5741 from cakephp/3.0-fix-query-regression
Browse files Browse the repository at this point in the history
3.0 fix query regression
  • Loading branch information
markstory committed Jan 25, 2015
2 parents 75ac510 + 8b153b4 commit 63e5b9e
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/Database/Driver/Mysql.php
Expand Up @@ -112,9 +112,10 @@ public function enabled()
public function prepare($query)
{
$this->connect();
$statement = $this->_connection->prepare((string)$query);
$isObject = $query instanceof Query;
$statement = $this->_connection->prepare($isObject ? $query->sql() : $query);
$result = new MysqlStatement($statement, $this);
if ($query instanceof Query && $query->bufferResults() === false) {
if ($isObject && $query->bufferResults() === false) {
$result->bufferResults(false);
}
return $result;
Expand Down
4 changes: 3 additions & 1 deletion src/Database/Driver/PDODriverTrait.php
Expand Up @@ -14,6 +14,7 @@
*/
namespace Cake\Database\Driver;

use Cake\Database\Query;
use Cake\Database\Statement\PDOStatement;
use PDO;

Expand Down Expand Up @@ -84,7 +85,8 @@ public function disconnect()
public function prepare($query)
{
$this->connect();
$statement = $this->_connection->prepare((string)$query);
$isObject = $query instanceof Query;
$statement = $this->_connection->prepare($isObject ? $query->sql() : $query);
return new PDOStatement($statement, $this);
}

Expand Down
5 changes: 3 additions & 2 deletions src/Database/Driver/Sqlite.php
Expand Up @@ -87,9 +87,10 @@ public function enabled()
public function prepare($query)
{
$this->connect();
$statement = $this->_connection->prepare((string)$query);
$isObject = $query instanceof Query;
$statement = $this->_connection->prepare($isObject ? $query->sql() : $query);
$result = new SqliteStatement(new PDOStatement($statement, $this), $this);
if ($query instanceof Query && $query->bufferResults() === false) {
if ($isObject && $query->bufferResults() === false) {
$result->bufferResults(false);
}
return $result;
Expand Down
5 changes: 3 additions & 2 deletions src/Database/Driver/Sqlserver.php
Expand Up @@ -101,10 +101,11 @@ public function prepare($query)
{
$this->connect();
$options = [PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL];
if ($query instanceof Query && $query->bufferResults() === false) {
$isObject = $query instanceof Query;
if ($isObject && $query->bufferResults() === false) {
$options = [];
}
$statement = $this->_connection->prepare((string)$query, $options);
$statement = $this->_connection->prepare($isObject ? $query->sql() : $query);
return new SqlserverStatement($statement, $this);
}
}
14 changes: 14 additions & 0 deletions tests/TestCase/ORM/QueryRegressionTest.php
Expand Up @@ -696,4 +696,18 @@ public function testFindMatchingOverwrite2()

$this->assertNotNull($result->article->author);
}


/**
* Tests that trying to contain an inexistent association
* throws an exception and not a fatal error.
*
* @expectedException InvalidArgumentException
* @return void
*/
public function testQueryNotFatalError()
{
$comments = TableRegistry::get('Comments');
$comments->find()->contain('Deprs')->all();
}
}

0 comments on commit 63e5b9e

Please sign in to comment.