# HG changeset patch # User Kim Alvefur # Date 1390265473 -3600 # Node ID e7efa9703a3f9cbf8d82244d87b29ce602e61d72 # Parent aa7534a877fe2618b25c5d856837ddf853e65e8a mod_storage_sql2: Only attempt to delete conflicting items if an ID/key is given diff -r aa7534a877fe -r e7efa9703a3f 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);