Changeset

7273:7e659f87973d

mod_storage_sql: Add LIMIT clause to queries where only a single row is expected
author Kim Alvefur <zash@zash.se>
date Sun, 13 Mar 2016 17:42:22 +0100
parents 7272:a23ca90d1984
children 7274:e0727512bb99
files plugins/mod_storage_sql.lua
diffstat 1 files changed, 3 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/mod_storage_sql.lua	Sun Mar 13 17:38:49 2016 +0100
+++ b/plugins/mod_storage_sql.lua	Sun Mar 13 17:42:22 2016 +0100
@@ -134,11 +134,11 @@
 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 @@
 				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