From 81652333967049547d9934e5b9a2205785c8c3cf Mon Sep 17 00:00:00 2001 From: junleea <354425203@qq.com> Date: Wed, 5 Mar 2025 19:21:42 +0800 Subject: [PATCH] =?UTF-8?q?sql=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dao/shell.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/dao/shell.go b/dao/shell.go index e382be7..23f962c 100644 --- a/dao/shell.go +++ b/dao/shell.go @@ -77,9 +77,24 @@ func UpdateShellByID(id, authId uint, shellName, shellContent string, status int func FindShellWillRunByServer(server string, uid uint) []Shell { var shells []Shell if proto.Config.SERVER_SQL_LOG { - DB.Debug().Exec("select * from shells where server = ? and auth_id = ? and status = 0 order by created_at desc limit 100", server, uid).Scan(&shells) + result := DB.Debug().Where("server = ? AND auth_id = ? AND status = 0", server, uid). + Order("created_at DESC"). + Limit(100). + Find(&shells) + if result.Error != nil { + // 若查询过程中出现错误,输出错误信息 + log.Printf("Failed to query shells: %v\n", result.Error) + } } else { - DB.Exec("select * from shells where server = ? and auth_id = ? and status = 0 order by created_at desc limit 100", server, uid).Scan(&shells) + //DB.Exec("select * from shells where server = ? and auth_id = ? and status = 0 order by created_at desc limit 100", server, uid).Scan(&shells) + result := DB.Where("server = ? AND auth_id = ? AND status = 0", server, uid). + Order("created_at DESC"). + Limit(100). + Find(&shells) + if result.Error != nil { + // 若查询过程中出现错误,输出错误信息 + log.Printf("Failed to query shells: %v\n", result.Error) + } } return shells }