# HG changeset patch # User Waqas Hussain # Date 1292114364 -18000 # Node ID bf449ecf2144e5acbe29c57b952570774192cb6d # Parent b3a5f9b1d1df038aa9f5e5a31e2b478fba6eaa60 mod_storage_sql: Auto-initialize SQLite3 database. diff -r b3a5f9b1d1df -r bf449ecf2144 plugins/mod_storage_sql.lua --- a/plugins/mod_storage_sql.lua Sun Dec 12 05:38:48 2010 +0500 +++ b/plugins/mod_storage_sql.lua Sun Dec 12 05:39:24 2010 +0500 @@ -47,6 +47,19 @@ dbh:autocommit(false); -- don't commit automatically connection = dbh; + + if params.driver == "SQLite3" then -- auto initialize + local stmt = assert(connection:prepare("SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name='Prosody';")); + local ok = assert(stmt:execute()); + local count = stmt:fetch()[1]; + if count == 0 then + local stmt = assert(connection:prepare("CREATE TABLE Prosody (host TEXT, user TEXT, store TEXT, key TEXT, subkey TEXT, type TEXT, value TEXT);")); + assert(stmt:execute()); + assert(connection:commit()); + module:log("debug", "Initialized new SQLite3 database"); + end + --print("===", json.stringify()) + end end local function serialize(value)