summaryrefslogtreecommitdiffstatshomepage
path: root/plugins/data/database.lua
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/data/database.lua')
-rw-r--r--plugins/data/database.lua24
1 files changed, 24 insertions, 0 deletions
diff --git a/plugins/data/database.lua b/plugins/data/database.lua
new file mode 100644
index 00000000000..4f55e999be2
--- /dev/null
+++ b/plugins/data/database.lua
@@ -0,0 +1,24 @@
+local sql = require("lsqlite3")
+local datfile = {}
+local db
+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")
+ end
+end
+
+if db then
+ local found = false
+ db:exec("select * from sqllite_master where name = version", function() found = true return 0 end)
+ if not found then
+ db:exec([[
+ CREATE TABLE version (
+ version VARCHAR NOT NULL,
+ datfile VARCHAR UNIQUE NOT NULL)]])
+ end
+end
+
+return function() return db, sql end