mod_storage_sql: Make archive:append() to return the id (or key) as first return value
authorKim Alvefur <zash@zash.se>
Mon, 20 Feb 2017 01:26:03 +0100
changeset 7910 8e2446cdf6fa
parent 7909 aa6b036150eb
child 7911 dbdaa8487ecd
mod_storage_sql: Make archive:append() to return the id (or key) as first return value
plugins/mod_storage_sql.lua
--- a/plugins/mod_storage_sql.lua	Mon Feb 20 00:51:12 2017 +0100
+++ b/plugins/mod_storage_sql.lua	Mon Feb 20 01:26:03 2017 +0100
@@ -187,7 +187,7 @@
 		when, with, value = value, when, with;
 	end
 	local user,store = username,self.store;
-	return engine:transaction(function()
+	local ok, key = engine:transaction(function()
 		if key then
 			engine:delete("DELETE FROM `prosodyarchive` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=?", host, user or "", store, key);
 		else
@@ -197,6 +197,8 @@
 		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);
+	if not ok then return ok, key; end
+	return key;
 end
 
 -- Helpers for building the WHERE clause