net.http.server: Properly handle persistent connections
[prosody.git] / plugins / mod_storage_sql.lua
index c9a45fca86e4057d6dae5e6948c247d75a666432..eed3fec900784518a8860b1d5ed79199a85e397b 100644 (file)
@@ -228,7 +228,8 @@ local function rollback(...)
        return ...;
 end
 local function commit(...)
-       if not connection:commit() then return nil, "SQL commit failed"; end
+       local success,err = connection:commit();
+       if not success then return nil, "SQL commit failed: "..tostring(err); end
        return ...;
 end
 
@@ -298,6 +299,17 @@ function keyval_store:set(username, data)
        end
        if success then return ret, err; else return rollback(nil, ret); end
 end
+function keyval_store:users()
+       local stmt, err = dosql("SELECT DISTINCT `user` FROM `prosody` WHERE `host`=? AND `store`=?", host, self.store);
+       if not stmt then
+               return rollback(nil, err);
+       end
+       local next = stmt:rows();
+       return commit(function()
+               local row = next();
+               return row and row[1];
+       end);
+end
 
 local function map_store_get(key)
        local stmt, err = getsql("SELECT * FROM `prosody` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=?", key or "");