Mercurial > prosody-hg
comparison plugins/mod_storage_sql.lua @ 3854:5a1551d604b1
mod_storage_sql: Auto-initialize SQLite3 database.
| author | Waqas Hussain <waqas20@gmail.com> |
|---|---|
| date | Sun, 12 Dec 2010 05:39:24 +0500 |
| parents | 1a58bbe19c60 |
| children | 5adfb8d0444d |
comparison
equal
deleted
inserted
replaced
| 3853:1a58bbe19c60 | 3854:5a1551d604b1 |
|---|---|
| 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 |
