aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2016-02-08 20:23:12 +0100
committerKim Alvefur <zash@zash.se>2016-02-08 20:23:12 +0100
commitb6a24a9bb00a9461eace9ad2172d3774d7a2a71b (patch)
tree0ad6dab74c865f1ad3b0d11cbf8e7c3a8b28c457 /plugins
parentef1ad262f7fcf3d53c16b79cfbb4e067a19adea3 (diff)
downloadprosody-b6a24a9bb00a9461eace9ad2172d3774d7a2a71b.tar.gz
prosody-b6a24a9bb00a9461eace9ad2172d3774d7a2a71b.zip
mod_storage_sql: Support non-string keys in map store
Diffstat (limited to 'plugins')
-rw-r--r--plugins/mod_storage_sql.lua16
1 files changed, 14 insertions, 2 deletions
diff --git a/plugins/mod_storage_sql.lua b/plugins/mod_storage_sql.lua
index 57d964e2..31d83f68 100644
--- a/plugins/mod_storage_sql.lua
+++ b/plugins/mod_storage_sql.lua
@@ -134,7 +134,10 @@ function map_store:get(username, key)
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 @@ function map_store:set(username, key, data)
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);