From 07bb8a42ce660684bbe4742aeefd5ea92092a37e Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 17 Sep 2012 05:42:10 +0200 Subject: storagemanager, datamanager, mod_storage_{internal,sql}: Replace list_stores() with an iterator version --- plugins/mod_storage_sql.lua | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'plugins/mod_storage_sql.lua') diff --git a/plugins/mod_storage_sql.lua b/plugins/mod_storage_sql.lua index ea25c90b..5a08598a 100644 --- a/plugins/mod_storage_sql.lua +++ b/plugins/mod_storage_sql.lua @@ -374,10 +374,9 @@ function driver:open(store, typ) 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 @@ function driver:list_stores(username) -- Not to be confused with the list store 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) -- cgit v1.2.3 From 3b96fac7491ce85877b7ee2038ae90b2d501ca6c Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Wed, 19 Sep 2012 12:09:27 +0100 Subject: mod_storage_sql: Remove obsolete comment --- plugins/mod_storage_sql.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins/mod_storage_sql.lua') diff --git a/plugins/mod_storage_sql.lua b/plugins/mod_storage_sql.lua index 5a08598a..e05a475d 100644 --- a/plugins/mod_storage_sql.lua +++ b/plugins/mod_storage_sql.lua @@ -374,7 +374,7 @@ function driver:open(store, typ) return nil, "unsupported-store"; end -function driver:stores(username) -- Not to be confused with the list store type +function driver:stores(username) local sql = "SELECT DISTINCT `store` FROM `prosody` WHERE `host`=? AND `user`" .. (username == true and "!=?" or "=?"); if username == true or not username then -- cgit v1.2.3