From 2bd14098f96c306ae90f3b70a1c2aa052ef1aa22 Mon Sep 17 00:00:00 2001 From: CedricYii Date: Fri, 11 Mar 2016 15:19:05 +0100 Subject: [PATCH] Fix Expression parameter binding in 'And' clause --- framework/db/QueryBuilder.php | 5 +++++ tests/framework/db/QueryBuilderTest.php | 1 + 2 files changed, 6 insertions(+) diff --git a/framework/db/QueryBuilder.php b/framework/db/QueryBuilder.php index 77d8d35..84ef8af 100644 --- a/framework/db/QueryBuilder.php +++ b/framework/db/QueryBuilder.php @@ -1006,6 +1006,11 @@ class QueryBuilder extends \yii\base\Object if (is_array($operand)) { $operand = $this->buildCondition($operand, $params); } + if ($operand instanceof Expression) { + foreach ($operand->params as $n => $v) { + $params[$n] = $v; + } + } if ($operand !== '') { $parts[] = $operand; } diff --git a/tests/framework/db/QueryBuilderTest.php b/tests/framework/db/QueryBuilderTest.php index e0bc965..331620e 100644 --- a/tests/framework/db/QueryBuilderTest.php +++ b/tests/framework/db/QueryBuilderTest.php @@ -216,6 +216,7 @@ class QueryBuilderTest extends DatabaseTestCase // and [ ['and', 'id=1', 'id=2'], '(id=1) AND (id=2)', [] ], [ ['and', 'type=1', ['or', 'id=1', 'id=2']], '(type=1) AND ((id=1) OR (id=2))', [] ], + [ ['and', 'id=1', new Expression('id=:param1', [':param1' => 2])], '(id=1) AND (id=:param1)', [':param1' => 2] ], // or [ ['or', 'id=1', 'id=2'], '(id=1) OR (id=2)', [] ],