aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/mod_storage_sql.lua
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2016-02-22 15:24:20 +0100
committerKim Alvefur <zash@zash.se>2016-02-22 15:24:20 +0100
commit82a913c6816be2b0503368afac85b8b20335db0e (patch)
tree3bb6d5bb05f75122414728e4605bbdb9aacacae0 /plugins/mod_storage_sql.lua
parent2675b63e1b14a929277d2ad8bcf6f1ec17187de2 (diff)
parenta1bba9eeab3263061a2b1e1634847b3ed4002e20 (diff)
downloadprosody-82a913c6816be2b0503368afac85b8b20335db0e.tar.gz
prosody-82a913c6816be2b0503368afac85b8b20335db0e.zip
Merge 0.10->trunk
Diffstat (limited to 'plugins/mod_storage_sql.lua')
-rw-r--r--plugins/mod_storage_sql.lua8
1 files changed, 3 insertions, 5 deletions
diff --git a/plugins/mod_storage_sql.lua b/plugins/mod_storage_sql.lua
index 50d34a23..bf3c1c7b 100644
--- a/plugins/mod_storage_sql.lua
+++ b/plugins/mod_storage_sql.lua
@@ -235,12 +235,12 @@ local function archive_where_id_range(query, args, where)
local args_len = #args
-- Before or after specific item, exclusive
if query.after then -- keys better be unique!
- where[#where+1] = "`sort_id` > (SELECT `sort_id` FROM `prosodyarchive` WHERE `key` = ? AND `host` = ? AND `user` = ? AND `store` = ? LIMIT 1)"
+ where[#where+1] = "`sort_id` > COALESCE((SELECT `sort_id` FROM `prosodyarchive` WHERE `key` = ? AND `host` = ? AND `user` = ? AND `store` = ? LIMIT 1), 0)"
args[args_len+1], args[args_len+2], args[args_len+3], args[args_len+4] = query.after, args[1], args[2], args[3];
args_len = args_len + 4
end
if query.before then
- where[#where+1] = "`sort_id` < (SELECT `sort_id` FROM `prosodyarchive` WHERE `key` = ? AND `host` = ? AND `user` = ? AND `store` = ? LIMIT 1)"
+ 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`))"
args[args_len+1], args[args_len+2], args[args_len+3], args[args_len+4] = query.before, args[1], args[2], args[3];
end
end
@@ -275,7 +275,6 @@ function archive_store:find(username, query)
end
sql_query = sql_query:format(t_concat(where, " AND "), query.reverse and "DESC" or "ASC", query.limit and " LIMIT ?" or "");
- module:log("debug", sql_query);
return engine:select(sql_query, unpack(args));
end);
if not ok then return ok, result end
@@ -301,7 +300,6 @@ function archive_store:delete(username, query)
archive_where(query, args, where);
archive_where_id_range(query, args, where);
sql_query = sql_query:format(t_concat(where, " AND "));
- module:log("debug", sql_query);
return engine:delete(sql_query, unpack(args));
end);
end
@@ -453,7 +451,7 @@ function module.load()
local params = normalize_params(module:get_option("sql", default_params));
engine = engines[sql.db2uri(params)];
if not engine then
- module:log("info", "Creating new engine");
+ module:log("debug", "Creating new engine");
engine = sql:create_engine(params, function (engine)
if module:get_option("sql_manage_tables", true) then
-- Automatically create table, ignore failure (table probably already exists)