This commit is contained in:
2023-04-07 18:00:25 +08:00
parent 66ecf2585a
commit 6d122c4ae1
+6 -18
View File
@@ -794,21 +794,17 @@ trait QueryTrait
} }
/** /**
* @param Closure|array|string $column * @param array|string $column
* @param string $opera * @param string $opera
* @param null $value * @param null $value
* @return $this * @return $this
* @throws * @throws
*/ */
public function where(Closure|array|string $column, string $opera = '=', $value = null): static public function where(array|string $column, string $opera = '=', $value = null): static
{ {
if (is_array($column)) { if (is_array($column)) {
return $this->addArray($column); return $this->addArray($column);
} }
if ($column instanceof Closure) {
$this->where[] = $this->makeClosureFunction($column);
return $this;
}
if (is_string($column)) { if (is_string($column)) {
$this->where[] = $column; $this->where[] = $column;
} else { } else {
@@ -890,14 +886,7 @@ trait QueryTrait
private function addArray(array $array): static private function addArray(array $array): static
{ {
foreach ($array as $key => $value) { foreach ($array as $key => $value) {
if (is_null($value)) continue; $this->where[] = $this->sprintf($key, $value);
if (is_numeric($key)) {
[$column, $opera, $value] = $this->opera(...$value);
$this->where[] = $this->sprintf($column, $value, $opera);
} else {
$this->where[] = $this->sprintf($key, $value);
}
} }
return $this; return $this;
} }
@@ -911,11 +900,10 @@ trait QueryTrait
*/ */
private function sprintf($column, $value, string $opera = '='): string private function sprintf($column, $value, string $opera = '='): string
{ {
if (is_numeric($value)) { if (is_string($value)) {
return "$column $opera $value"; $value = addslashes($value);
} }
$value = trim($value, '\'"'); return $column . ' ' . $opera . ' \'' . $value . '\'';
return "$column $opera '$value'";
} }