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
{
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 = [];
foreach ($attributes as $key => $value) {
if ($isInsert === true) {
$keys[] = ':save' . $key . $order;
$this->query->bindParam(':save' . $key . $order, $value);
$keys[] = '?';
$this->query->pushParam($value);
} else {
$keys = $this->resolveParams($key, $value, $order, $keys);
}
@@ -195,8 +195,8 @@ class SqlBuilder extends Component
str_starts_with($value, '- '))) {
$keys[] = $key . '=' . $key . ' ' . $value;
} else {
$this->query->bindParam(':update' . $key . $order, $value);
$keys[] = $key . '=:update' . $key . $order;
$this->query->pushParam($value);
$keys[] = $key . '= ?';
}
return $keys;
}
+4 -4
View File
@@ -133,8 +133,8 @@ trait Builder
private function resolveCondition($field, $condition, $_tmp): string
{
if (is_string($field)) {
$this->query->bindParam(':where' . $field, $condition);
return $field . ' = ' . ':where' . $field;
$this->query->pushParam($condition);
return $field . ' = ?';
} else if (is_string($condition)) {
return $condition;
} else {
@@ -191,8 +191,8 @@ trait Builder
{
$_array = [];
foreach ($condition as $key => $value) {
$this->query->bindParam(':hash' . $key, $value);
$_array[] = $key . '=:hash' . $key;
$this->query->pushParam($value);
$_array[] = $key . '= ?';
}
return $_array;
}
+34 -19
View File
@@ -472,8 +472,8 @@ trait QueryTrait
*/
public function whereLike(string $column, string $value): static
{
$this->bindParam(':LIKE' . $column, $value);
$this->where[] = $column . ' LIKE \':LIKE' . $column . '\'';
$this->pushParam($value);
$this->where[] = $column . ' LIKE \'%?%\'';
return $this;
}
@@ -484,8 +484,8 @@ trait QueryTrait
*/
public function whereLeftLike(string $column, string $value): static
{
$this->bindParam(':LLike' . $column, $value);
$this->where[] = $column . ' LLike \'%:LLike' . $column . '\'';
$this->pushParam($value);
$this->where[] = $column . ' LLike \'%?\'';
return $this;
}
@@ -496,8 +496,8 @@ trait QueryTrait
*/
public function whereRightLike(string $column, string $value): static
{
$this->bindParam(':RLike' . $column, $value);
$this->where[] = $column . ' RLike \':RLike' . $column . '%\'';
$this->pushParam($value);
$this->where[] = $column . ' RLike \'?%\'';
return $this;
}
@@ -509,8 +509,8 @@ trait QueryTrait
*/
public function whereNotLike(string $column, string $value): static
{
$this->bindParam(':LIKE' . $column, $value);
$this->where[] = $column . ' NOT LIKE \'%:LIKE' . $column . '%\'';
$this->pushParam($value);
$this->where[] = $column . ' NOT LIKE \'%?%\'';
return $this;
}
@@ -586,9 +586,9 @@ trait QueryTrait
return $this;
}
$this->bindParam(':between_start' . $column, $start);
$this->bindParam(':between_end' . $column, $end);
$this->where[] = $column . ' BETWEEN :not_between_start' . $column . ' AND :not_between_end' . $column;
$this->pushParam($start);
$this->pushParam($end);
$this->where[] = $column . ' BETWEEN ? AND ?';
return $this;
}
@@ -605,9 +605,9 @@ trait QueryTrait
return $this;
}
$this->bindParam(':not_between_start' . $column, $start);
$this->bindParam(':not_between_end' . $column, $end);
$this->where[] = $column . ' NOT BETWEEN :not_between_start' . $column . ' AND :not_between_end' . $column;
$this->pushParam($start);
$this->pushParam($end);
$this->where[] = $column . ' NOT BETWEEN ? AND ?';
return $this;
}
@@ -622,7 +622,9 @@ trait QueryTrait
if ($params === null) {
return $this;
}
$this->attributes = array_merge($this->attributes, $params);
foreach ($params as $param) {
$this->attributes[] = $param;
}
return $this;
}
@@ -640,6 +642,19 @@ trait QueryTrait
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
* @return $this
@@ -658,8 +673,8 @@ trait QueryTrait
*/
public function whereMath(string $column, string $opera, mixed $value): static
{
$this->bindParam(':' . $column, $value);
$this->where[] = $column . ' ' . $opera . ':' . $column;
$this->pushParam($value);
$this->where[] = $column . ' ' . $opera . ' ?';
return $this;
}
@@ -772,8 +787,8 @@ trait QueryTrait
*/
private function sprintf($column, $value, string $opera = '='): string
{
$this->bindParam(':' . $column, $value);
return $column . ' ' . $opera . ' :' . $column;
$this->pushParam($value);
return $column . ' ' . $opera . ' ?';
}