Skip to content

Commit

Permalink
修正自动参数绑定
Browse files Browse the repository at this point in the history
  • Loading branch information
liu21st committed Mar 6, 2023
1 parent 4457c03 commit ce9f1d2
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/db/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ protected function parseData(Query $query, array $data = [], array $fields = [],
}
} elseif (is_scalar($val)) {
// 过滤非标量数据
if (!$query->isAutoBind() && PDO::PARAM_STR == $bind[$key]) {
$val = '\'' . $val . '\'';
}
$result[$item] = !$query->isAutoBind() ? $val : $this->parseDataBind($query, $key, $val, $bind);
}
}
Expand Down Expand Up @@ -796,18 +799,19 @@ protected function parseIn(Query $query, string $key, string $exp, $value, $fiel
if ($query->isAutoBind()) {
$array = [];
foreach ($value as $v) {
$name = $query->bindValue($v, $bindType);
$array[] = ':' . $name;
$name = $query->bindValue($v, $bindType);
$array[] = ':' . $name;
}
$value = implode(',', $array);
} elseif (PDO::PARAM_STR == $bindType) {
$value = '\'' . implode('\',\'', $value) . '\'';
} else {
$array = $value;
$value = implode(',', $value);
}

if (count($array) == 1) {
return $key . ('IN' == $exp ? ' = ' : ' <> ') . $array[0];
if (!str_contains($value, ',')) {
return $key . ('IN' == $exp ? ' = ' : ' <> ') . $value;
}

$value = implode(',', $array);
}

return $key . ' ' . $exp . ' (' . $value . ')';
Expand Down

0 comments on commit ce9f1d2

Please sign in to comment.