改进where方法的原生sql条件 并且支持参数绑定

This commit is contained in:
thinkphp
2016-04-28 14:19:55 +08:00
parent 43fb7cc445
commit 810a88a48e
2 changed files with 8 additions and 2 deletions

View File

@@ -311,7 +311,7 @@ abstract class Builder
$whereStr .= $key . ' ' . $exp . ' ' . $this->parseValue($value); $whereStr .= $key . ' ' . $exp . ' ' . $this->parseValue($value);
} elseif ('EXP' == $exp) { } elseif ('EXP' == $exp) {
// 表达式查询 // 表达式查询
$whereStr .= $key . ' ' . $value; $whereStr .= '( ' . $key . ' ' . $value . ' )';
} elseif (in_array($exp, ['NOT NULL', 'NULL'])) { } elseif (in_array($exp, ['NOT NULL', 'NULL'])) {
// NULL 查询 // NULL 查询
$whereStr .= $key . ' IS ' . $exp; $whereStr .= $key . ' IS ' . $exp;

View File

@@ -491,7 +491,13 @@ class Query
if (is_string($field) && !empty($this->options['via'])) { if (is_string($field) && !empty($this->options['via'])) {
$field = $this->options['via'] . '.' . $field; $field = $this->options['via'] . '.' . $field;
} }
if (is_null($op) && is_null($condition)) { if (is_string($field) && strpos($field, ' ')) {
$where[] = ['exp', $field];
if (is_array($op)) {
// 参数绑定
$this->bind($op);
}
} elseif (is_null($op) && is_null($condition)) {
if (is_array($field)) { if (is_array($field)) {
// 数组批量查询 // 数组批量查询
$where = $field; $where = $field;