Skip to content

Commit 6e9b9eb

Browse files
committed
Making a backup of the value binder while quoting identifiers, otherwise
the query will be marked as dirty and all values lost and the end of the query transformation
1 parent 8c8e08c commit 6e9b9eb

File tree

4 files changed

+15
-2
lines changed

4 files changed

+15
-2
lines changed

Cake/Database/Expression/FieldExpression.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
use Cake\Database\ExpressionInterface;
2020
use Cake\Database\ValueBinder;
2121

22+
/**
23+
* Represents a single field name in the database
24+
*
25+
*/
2226
class FieldExpression implements ExpressionInterface {
2327

2428
/**

Cake/Database/Query.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1666,7 +1666,10 @@ protected function _transformQuery() {
16661666
protected function _dirty() {
16671667
$this->_dirty = true;
16681668
$this->_transformedQuery = null;
1669-
$this->valueBinder()->reset();
1669+
1670+
if ($this->_valueBinder) {
1671+
$this->valueBinder()->reset();
1672+
}
16701673
}
16711674

16721675
/**

Cake/Database/SqlDialectTrait.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ protected function _quoteQueryIdentifiers($type, $query) {
193193
return $query;
194194
}
195195

196+
$binder = $query->valueBinder();
197+
$query->valueBinder(false);
196198
$quoter = function($part) use ($query) {
197199
$result = [];
198200
foreach ((array)$query->clause($part) as $alias => $value) {
@@ -218,7 +220,7 @@ protected function _quoteQueryIdentifiers($type, $query) {
218220
$result[$alias] = $value;
219221
}
220222
$query->join($result, [], true);
221-
223+
$query->valueBinder($binder);
222224
return $query;
223225
}
224226

Cake/Test/TestCase/Database/QueryTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@ class QueryTest extends TestCase {
3636
public function setUp() {
3737
parent::setUp();
3838
$this->connection = ConnectionManager::get('test');
39+
$this->autoQuote = $this->connection->driver()->autoQuoting();
3940
}
4041

4142
public function tearDown() {
4243
parent::tearDown();
44+
$this->connection->driver()->autoQuoting($this->autoQuote);
4345
unset($this->connection);
4446
}
4547

@@ -49,6 +51,7 @@ public function tearDown() {
4951
* @return void
5052
*/
5153
public function testSelectFieldsOnly() {
54+
$this->connection->driver()->autoQuoting(false);
5255
$query = new Query($this->connection);
5356
$result = $query->select('1 + 1')->execute();
5457
$this->assertInstanceOf('Cake\Database\StatementInterface', $result);
@@ -70,6 +73,7 @@ public function testSelectFieldsOnly() {
7073
* @return void
7174
*/
7275
public function testSelectClosure() {
76+
$this->connection->driver()->autoQuoting(false);
7377
$query = new Query($this->connection);
7478
$result = $query->select(function($q) use ($query) {
7579
$this->assertSame($query, $q);

0 commit comments

Comments
 (0)