Software / code / prosody
Comparison
plugins/mod_storage_sql2.lua @ 6335:eaf6e7986934
plugins/mod_storage_sql2: Return correct arguments from map_store operations
| author | daurnimator <quae@daurnimator.com> |
|---|---|
| date | Thu, 07 Aug 2014 18:34:51 -0400 |
| parent | 6331:fc5113a4540e |
| child | 6349:0cee68dd35f8 |
comparison
equal
deleted
inserted
replaced
| 6334:ba2555e06c7c | 6335:eaf6e7986934 |
|---|---|
| 217 end | 217 end |
| 218 | 218 |
| 219 local map_store = {}; | 219 local map_store = {}; |
| 220 map_store.__index = map_store; | 220 map_store.__index = map_store; |
| 221 function map_store:get(username, key) | 221 function map_store:get(username, key) |
| 222 return engine:transaction(function() | 222 local ok, result = engine:transaction(function() |
| 223 if type(key) == "string" and key ~= "" then | 223 if type(key) == "string" and key ~= "" then |
| 224 local iter, state, first = engine:select("SELECT * FROM `prosody` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=?", | 224 local iter, state, first = engine:select("SELECT * FROM `prosody` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=?", |
| 225 host, username, self.store, key or ""); | 225 host, username, self.store, key or ""); |
| 226 local row = iter(state, first); | 226 local row = iter(state, first); |
| 227 if row then | 227 if row then |
| 231 end | 231 end |
| 232 else | 232 else |
| 233 error("TODO: non-string keys"); | 233 error("TODO: non-string keys"); |
| 234 end | 234 end |
| 235 end); | 235 end); |
| 236 if not ok then return nil, result; end | |
| 237 return result; | |
| 236 end | 238 end |
| 237 function map_store:set(username, key, data) | 239 function map_store:set(username, key, data) |
| 238 return engine:transaction(function() | 240 local ok, result = engine:transaction(function() |
| 239 if data == nil then | 241 if data == nil then |
| 240 engine:delete("DELETE FROM `prosody` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=?", | 242 engine:delete("DELETE FROM `prosody` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=?", |
| 241 host, username, self.store, key or ""); | 243 host, username, self.store, key or ""); |
| 242 elseif type(key) == "string" and key ~= "" then | 244 elseif type(key) == "string" and key ~= "" then |
| 243 local t, value = assert(serialize(data)); | 245 local t, value = assert(serialize(data)); |
| 246 else | 248 else |
| 247 error("TODO: non-string keys"); | 249 error("TODO: non-string keys"); |
| 248 end | 250 end |
| 249 return true; | 251 return true; |
| 250 end); | 252 end); |
| 253 if not ok then return nil, result; end | |
| 254 return result; | |
| 251 end | 255 end |
| 252 | 256 |
| 253 local archive_store = {} | 257 local archive_store = {} |
| 254 archive_store.__index = archive_store | 258 archive_store.__index = archive_store |
| 255 function archive_store:append(username, key, when, with, value) | 259 function archive_store:append(username, key, when, with, value) |