mod_storage_sql2: Only attempt to delete conflicting items if an ID/key is given
authorKim Alvefur <zash@zash.se>
Tue, 21 Jan 2014 01:51:13 +0100
changeset 5996 e7efa9703a3f
parent 5995 aa7534a877fe
child 6000 0f6399c86c10
mod_storage_sql2: Only attempt to delete conflicting items if an ID/key is given
plugins/mod_storage_sql2.lua
--- a/plugins/mod_storage_sql2.lua	Tue Jan 21 00:51:31 2014 +0100
+++ b/plugins/mod_storage_sql2.lua	Tue Jan 21 01:51:13 2014 +0100
@@ -222,9 +222,12 @@
 	end
 	local user,store = username,self.store;
 	return engine:transaction(function()
-		local key = key or uuid.generate();
+		if key then
+			engine:delete("DELETE FROM `prosodyarchive` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=?", host, user or "", store, key);
+		else
+			key = uuid.generate();
+		end
 		local t, value = serialize(value);
-		engine:delete("DELETE FROM `prosodyarchive` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=?", host, user or "", store, key);
 		engine:insert("INSERT INTO `prosodyarchive` (`host`, `user`, `store`, `when`, `with`, `key`, `type`, `value`) VALUES (?,?,?,?,?,?,?,?)", host, user or "", store, when, with, key, t, value);
 		return key;
 	end);