Changeset

7274:e0727512bb99

mod_storage_sql: Allow loops over results to end on their own
author Kim Alvefur <zash@zash.se>
date Sun, 13 Mar 2016 17:43:33 +0100
parents 7273:7e659f87973d
children 7275:187ba2e9c012
files plugins/mod_storage_sql.lua
diffstat 1 files changed, 8 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/mod_storage_sql.lua	Sun Mar 13 17:42:22 2016 +0100
+++ b/plugins/mod_storage_sql.lua	Sun Mar 13 17:43:33 2016 +0100
@@ -133,15 +133,17 @@
 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 @@
 				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 @@
 		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;