diff options
author | 2018-01-14 12:09:06 +0100 | |
---|---|---|
committer | 2018-01-14 12:09:06 +0100 | |
commit | 7da4d2dfc64d5f76a7ac437083ba9fd345b22a65 (patch) | |
tree | 86b66eda458ef958013fd043dee1e05a83151fc3 /plugins/data/database.lua | |
parent | e42ca026d99dff625a97fbf886ccb3fc3ee37dab (diff) |
plugins/data: added reporting of database errors (nw)
Diffstat (limited to 'plugins/data/database.lua')
-rw-r--r-- | plugins/data/database.lua | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/plugins/data/database.lua b/plugins/data/database.lua index 5925766dcfe..9e1fd7ae855 100644 --- a/plugins/data/database.lua +++ b/plugins/data/database.lua @@ -1,23 +1,33 @@ local sql = require("lsqlite3") local datfile = {} local db + +function check_db(msg) + if db:errcode() > sqlite3.OK then + io.stderr:write("Error: " .. msg .. " (" .. db:errcode() .. " - " .. db:errmsg() .. ")\n") + end +end + do local dbpath = lfs.env_replace(mame_manager:ui():options().entries.historypath:value():match("([^;]+)")) db = sql.open(dbpath .. "/history.db") if not db then lfs.mkdir(dbpath) db = sql.open(dbpath .. "/history.db") + check_db("opening database") end end if db then local found = false db:exec("select * from sqlite_master where name = 'version'", function() found = true return 0 end) + check_db("checking for 'version' table") if not found then db:exec([[ CREATE TABLE version ( version VARCHAR NOT NULL, datfile VARCHAR UNIQUE NOT NULL)]]) + check_db("creating 'version' table") end end |