Diff

plugins/mod_storage_sql.lua @ 5130:051d352ed03c

storagemanager, datamanager, mod_storage_{internal,sql}: Replace list_stores() with an iterator version
author Kim Alvefur <zash@zash.se>
date Mon, 17 Sep 2012 05:42:10 +0200
parent 5056:a125daa42ad4
child 5132:ce6546f867f9
line wrap: on
line diff
--- a/plugins/mod_storage_sql.lua	Sun Sep 16 02:18:07 2012 +0200
+++ b/plugins/mod_storage_sql.lua	Mon Sep 17 05:42:10 2012 +0200
@@ -374,10 +374,9 @@
 	return nil, "unsupported-store";
 end
 
-function driver:list_stores(username) -- Not to be confused with the list store type
-	local sql = (username == true
-		and "SELECT DISTINCT `store` FROM `prosody` WHERE `host`=? AND `user`!=?"
-		or  "SELECT DISTINCT `store` FROM `prosody` WHERE `host`=? AND `user`=?");
+function driver:stores(username) -- Not to be confused with the list store type
+	local sql = "SELECT DISTINCT `store` FROM `prosody` WHERE `host`=? AND `user`" ..
+		(username == true and "!=?" or "=?");
 	if username == true or not username then
 		username = "";
 	end
@@ -385,11 +384,11 @@
 	if not stmt then
 		return rollback(nil, err);
 	end
-	local stores = {};
-	for row in stmt:rows() do
-		stores[#stores+1] = row[1];
-	end
-	return commit(stores);
+	local next = stmt:rows();
+	return commit(function()
+		local row = next();
+		return row and row[1];
+	end);
 end
 
 function driver:purge(username)