mod_storage_sql: Add LIMIT clause to queries where only a single row is expected
authorKim Alvefur <zash@zash.se>
Sun, 13 Mar 2016 16:42:22 +0000 (17:42 +0100)
committerKim Alvefur <zash@zash.se>
Sun, 13 Mar 2016 16:42:22 +0000 (17:42 +0100)
plugins/mod_storage_sql.lua

index bf3c1c7bd127756d2a641fd937709f4bf400d542..a289310b1ac5c82ba907c2921282b6497380a73b 100644 (file)
@@ -134,11 +134,11 @@ map_store.remove = {};
 function map_store:get(username, key)
        local ok, result = engine:transaction(function()
                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`=?", host, username or "", self.store, key) do
+                       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]);
                        end
                else
-                       for row in engine:select("SELECT `type`, `value` FROM `prosody` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=?", host, username or "", self.store, "") do
+                       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;
                        end
@@ -163,7 +163,7 @@ function map_store:set_keys(username, keydatas)
                                end
                        else
                                local extradata = {};
-                               for row in engine:select("SELECT `type`, `value` FROM `prosody` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=?", host, username or "", self.store, "") do
+                               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