Skip to content

Commit

Permalink
Making a backup of the value binder while quoting identifiers, otherwise
Browse files Browse the repository at this point in the history
the query will be marked as dirty and all values lost and the end of the
query transformation
  • Loading branch information
lorenzo committed Nov 6, 2013
1 parent 8c8e08c commit 6e9b9eb
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
4 changes: 4 additions & 0 deletions Cake/Database/Expression/FieldExpression.php
Expand Up @@ -19,6 +19,10 @@
use Cake\Database\ExpressionInterface;
use Cake\Database\ValueBinder;

/**
* Represents a single field name in the database
*
*/
class FieldExpression implements ExpressionInterface {

/**
Expand Down
5 changes: 4 additions & 1 deletion Cake/Database/Query.php
Expand Up @@ -1666,7 +1666,10 @@ protected function _transformQuery() {
protected function _dirty() {
$this->_dirty = true;
$this->_transformedQuery = null;
$this->valueBinder()->reset();

if ($this->_valueBinder) {
$this->valueBinder()->reset();
}
}

/**
Expand Down
4 changes: 3 additions & 1 deletion Cake/Database/SqlDialectTrait.php
Expand Up @@ -193,6 +193,8 @@ protected function _quoteQueryIdentifiers($type, $query) {
return $query;
}

$binder = $query->valueBinder();
$query->valueBinder(false);
$quoter = function($part) use ($query) {
$result = [];
foreach ((array)$query->clause($part) as $alias => $value) {
Expand All @@ -218,7 +220,7 @@ protected function _quoteQueryIdentifiers($type, $query) {
$result[$alias] = $value;
}
$query->join($result, [], true);

$query->valueBinder($binder);
return $query;
}

Expand Down
4 changes: 4 additions & 0 deletions Cake/Test/TestCase/Database/QueryTest.php
Expand Up @@ -36,10 +36,12 @@ class QueryTest extends TestCase {
public function setUp() {
parent::setUp();
$this->connection = ConnectionManager::get('test');
$this->autoQuote = $this->connection->driver()->autoQuoting();
}

public function tearDown() {
parent::tearDown();
$this->connection->driver()->autoQuoting($this->autoQuote);
unset($this->connection);
}

Expand All @@ -49,6 +51,7 @@ public function tearDown() {
* @return void
*/
public function testSelectFieldsOnly() {
$this->connection->driver()->autoQuoting(false);
$query = new Query($this->connection);
$result = $query->select('1 + 1')->execute();
$this->assertInstanceOf('Cake\Database\StatementInterface', $result);
Expand All @@ -70,6 +73,7 @@ public function testSelectFieldsOnly() {
* @return void
*/
public function testSelectClosure() {
$this->connection->driver()->autoQuoting(false);
$query = new Query($this->connection);
$result = $query->select(function($q) use ($query) {
$this->assertSame($query, $q);
Expand Down

0 comments on commit 6e9b9eb

Please sign in to comment.