mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-06 23:02:48 +08:00
改进查询条件的参数绑定
This commit is contained in:
@@ -321,21 +321,33 @@ abstract class Builder
|
|||||||
$whereStr .= $key . ' ' . $exp . ' ' . $this->parseClosure($value);
|
$whereStr .= $key . ' ' . $exp . ' ' . $this->parseClosure($value);
|
||||||
} else {
|
} else {
|
||||||
$value = is_array($value) ? $value : explode(',', $value);
|
$value = is_array($value) ? $value : explode(',', $value);
|
||||||
$bind = [];
|
if (array_key_exists($field, $binds)) {
|
||||||
$array = [];
|
$bind = [];
|
||||||
foreach ($value as $k => $v) {
|
$array = [];
|
||||||
$bind[$field . '_in_' . $k] = [$v, $bindType];
|
foreach ($value as $k => $v) {
|
||||||
$array[] = ':' . $field . '_in_' . $k;
|
$bindName = str_replace('.', '_', $field) . '_in_' . $k;
|
||||||
|
$bind[$bindName] = [$v, $bindType];
|
||||||
|
$array[] = ':' . $bindName;
|
||||||
|
}
|
||||||
|
$this->query->bind($bind);
|
||||||
|
$zone = implode(',', $array);
|
||||||
|
} else {
|
||||||
|
$zone = implode(',', $this->parseValue($value, $field));
|
||||||
}
|
}
|
||||||
$this->query->bind($bind);
|
$whereStr .= $key . ' ' . $exp . ' (' . $zone . ')';
|
||||||
$whereStr .= $key . ' ' . $exp . ' (' . implode(',', $array) . ')';
|
|
||||||
}
|
}
|
||||||
} elseif (in_array($exp, ['NOT BETWEEN', 'BETWEEN'])) {
|
} elseif (in_array($exp, ['NOT BETWEEN', 'BETWEEN'])) {
|
||||||
// BETWEEN 查询
|
// BETWEEN 查询
|
||||||
$data = is_array($value) ? $value : explode(',', $value);
|
$data = is_array($value) ? $value : explode(',', $value);
|
||||||
$bind = [$field . '_between_1' => [$data[0], $bindType], $field . '_between_2' => [$data[1], $bindType]];
|
if (array_key_exists($field, $binds)) {
|
||||||
$this->query->bind($bind);
|
$field = str_replace('.', '_', $field);
|
||||||
$whereStr .= $key . ' ' . $exp . ' :' . $field . '_between_1' . ' AND :' . $field . '_between_2';
|
$bind = [$field . '_between_1' => [$data[0], $bindType], $field . '_between_2' => [$data[1], $bindType]];
|
||||||
|
$this->query->bind($bind);
|
||||||
|
$between = ' :' . $field . '_between_1' . ' AND :' . $field . '_between_2';
|
||||||
|
} else {
|
||||||
|
$between = $this->parseValue($data[0], $field) . ' AND ' . $this->parseValue($data[1], $field);
|
||||||
|
}
|
||||||
|
$whereStr .= $key . ' ' . $exp . ' ' . $between;
|
||||||
} elseif (in_array($exp, ['NOT EXISTS', 'EXISTS'])) {
|
} elseif (in_array($exp, ['NOT EXISTS', 'EXISTS'])) {
|
||||||
// EXISTS 查询
|
// EXISTS 查询
|
||||||
if ($value instanceof \Closure) {
|
if ($value instanceof \Closure) {
|
||||||
@@ -349,7 +361,8 @@ abstract class Builder
|
|||||||
if (is_string($value)) {
|
if (is_string($value)) {
|
||||||
$value = explode(',', $value);
|
$value = explode(',', $value);
|
||||||
}
|
}
|
||||||
$whereStr .= $key . ' ' . substr($exp, 0, -4) . $this->parseDateTime($value[0], $field, $options, $field . '_between_1', $bindType) . ' AND ' . $this->parseDateTime($value[1], $field, $options, $field . '_between_2', $bindType);
|
|
||||||
|
$whereStr .= $key . ' ' . substr($exp, 0, -4) . $this->parseDateTime($value[0], $field, $options, str_replace('.', '_', $field) . '_between_1', $bindType) . ' AND ' . $this->parseDateTime($value[1], $field, $options, str_replace('.', '_', $field) . '_between_2', $bindType);
|
||||||
}
|
}
|
||||||
return $whereStr;
|
return $whereStr;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user