diff --git a/Database/SqlBuilder.php b/Database/SqlBuilder.php index 20f510d9..e26cf0e7 100644 --- a/Database/SqlBuilder.php +++ b/Database/SqlBuilder.php @@ -66,7 +66,6 @@ class SqlBuilder extends Component public function mathematics(array $attributes, string $opera = '+'): bool|array { $string = []; - foreach ($attributes as $attribute => $value) { $string[] = $attribute . '=' . $attribute . $opera . $value; } @@ -80,7 +79,7 @@ class SqlBuilder extends Component * @return array|bool * @throws Exception */ - private function __updateBuilder(array $string,array $params): array|bool + private function __updateBuilder(array $string, array $params): array|bool { if (empty($string)) { return $this->addError('None data update.'); @@ -92,7 +91,7 @@ class SqlBuilder extends Component } $update = 'UPDATE ' . $this->tableName() . ' SET ' . implode(',', $string) . $condition; - $update .= $this->builderLimit($this->query); + $update .= $this->builderLimit($this->query, false); return [$update, $params]; } @@ -185,7 +184,7 @@ class SqlBuilder extends Component str_starts_with($value, '+ ') || str_starts_with($value, '- ') ) { - $keys[] = $key . '=' . $key . $value; + $keys[] = $key . '=' . $key . ' ' . $value; } else { $params[$key . $order] = $value; $keys[] = $key . '=:' . $key . $order; diff --git a/Database/Traits/Builder.php b/Database/Traits/Builder.php index 2877b7be..d5e84af5 100644 --- a/Database/Traits/Builder.php +++ b/Database/Traits/Builder.php @@ -104,14 +104,15 @@ trait Builder /** * @param ActiveQuery|Query $query + * @param bool $hasLimit * @return string */ - #[Pure] private function builderLimit(ActiveQuery|Query $query): string + #[Pure] private function builderLimit(ActiveQuery|Query $query, bool $hasLimit = true): string { if (!is_numeric($query->limit) || $query->limit < 1) { return ""; } - if ($query->offset !== null) { + if ($query->offset !== null && $hasLimit) { return ' LIMIT ' . $query->offset . ',' . $query->limit; } return ' LIMIT ' . $query->limit;