From 71c4d6f7d1390d0db17011d235f33e62e91a00f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=99=AF=E7=AB=8B?= Date: Sun, 17 Aug 2025 22:06:16 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E5=99=A8=E5=BC=82=E5=B8=B8=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin/think-library/src/helper/PageHelper.php | 7 +++++-- plugin/think-library/src/helper/QueryHelper.php | 6 +++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/plugin/think-library/src/helper/PageHelper.php b/plugin/think-library/src/helper/PageHelper.php index 2afd69945..f2825e13d 100644 --- a/plugin/think-library/src/helper/PageHelper.php +++ b/plugin/think-library/src/helper/PageHelper.php @@ -174,7 +174,6 @@ class PageHelper extends Helper * @param BaseQuery|Model|string $dbQuery * @param string $field 指定排序字段 * @return \think\db\Query - * @throws \think\db\exception\DbException */ public function autoSortQuery($dbQuery, string $field = 'sort'): Query { @@ -185,7 +184,11 @@ class PageHelper extends Helper if ($this->app->request->has($pk = $query->getPk() ?: 'id', 'post')) { $map = [$pk => $this->app->request->post($pk, 0)]; $data = [$field => intval($this->app->request->post($field, 0))]; - $query->newQuery()->where($map)->update($data); + try { + $query->newQuery()->where($map)->update($data); + } catch (\Throwable $exception) { + $this->class->error('列表排序失败!'); + } $this->class->success('列表排序成功!', ''); } } diff --git a/plugin/think-library/src/helper/QueryHelper.php b/plugin/think-library/src/helper/QueryHelper.php index b54384f37..fbeb6954c 100644 --- a/plugin/think-library/src/helper/QueryHelper.php +++ b/plugin/think-library/src/helper/QueryHelper.php @@ -73,7 +73,6 @@ class QueryHelper extends Helper * @param string|array|null $input 输入数据 * @param callable|null $callable 初始回调 * @return $this - * @throws \think\db\exception\DbException */ public function init($dbQuery, $input = null, ?callable $callable = null): QueryHelper { @@ -244,7 +243,6 @@ class QueryHelper extends Helper /** * 清空数据并保留表结构 * @return $this - * @throws \think\db\exception\DbException */ public function empty(): QueryHelper { @@ -254,8 +252,10 @@ class QueryHelper extends Helper $this->query->getConnection()->execute("truncate table `{$table}`"); } elseif (in_array($ctype, ['sqlsrv', 'oracle', 'pgsql'])) { $this->query->getConnection()->execute("truncate table {$table}"); - } else { + } else try { $this->query->newQuery()->whereRaw('1=1')->delete(); + } catch (\Throwable $exception) { + trace_file($exception); } return $this; }