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 |