Comparison

plugins/mod_storage_sql2.lua @ 6740:99b3f29c3c71

Merge with 0.10
author Matthew Wild <mwild1@gmail.com>
date Wed, 24 Jun 2015 23:25:42 +0100
parent 6739:6216743c188c
parent 6728:db28b8639737
child 6745:6728ad041761
child 6746:5e8a8319699d
comparison
equal deleted inserted replaced
6739:6216743c188c 6740:99b3f29c3c71
124 end 124 end
125 125
126 --- Archive store API 126 --- Archive store API
127 127
128 local archive_store = {} 128 local archive_store = {}
129 archive_store.caps = {
130 total = true;
131 };
129 archive_store.__index = archive_store 132 archive_store.__index = archive_store
130 function archive_store:append(username, key, when, with, value) 133 function archive_store:append(username, key, value, when, with)
131 if value == nil then -- COMPAT early versions 134 if type(when) ~= "number" then
132 when, with, value, key = key, when, with, value 135 when, with, value = value, when, with;
133 end 136 end
134 local user,store = username,self.store; 137 local user,store = username,self.store;
135 return engine:transaction(function() 138 return engine:transaction(function()
136 if key then 139 if key then
137 engine:delete("DELETE FROM `prosodyarchive` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=?", host, user or "", store, key); 140 engine:delete("DELETE FROM `prosodyarchive` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=?", host, user or "", store, key);
190 function archive_store:find(username, query) 193 function archive_store:find(username, query)
191 query = query or {}; 194 query = query or {};
192 local user,store = username,self.store; 195 local user,store = username,self.store;
193 local total; 196 local total;
194 local ok, result = engine:transaction(function() 197 local ok, result = engine:transaction(function()
195 local sql_query = "SELECT `key`, `type`, `value`, `when` FROM `prosodyarchive` WHERE %s ORDER BY `sort_id` %s%s;"; 198 local sql_query = "SELECT `key`, `type`, `value`, `when`, `with` FROM `prosodyarchive` WHERE %s ORDER BY `sort_id` %s%s;";
196 local args = { host, user or "", store, }; 199 local args = { host, user or "", store, };
197 local where = { "`host` = ?", "`user` = ?", "`store` = ?", }; 200 local where = { "`host` = ?", "`user` = ?", "`store` = ?", };
198 201
199 archive_where(query, args, where); 202 archive_where(query, args, where);
200 203
222 end); 225 end);
223 if not ok then return ok, result end 226 if not ok then return ok, result end
224 return function() 227 return function()
225 local row = result(); 228 local row = result();
226 if row ~= nil then 229 if row ~= nil then
227 return row[1], deserialize(row[2], row[3]), row[4]; 230 return row[1], deserialize(row[2], row[3]), row[4], row[5];
228 end 231 end
229 end, total; 232 end, total;
230 end 233 end
231 234
232 function archive_store:delete(username, query) 235 function archive_store:delete(username, query)