Software /
code /
prosody
Comparison
plugins/mod_storage_sql.lua @ 3732:bf449ecf2144
mod_storage_sql: Auto-initialize SQLite3 database.
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Sun, 12 Dec 2010 05:39:24 +0500 |
parent | 3731:b3a5f9b1d1df |
child | 3743:5adfb8d0444d |
comparison
equal
deleted
inserted
replaced
3731:b3a5f9b1d1df | 3732:bf449ecf2144 |
---|---|
45 prosody.lock_globals(); | 45 prosody.lock_globals(); |
46 assert(dbh, err); | 46 assert(dbh, err); |
47 | 47 |
48 dbh:autocommit(false); -- don't commit automatically | 48 dbh:autocommit(false); -- don't commit automatically |
49 connection = dbh; | 49 connection = dbh; |
50 | |
51 if params.driver == "SQLite3" then -- auto initialize | |
52 local stmt = assert(connection:prepare("SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name='Prosody';")); | |
53 local ok = assert(stmt:execute()); | |
54 local count = stmt:fetch()[1]; | |
55 if count == 0 then | |
56 local stmt = assert(connection:prepare("CREATE TABLE Prosody (host TEXT, user TEXT, store TEXT, key TEXT, subkey TEXT, type TEXT, value TEXT);")); | |
57 assert(stmt:execute()); | |
58 assert(connection:commit()); | |
59 module:log("debug", "Initialized new SQLite3 database"); | |
60 end | |
61 --print("===", json.stringify()) | |
62 end | |
50 end | 63 end |
51 | 64 |
52 local function serialize(value) | 65 local function serialize(value) |
53 local t = type(value); | 66 local t = type(value); |
54 if t == "string" or t == "boolean" or t == "number" then | 67 if t == "string" or t == "boolean" or t == "number" then |