BookInfo: Saner database migration (#7039)

Avoid opening two connections in //, by feeding the current connection
to saveSetting, like we were already doing for loadSettings...

It somehow worked just fine on Kobo/Emu, but blew up in fun and
interesting ways on Kindle, probably because of the Fuse proxy.

It was still pretty dumb nonetheless.
reviewable/pr7042/r1
NiLuJe 3 years ago committed by GitHub
parent 7dd94b348f
commit 838769b0fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -169,7 +169,7 @@ function BookInfoManager:createDB()
-- Restore non-deprecated settings
for k, v in pairs(self.settings) do
if k ~= "version" then
self:saveSetting(k, v, true)
self:saveSetting(k, v, db_conn, true)
end
end
self:loadSettings(db_conn)
@ -268,16 +268,24 @@ function BookInfoManager:getSetting(key)
return self.settings[key]
end
function BookInfoManager:saveSetting(key, value, skip_reload)
function BookInfoManager:saveSetting(key, value, db_conn, skip_reload)
if not value or value == false or value == "" then
if lfs.attributes(self.db_location, "mode") ~= "file" then
-- If no db created, no need to save (and create db) an empty value
return
end
end
self:openDbConnection()
local my_db_conn
if db_conn then
my_db_conn = db_conn
else
self:openDbConnection()
my_db_conn = self.db_conn
end
local query = "INSERT OR REPLACE INTO config (key, value) VALUES (?, ?);"
local stmt = self.db_conn:prepare(query)
local stmt = my_db_conn:prepare(query)
if value == false then -- convert false to NULL
value = nil
elseif value == true then -- convert true to "Y"

Loading…
Cancel
Save