From 0e0caaf8a90e538ded57d9cc1f0d3d255b9cbdb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Wed, 7 Jul 2021 14:04:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Database/SqlBuilder.php | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/Database/SqlBuilder.php b/Database/SqlBuilder.php index 9362ee4b..20f510d9 100644 --- a/Database/SqlBuilder.php +++ b/Database/SqlBuilder.php @@ -52,19 +52,8 @@ class SqlBuilder extends Component public function update(array $attributes): bool|array { [$string, $array] = $this->builderParams($attributes); - if (empty($string) || empty($array)) { - return $this->addError('None data update.'); - } - $condition = $this->conditionToString(); - if (!empty($condition)) { - $condition = ' WHERE ' . $condition; - } - - $update = 'UPDATE ' . $this->tableName() . ' SET ' . implode(',', $string) . $condition; - $update .= $this->builderLimit($this->query); - - return [$update, $array]; + return $this->__updateBuilder($string, $array); } @@ -76,12 +65,23 @@ class SqlBuilder extends Component */ public function mathematics(array $attributes, string $opera = '+'): bool|array { - $string = $array = []; + $string = []; foreach ($attributes as $attribute => $value) { $string[] = $attribute . '=' . $attribute . $opera . $value; } + return $this->__updateBuilder($string, []); + } + + /** + * @param array $string + * @param array $params + * @return array|bool + * @throws Exception + */ + private function __updateBuilder(array $string,array $params): array|bool + { if (empty($string)) { return $this->addError('None data update.'); } @@ -94,7 +94,7 @@ class SqlBuilder extends Component $update = 'UPDATE ' . $this->tableName() . ' SET ' . implode(',', $string) . $condition; $update .= $this->builderLimit($this->query); - return [$update, []]; + return [$update, $params]; }