Comparison

plugins/mod_storage_sql.lua @ 7178:5953f415c815

mod_storage_sql: Treat non-existent archive IDs as beyound the end of the archive (fixes #624) (tested on sqlite3 only)
author Kim Alvefur <zash@zash.se>
date Mon, 22 Feb 2016 15:23:27 +0100
parent 7175:3e7c69190193
child 7273:7e659f87973d
comparison
equal deleted inserted replaced
7177:1295e14614f4 7178:5953f415c815
233 end 233 end
234 local function archive_where_id_range(query, args, where) 234 local function archive_where_id_range(query, args, where)
235 local args_len = #args 235 local args_len = #args
236 -- Before or after specific item, exclusive 236 -- Before or after specific item, exclusive
237 if query.after then -- keys better be unique! 237 if query.after then -- keys better be unique!
238 where[#where+1] = "`sort_id` > (SELECT `sort_id` FROM `prosodyarchive` WHERE `key` = ? AND `host` = ? AND `user` = ? AND `store` = ? LIMIT 1)" 238 where[#where+1] = "`sort_id` > COALESCE((SELECT `sort_id` FROM `prosodyarchive` WHERE `key` = ? AND `host` = ? AND `user` = ? AND `store` = ? LIMIT 1), 0)"
239 args[args_len+1], args[args_len+2], args[args_len+3], args[args_len+4] = query.after, args[1], args[2], args[3]; 239 args[args_len+1], args[args_len+2], args[args_len+3], args[args_len+4] = query.after, args[1], args[2], args[3];
240 args_len = args_len + 4 240 args_len = args_len + 4
241 end 241 end
242 if query.before then 242 if query.before then
243 where[#where+1] = "`sort_id` < (SELECT `sort_id` FROM `prosodyarchive` WHERE `key` = ? AND `host` = ? AND `user` = ? AND `store` = ? LIMIT 1)" 243 where[#where+1] = "`sort_id` < COALESCE((SELECT `sort_id` FROM `prosodyarchive` WHERE `key` = ? AND `host` = ? AND `user` = ? AND `store` = ? LIMIT 1), (SELECT MAX(`sort_id`)+1 FROM `prosodyarchive`))"
244 args[args_len+1], args[args_len+2], args[args_len+3], args[args_len+4] = query.before, args[1], args[2], args[3]; 244 args[args_len+1], args[args_len+2], args[args_len+3], args[args_len+4] = query.before, args[1], args[2], args[3];
245 end 245 end
246 end 246 end
247 247
248 function archive_store:find(username, query) 248 function archive_store:find(username, query)