Merge 0.9->trunk
[prosody.git] / plugins / mod_storage_sql.lua
index ebc337bf1aeec99c9975e81a6c08d61d43ca8189..c9a45fca86e4057d6dae5e6948c247d75a666432 100644 (file)
@@ -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)
+       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)