From e4c3b8ca3aae2fe775290d0b3951aea93071004b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=86=E6=9D=A5=E5=A4=A7=E4=B8=8D=E5=90=8C?= <8243556+zhaobangyu@user.noreply.gitee.com> Date: Fri, 19 Apr 2024 03:19:38 +0000 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96sqlite?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script/driver/sqlite.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/script/driver/sqlite.lua b/script/driver/sqlite.lua index 85c2d971..e4456b58 100644 --- a/script/driver/sqlite.lua +++ b/script/driver/sqlite.lua @@ -46,9 +46,9 @@ function Sqlite:register_prepare(sheet) } end -function Sqlite:get_prepare(sheet) +function Sqlite:get_prepare(sheet, primary_id) if not self.prepares[sheet] then - self:register_prepare(sheet) + self:init_sheet(sheet, primary_id) end return self.prepares[sheet] end @@ -67,14 +67,14 @@ end function Sqlite:init_sheet(sheet, primary_id) log_debug("[Sqlite][init_sheet] sheet:{} primary_id:{}", sheet, primary_id) - self:register_prepare(sheet) self.driver.exec(sformat("CREATE TABLE IF NOT EXISTS '%s' (KEY %s PRIMARY KEY NOT NULL, VALUE BLOB);", sheet, type(primary_id) == "string" and "TEXT" or "INTEGER")) + self:register_prepare(sheet) end function Sqlite:put(primary_id, data, sheet) log_debug("[Sqlite][put] primary_id:{} data:{} sheet:{}", primary_id, data, sheet) - local rc = self:get_prepare(sheet).update.run(primary_id, data) + local rc = self:get_prepare(sheet, primary_id).update.run(primary_id, data) if rc ~= SQLITE_DONE then log_debug("[Sqlite][put] fail rc={}", rc) return false @@ -84,7 +84,7 @@ end function Sqlite:get(primary_id, sheet) log_debug("[Sqlite][get] sheet:{} primary_id:{}", sheet, primary_id) - local rc, data = self:get_prepare(sheet).select.run(primary_id) + local rc, data = self:get_prepare(sheet, primary_id).select.run(primary_id) if rc == SQLITE_NFOUND or rc == SQLITE_DONE then return (data[1] and data[1].VALUE) and data[1].VALUE or {}, true end @@ -92,7 +92,7 @@ function Sqlite:get(primary_id, sheet) end function Sqlite:del(primary_id, sheet) - local rc = self:get_prepare(sheet).delete.run(primary_id) + local rc = self:get_prepare(sheet, primary_id).delete.run(primary_id) return rc == SQLITE_NFOUND or rc == SQLITE_OK end