aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2016-03-13 17:43:33 +0100
committerKim Alvefur <zash@zash.se>2016-03-13 17:43:33 +0100
commit144597d16ba3c2dde9196d39cce0c68c67801806 (patch)
tree4cca54fc25a178fefc71061229e42d7aef9f69a1 /plugins
parent9df91659b930ab36d9761b049d18ed30f4b93352 (diff)
downloadprosody-144597d16ba3c2dde9196d39cce0c68c67801806.tar.gz
prosody-144597d16ba3c2dde9196d39cce0c68c67801806.zip
mod_storage_sql: Allow loops over results to end on their own
Diffstat (limited to 'plugins')
-rw-r--r--plugins/mod_storage_sql.lua14
1 files changed, 8 insertions, 6 deletions
diff --git a/plugins/mod_storage_sql.lua b/plugins/mod_storage_sql.lua
index a289310b..70f1ab83 100644
--- a/plugins/mod_storage_sql.lua
+++ b/plugins/mod_storage_sql.lua
@@ -133,15 +133,17 @@ map_store.__index = map_store;
map_store.remove = {};
function map_store:get(username, key)
local ok, result = engine:transaction(function()
+ local data;
if type(key) == "string" and key ~= "" then
for row in engine:select("SELECT `type`, `value` FROM `prosody` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=? LIMIT 1", host, username or "", self.store, key) do
- return deserialize(row[1], row[2]);
+ data = deserialize(row[1], row[2]);
end
+ return data;
else
for row in engine:select("SELECT `type`, `value` FROM `prosody` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=? LIMIT 1", host, username or "", self.store, "") do
- local data = deserialize(row[1], row[2]);
- return data and data[key] or nil;
+ data = deserialize(row[1], row[2]);
end
+ return data and data[key] or nil;
end
end);
if not ok then return nil, result; end
@@ -165,7 +167,6 @@ function map_store:set_keys(username, keydatas)
local extradata = {};
for row in engine:select("SELECT `type`, `value` FROM `prosody` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=? LIMIT 1", host, username or "", self.store, "") do
extradata = deserialize(row[1], row[2]);
- break;
end
engine:delete("DELETE FROM `prosody` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=?",
host, username or "", self.store, "");
@@ -260,8 +261,9 @@ function archive_store:find(username, query)
if query.total then
local stats = engine:select("SELECT COUNT(*) FROM `prosodyarchive` WHERE " .. t_concat(where, " AND "), unpack(args));
if stats then
- local _total = stats()
- total = _total and _total[1];
+ for row in stats do
+ total = row[1];
+ end
end
if query.limit == 0 then -- Skip the real query
return noop, total;