diff --git a/library/think/db/Builder.php b/library/think/db/Builder.php index d951c232..fb8ef195 100644 --- a/library/think/db/Builder.php +++ b/library/think/db/Builder.php @@ -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%'], [ diff --git a/library/think/db/Query.php b/library/think/db/Query.php index 35cad2ef..205f1f33 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -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; }