变更
This commit is contained in:
+5
-17
@@ -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,15 +886,8 @@ 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;
|
|
||||||
if (is_numeric($key)) {
|
|
||||||
[$column, $opera, $value] = $this->opera(...$value);
|
|
||||||
|
|
||||||
$this->where[] = $this->sprintf($column, $value, $opera);
|
|
||||||
} else {
|
|
||||||
$this->where[] = $this->sprintf($key, $value);
|
$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'";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user