Merge 0.10->trunk
authorKim Alvefur <zash@zash.se>
Tue, 19 May 2015 21:23:44 +0000 (23:23 +0200)
committerKim Alvefur <zash@zash.se>
Tue, 19 May 2015 21:23:44 +0000 (23:23 +0200)
1  2 
plugins/mod_storage_sql2.lua

index a637c9dcbd3de99b492d0c2a2a3433f2d4f49774,21299f334f9bc932f3f051ad67b49856611d2780..8d5d948b8f114e85c2d3b2b7fa510db19fefd16a
@@@ -214,44 -214,14 +214,47 @@@ function keyval_store:users(
        return iterator(result);
  end
  
 +local map_store = {};
 +map_store.__index = map_store;
 +function map_store:get(username, key)
 +      local ok, result = engine:transaction(function()
 +              if type(key) == "string" and key ~= "" then
 +                      for row in engine:select("SELECT `type`, `value` FROM `prosody` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=?", host, username or "", self.store, key) do
 +                              return deserialize(row[1], row[2]);
 +                      end
 +              else
 +                      error("TODO: non-string keys");
 +              end
 +      end);
 +      if not ok then return nil, result; end
 +      return result;
 +end
 +function map_store:set(username, key, data)
 +      local ok, result = engine:transaction(function()
 +              if type(key) == "string" and key ~= "" then
 +                      engine:delete("DELETE FROM `prosody` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=?",
 +                              host, username or "", self.store, key);
 +                      if data ~= nil then
 +                              local t, value = assert(serialize(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");
 +              end
 +              return true;
 +      end);
 +      if not ok then return nil, result; end
 +      return result;
 +end
 +
  local archive_store = {}
+ archive_store.caps = {
+       total = true;
+ };
  archive_store.__index = archive_store
- function archive_store:append(username, key, when, with, value)
-       if value == nil then -- COMPAT early versions
-               when, with, value, key = key, when, with, value
+ function archive_store:append(username, key, value, when, with)
+       if type(when) ~= "number" then
+               value, when, with = when, with, value;
        end
        local user,store = username,self.store;
        return engine:transaction(function()