mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-23 04:00:23 +08:00
added support for yii\db\Expression to querybuilder BETWEEN and LIKE
fixes #6164
This commit is contained in:
@ -31,6 +31,7 @@ Yii Framework 2 Change Log
|
||||
- Bug #6107: `yii message` was emptying existing translations in .po in case of multiple categories (samdark)
|
||||
- Bug #6112: `yii message` was incorrectly writing not yet translated strings in .po in case of multiple categories (samdark)
|
||||
- Bug #6172: `yii\rbac\DbManager` should properly quote table and column names (qiangxue)
|
||||
- Bug #6164: Added missing support for `yii\db\Exression` QueryBuilder `BETWEEN` and `LIKE` conditions (cebe)
|
||||
- Bug: Gii console command help information does not contain global options (qiangxue)
|
||||
- Bug: `yii\web\UrlRule` was unable to create URLs for rules containing unicode characters (samdark)
|
||||
- Enh #4181: Added `yii\bootstrap\Modal::$headerOptions` and `yii\bootstrap\Modal::$footerOptions` (tuxoff, samdark)
|
||||
|
@ -1020,10 +1020,24 @@ class QueryBuilder extends \yii\base\Object
|
||||
if (strpos($column, '(') === false) {
|
||||
$column = $this->db->quoteColumnName($column);
|
||||
}
|
||||
$phName1 = self::PARAM_PREFIX . count($params);
|
||||
$params[$phName1] = $value1;
|
||||
$phName2 = self::PARAM_PREFIX . count($params);
|
||||
$params[$phName2] = $value2;
|
||||
if ($value1 instanceof Expression) {
|
||||
foreach ($value1->params as $n => $v) {
|
||||
$params[$n] = $v;
|
||||
}
|
||||
$phName1 = $value1->expression;
|
||||
} else {
|
||||
$phName1 = self::PARAM_PREFIX . count($params);
|
||||
$params[$phName1] = $value1;
|
||||
}
|
||||
if ($value2 instanceof Expression) {
|
||||
foreach ($value2->params as $n => $v) {
|
||||
$params[$n] = $v;
|
||||
}
|
||||
$phName2 = $value2->expression;
|
||||
} else {
|
||||
$phName2 = self::PARAM_PREFIX . count($params);
|
||||
$params[$phName2] = $value2;
|
||||
}
|
||||
|
||||
return "$column $operator $phName1 AND $phName2";
|
||||
}
|
||||
@ -1181,7 +1195,9 @@ class QueryBuilder extends \yii\base\Object
|
||||
|
||||
list($column, $values) = $operands;
|
||||
|
||||
$values = (array) $values;
|
||||
if (!is_array($values)) {
|
||||
$values = [$values];
|
||||
}
|
||||
|
||||
if (empty($values)) {
|
||||
return $not ? '' : '0=1';
|
||||
@ -1193,8 +1209,15 @@ class QueryBuilder extends \yii\base\Object
|
||||
|
||||
$parts = [];
|
||||
foreach ($values as $value) {
|
||||
$phName = self::PARAM_PREFIX . count($params);
|
||||
$params[$phName] = empty($escape) ? $value : ('%' . strtr($value, $escape) . '%');
|
||||
if ($value instanceof Expression) {
|
||||
foreach ($value->params as $n => $v) {
|
||||
$params[$n] = $v;
|
||||
}
|
||||
$phName = $value->expression;
|
||||
} else {
|
||||
$phName = self::PARAM_PREFIX . count($params);
|
||||
$params[$phName] = empty($escape) ? $value : ('%' . strtr($value, $escape) . '%');
|
||||
}
|
||||
$parts[] = "$column $operator $phName";
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user