plugins/mod_storage_sql.lua

changeset 3975
aa5e93e61760
parent 3974
af40a7ce4f77
child 3976
16170a66e140
equal deleted inserted replaced
3974:af40a7ce4f77 3975:aa5e93e61760
53 local ok = assert(stmt:execute()); 53 local ok = assert(stmt:execute());
54 local count = stmt:fetch()[1]; 54 local count = stmt:fetch()[1];
55 if count == 0 then 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);")); 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()); 57 assert(stmt:execute());
58 assert(connection:commit());
59 module:log("debug", "Initialized new SQLite3 database"); 58 module:log("debug", "Initialized new SQLite3 database");
60 end 59 end
60 assert(connection:commit());
61 --print("===", json.stringify()) 61 --print("===", json.stringify())
62 end 62 end
63 end 63 end
64 64
65 local function serialize(value) 65 local function serialize(value)
130 result[a] = b; 130 result[a] = b;
131 end 131 end
132 end 132 end
133 end 133 end
134 end 134 end
135 return haveany and result or nil; 135 return commit(haveany and result or nil);
136 end 136 end
137 function keyval_store:set(username, data) 137 function keyval_store:set(username, data)
138 user,store = username,self.store; 138 user,store = username,self.store;
139 -- start transaction 139 -- start transaction
140 local affected, err = setsql("DELETE FROM `Prosody` WHERE `host`=? AND `user`=? AND `store`=? AND `subkey`=''"); 140 local affected, err = setsql("DELETE FROM `Prosody` WHERE `host`=? AND `user`=? AND `store`=? AND `subkey`=''");
180 result[a] = b; 180 result[a] = b;
181 end 181 end
182 end 182 end
183 end 183 end
184 end 184 end
185 return haveany and result or nil; 185 return commit(haveany and result or nil);
186 end 186 end
187 function map_store:set(username, key, data) 187 function map_store:set(username, key, data)
188 user,store = username,self.store; 188 user,store = username,self.store;
189 -- start transaction 189 -- start transaction
190 local affected, err = setsql("DELETE FROM `Prosody` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=?", key or ""); 190 local affected, err = setsql("DELETE FROM `Prosody` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=?", key or "");

mercurial