fix: 优化查询器异常处理

This commit is contained in:
邹景立 2025-08-17 22:06:16 +08:00
parent 8ff44eea2f
commit 71c4d6f7d1
2 changed files with 8 additions and 5 deletions

View File

@ -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))];
try {
$query->newQuery()->where($map)->update($data);
} catch (\Throwable $exception) {
$this->class->error('列表排序失败!');
}
$this->class->success('列表排序成功!', '');
}
}

View File

@ -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;
}