改进insertAll方法

This commit is contained in:
thinkphp
2018-04-14 10:12:25 +08:00
parent 94384d1aba
commit 137ccfc458
2 changed files with 9 additions and 9 deletions

View File

@@ -391,7 +391,7 @@ abstract class Builder
}
} elseif ('EXP' == $exp) {
// 表达式查询
$whereStr .= '( ' . $key . ' ' . $value . ' )';
$whereStr .= '( ' . $key . ' ' . ($value instanceof Expression ? $value->getValue() : $value) . ' )';
} elseif (in_array($exp, ['NOT NULL', 'NULL'])) {
// NULL 查询
$whereStr .= $key . ' IS ' . $exp;
@@ -673,11 +673,7 @@ abstract class Builder
return '';
}
if (is_array($index)) {
$index = join(",", $index);
}
return sprintf(" FORCE INDEX ( %s ) ", $index);
return sprintf(" FORCE INDEX ( %s ) ", is_array($index) ? implode(',', $index) : $index);
}
/**
@@ -795,10 +791,14 @@ abstract class Builder
$values[] = 'SELECT ' . implode(',', $value);
if (!isset($insertFields)) {
$insertFields = array_map([$this, 'parseKey'], array_keys($data));
$insertFields = array_keys($data);
}
}
foreach ($insertFields as $field) {
$fields[] = $this->parseKey($query, $field, true);
}
return str_replace(
['%INSERT%', '%TABLE%', '%FIELD%', '%DATA%', '%COMMENT%'],
[

View File

@@ -883,7 +883,7 @@ class Query
*/
public function exp($field, $value)
{
$this->data($field, ['exp', $value]);
$this->data($field, $this->raw($value));
return $this;
}
@@ -1188,7 +1188,7 @@ class Query
*/
public function whereExp($field, $condition, $logic = 'AND')
{
$this->parseWhereExp($logic, $field, 'exp', $condition, [], true);
$this->parseWhereExp($logic, $field, 'exp', $this->raw($condition), [], true);
return $this;
}