diff options
author | Waqas Hussain <waqas20@gmail.com> | 2010-12-12 05:39:24 +0500 |
---|---|---|
committer | Waqas Hussain <waqas20@gmail.com> | 2010-12-12 05:39:24 +0500 |
commit | d6ce1c7e2a0e857ef575e999b4db2fb911650f5d (patch) | |
tree | 6d7f4dd04c08c04f827b06a9d6de3657cc50f1db /plugins/mod_storage_sql.lua | |
parent | a1a38f2f551bcc936d470efa3c69ead5646eb327 (diff) | |
download | prosody-d6ce1c7e2a0e857ef575e999b4db2fb911650f5d.tar.gz prosody-d6ce1c7e2a0e857ef575e999b4db2fb911650f5d.zip |
mod_storage_sql: Auto-initialize SQLite3 database.
Diffstat (limited to 'plugins/mod_storage_sql.lua')
-rw-r--r-- | plugins/mod_storage_sql.lua | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/plugins/mod_storage_sql.lua b/plugins/mod_storage_sql.lua index 68b38134..593acd31 100644 --- a/plugins/mod_storage_sql.lua +++ b/plugins/mod_storage_sql.lua @@ -47,6 +47,19 @@ do -- process options to get a db connection 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) |