# HG changeset patch # User Kim Alvefur # Date 1454959392 -3600 # Node ID bb0fd02ae70f5d219e89e042000f2fe1734b9b27 # Parent b1a10985850242fe0efd215748eb4b9f18f3239d mod_storage_sql: Support non-string keys in map store diff -r b1a109858502 -r bb0fd02ae70f plugins/mod_storage_sql.lua --- a/plugins/mod_storage_sql.lua Fri Feb 05 16:12:01 2016 +0100 +++ b/plugins/mod_storage_sql.lua Mon Feb 08 20:23:12 2016 +0100 @@ -134,7 +134,10 @@ return deserialize(row[1], row[2]); end else - error("TODO: non-string keys"); + for row in engine:select("SELECT `type`, `value` FROM `prosody` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=?", host, username or "", self.store, "") do + local data = deserialize(row[1], row[2]); + return data and data[key] or nil; + end end end); if not ok then return nil, result; end @@ -150,7 +153,16 @@ engine:insert("INSERT INTO `prosody` (`host`,`user`,`store`,`key`,`type`,`value`) VALUES (?,?,?,?,?,?)", host, username or "", self.store, key, t, value); end else - error("TODO: non-string keys"); + 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 + extradata = deserialize(row[1], row[2]); + break; + end + engine:delete("DELETE FROM `prosody` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=?", + host, username or "", self.store, ""); + extradata[key] = data; + local t, value = assert(serialize(extradata)); + engine:insert("INSERT INTO `prosody` (`host`,`user`,`store`,`key`,`type`,`value`) VALUES (?,?,?,?,?,?)", host, username or "", self.store, "", t, value); end return true; end);