This commit is contained in:
2023-08-14 14:02:16 +08:00
parent 63ddc36958
commit d42d284f62
4 changed files with 43 additions and 28 deletions
+1 -1
View File
@@ -226,7 +226,7 @@ class Command extends Component
*/ */
private function error(Throwable $throwable): bool private function error(Throwable $throwable): bool
{ {
return trigger_print_error($this->sql . '.' . json_encode($this->params, JSON_UNESCAPED_UNICODE) . PHP_EOL . jTraceEx($throwable), 'mysql'); return trigger_print_error($this->sql . '.' . json_encode($this->params, JSON_UNESCAPED_UNICODE) . PHP_EOL . throwable($throwable), 'mysql');
} }
+4 -4
View File
@@ -169,8 +169,8 @@ class SqlBuilder extends Component
$keys = []; $keys = [];
foreach ($attributes as $key => $value) { foreach ($attributes as $key => $value) {
if ($isInsert === true) { if ($isInsert === true) {
$keys[] = ':save' . $key . $order; $keys[] = '?';
$this->query->bindParam(':save' . $key . $order, $value); $this->query->pushParam($value);
} else { } else {
$keys = $this->resolveParams($key, $value, $order, $keys); $keys = $this->resolveParams($key, $value, $order, $keys);
} }
@@ -195,8 +195,8 @@ class SqlBuilder extends Component
str_starts_with($value, '- '))) { str_starts_with($value, '- '))) {
$keys[] = $key . '=' . $key . ' ' . $value; $keys[] = $key . '=' . $key . ' ' . $value;
} else { } else {
$this->query->bindParam(':update' . $key . $order, $value); $this->query->pushParam($value);
$keys[] = $key . '=:update' . $key . $order; $keys[] = $key . '= ?';
} }
return $keys; return $keys;
} }
+4 -4
View File
@@ -133,8 +133,8 @@ trait Builder
private function resolveCondition($field, $condition, $_tmp): string private function resolveCondition($field, $condition, $_tmp): string
{ {
if (is_string($field)) { if (is_string($field)) {
$this->query->bindParam(':where' . $field, $condition); $this->query->pushParam($condition);
return $field . ' = ' . ':where' . $field; return $field . ' = ?';
} else if (is_string($condition)) { } else if (is_string($condition)) {
return $condition; return $condition;
} else { } else {
@@ -191,8 +191,8 @@ trait Builder
{ {
$_array = []; $_array = [];
foreach ($condition as $key => $value) { foreach ($condition as $key => $value) {
$this->query->bindParam(':hash' . $key, $value); $this->query->pushParam($value);
$_array[] = $key . '=:hash' . $key; $_array[] = $key . '= ?';
} }
return $_array; return $_array;
} }
+34 -19
View File
@@ -472,8 +472,8 @@ trait QueryTrait
*/ */
public function whereLike(string $column, string $value): static public function whereLike(string $column, string $value): static
{ {
$this->bindParam(':LIKE' . $column, $value); $this->pushParam($value);
$this->where[] = $column . ' LIKE \':LIKE' . $column . '\''; $this->where[] = $column . ' LIKE \'%?%\'';
return $this; return $this;
} }
@@ -484,8 +484,8 @@ trait QueryTrait
*/ */
public function whereLeftLike(string $column, string $value): static public function whereLeftLike(string $column, string $value): static
{ {
$this->bindParam(':LLike' . $column, $value); $this->pushParam($value);
$this->where[] = $column . ' LLike \'%:LLike' . $column . '\''; $this->where[] = $column . ' LLike \'%?\'';
return $this; return $this;
} }
@@ -496,8 +496,8 @@ trait QueryTrait
*/ */
public function whereRightLike(string $column, string $value): static public function whereRightLike(string $column, string $value): static
{ {
$this->bindParam(':RLike' . $column, $value); $this->pushParam($value);
$this->where[] = $column . ' RLike \':RLike' . $column . '%\''; $this->where[] = $column . ' RLike \'?%\'';
return $this; return $this;
} }
@@ -509,8 +509,8 @@ trait QueryTrait
*/ */
public function whereNotLike(string $column, string $value): static public function whereNotLike(string $column, string $value): static
{ {
$this->bindParam(':LIKE' . $column, $value); $this->pushParam($value);
$this->where[] = $column . ' NOT LIKE \'%:LIKE' . $column . '%\''; $this->where[] = $column . ' NOT LIKE \'%?%\'';
return $this; return $this;
} }
@@ -586,9 +586,9 @@ trait QueryTrait
return $this; return $this;
} }
$this->bindParam(':between_start' . $column, $start); $this->pushParam($start);
$this->bindParam(':between_end' . $column, $end); $this->pushParam($end);
$this->where[] = $column . ' BETWEEN :not_between_start' . $column . ' AND :not_between_end' . $column; $this->where[] = $column . ' BETWEEN ? AND ?';
return $this; return $this;
} }
@@ -605,9 +605,9 @@ trait QueryTrait
return $this; return $this;
} }
$this->bindParam(':not_between_start' . $column, $start); $this->pushParam($start);
$this->bindParam(':not_between_end' . $column, $end); $this->pushParam($end);
$this->where[] = $column . ' NOT BETWEEN :not_between_start' . $column . ' AND :not_between_end' . $column; $this->where[] = $column . ' NOT BETWEEN ? AND ?';
return $this; return $this;
} }
@@ -622,7 +622,9 @@ trait QueryTrait
if ($params === null) { if ($params === null) {
return $this; return $this;
} }
$this->attributes = array_merge($this->attributes, $params); foreach ($params as $param) {
$this->attributes[] = $param;
}
return $this; return $this;
} }
@@ -640,6 +642,19 @@ trait QueryTrait
return $this; return $this;
} }
/**
* @param mixed $value
* @return $this
*/
public function pushParam(mixed $value): static
{
if (is_string($value)) {
$value = addslashes($value);
}
$this->attributes[] = $value;
return $this;
}
/** /**
* @param array $column * @param array $column
* @return $this * @return $this
@@ -658,8 +673,8 @@ trait QueryTrait
*/ */
public function whereMath(string $column, string $opera, mixed $value): static public function whereMath(string $column, string $opera, mixed $value): static
{ {
$this->bindParam(':' . $column, $value); $this->pushParam($value);
$this->where[] = $column . ' ' . $opera . ':' . $column; $this->where[] = $column . ' ' . $opera . ' ?';
return $this; return $this;
} }
@@ -772,8 +787,8 @@ trait QueryTrait
*/ */
private function sprintf($column, $value, string $opera = '='): string private function sprintf($column, $value, string $opera = '='): string
{ {
$this->bindParam(':' . $column, $value); $this->pushParam($value);
return $column . ' ' . $opera . ' :' . $column; return $column . ' ' . $opera . ' ?';
} }