mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-10 00:22:48 +08:00
优化Builder类的parseWhere方法
This commit is contained in:
@@ -224,23 +224,15 @@ abstract class Builder
|
||||
}
|
||||
|
||||
$whereStr = '';
|
||||
// 获取字段信息
|
||||
$fields = $this->query->getTableFields($options);
|
||||
$binds = $this->query->getFieldsBind($options);
|
||||
foreach ($where as $key => $val) {
|
||||
$str = [];
|
||||
foreach ($val as $field => $value) {
|
||||
if ($fields && in_array($field, $fields, true) && is_scalar($value) && !$this->query->isBind($field)) {
|
||||
$this->query->bind($field, $value, isset($binds[$field]) ? $binds[$field] : PDO::PARAM_STR);
|
||||
$value = ':' . $field;
|
||||
}
|
||||
if ($value instanceof \Closure) {
|
||||
// 使用闭包查询
|
||||
$query = new Query($this->connection);
|
||||
call_user_func_array($value, [ & $query]);
|
||||
$str[] = ' ' . $key . ' ( ' . $this->buildWhere($query->getOptions('where'), $options) . ' )';
|
||||
} else {
|
||||
if (strpos($field, '|')) {
|
||||
} elseif (strpos($field, '|')) {
|
||||
// 不同字段使用相同查询条件(OR)
|
||||
$array = explode('|', $field);
|
||||
$item = [];
|
||||
@@ -262,7 +254,6 @@ abstract class Builder
|
||||
$str[] = ' ' . $key . ' ' . $this->parseWhereItem($field, $value, $key, $options);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$whereStr .= empty($whereStr) ? substr(implode(' ', $str), strlen($key) + 1) : implode(' ', $str);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user