# HG changeset patch # User Waqas Hussain # Date 1292114364 -18000 # Node ID 5a1551d604b1b58d8209a5aba8a432e56b7142d3 # Parent 1a58bbe19c60c9c742b6608f9950cb714f3fa387 mod_storage_sql: Auto-initialize SQLite3 database. diff -r 1a58bbe19c60 -r 5a1551d604b1 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)