From 69cf9de56b1df8456c8f2af26268537435e5d96c Mon Sep 17 00:00:00 2001 From: Alexander Kartavenko Date: Thu, 1 Aug 2019 13:20:37 +0300 Subject: [PATCH] Fix #17473: Fixed `SimpleConditionBuilder::build()` when column is not a string --- framework/CHANGELOG.md | 1 + framework/db/conditions/SimpleConditionBuilder.php | 3 +-- tests/framework/db/QueryBuilderTest.php | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index fac12b0841..67a5f01f69 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -4,6 +4,7 @@ Yii Framework 2 Change Log 2.0.25 under development ------------------------ +- Bug #17473: Fixed `SimpleConditionBuilder::build()` when column is not a string (alexkart) - Bug #17486: Fixed error when using `batch()` without `$db` parameter with MSSQL (alexkart) diff --git a/framework/db/conditions/SimpleConditionBuilder.php b/framework/db/conditions/SimpleConditionBuilder.php index 512a164dc7..ab7633210a 100644 --- a/framework/db/conditions/SimpleConditionBuilder.php +++ b/framework/db/conditions/SimpleConditionBuilder.php @@ -10,7 +10,6 @@ namespace yii\db\conditions; use yii\db\ExpressionBuilderInterface; use yii\db\ExpressionBuilderTrait; use yii\db\ExpressionInterface; -use yii\db\Query; /** * Class NotConditionBuilder builds objects of [[SimpleCondition]] @@ -37,7 +36,7 @@ class SimpleConditionBuilder implements ExpressionBuilderInterface $column = $expression->getColumn(); $value = $expression->getValue(); - if (strpos($column, '(') === false) { + if (is_string($column) && strpos($column, '(') === false) { $column = $this->queryBuilder->db->quoteColumnName($column); } diff --git a/tests/framework/db/QueryBuilderTest.php b/tests/framework/db/QueryBuilderTest.php index 38a67c8c2c..44b49e0ac2 100644 --- a/tests/framework/db/QueryBuilderTest.php +++ b/tests/framework/db/QueryBuilderTest.php @@ -1201,6 +1201,7 @@ abstract class QueryBuilderTest extends DatabaseTestCase [['>=', 'date', new Expression('DATE_SUB(NOW(), INTERVAL 1 MONTH)')], '[[date]] >= DATE_SUB(NOW(), INTERVAL 1 MONTH)', []], [['>=', 'date', new Expression('DATE_SUB(NOW(), INTERVAL :month MONTH)', [':month' => 2])], '[[date]] >= DATE_SUB(NOW(), INTERVAL :month MONTH)', [':month' => 2]], [['=', 'date', (new Query())->select('max(date)')->from('test')->where(['id' => 5])], '[[date]] = (SELECT max(date) FROM [[test]] WHERE [[id]]=:qp0)', [':qp0' => 5]], + [['=', new Expression('date'), '2019-08-01'], 'date = :qp0', [':qp0' => '2019-08-01']], // operand1 is Expression // hash condition [['a' => 1, 'b' => 2], '([[a]]=:qp0) AND ([[b]]=:qp1)', [':qp0' => 1, ':qp1' => 2]],