aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/mod_storage_sql.lua
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2019-05-26 19:41:58 +0200
committerKim Alvefur <zash@zash.se>2019-05-26 19:41:58 +0200
commit31db616162d82f7a4dc5f7f496cd95c19cbd5918 (patch)
tree11a618b505748faf115684e27aa45b2a622e80a9 /plugins/mod_storage_sql.lua
parent5c927a37de1ce01b20970e5245959c1c41a85b3f (diff)
parent069408d15861035e9da8052068c60939be938ab3 (diff)
downloadprosody-31db616162d82f7a4dc5f7f496cd95c19cbd5918.tar.gz
prosody-31db616162d82f7a4dc5f7f496cd95c19cbd5918.zip
Merge 0.11->trunk
Diffstat (limited to 'plugins/mod_storage_sql.lua')
-rw-r--r--plugins/mod_storage_sql.lua36
1 files changed, 22 insertions, 14 deletions
diff --git a/plugins/mod_storage_sql.lua b/plugins/mod_storage_sql.lua
index 596687ae..f0a8fee0 100644
--- a/plugins/mod_storage_sql.lua
+++ b/plugins/mod_storage_sql.lua
@@ -472,13 +472,23 @@ function archive_store:delete(username, query)
else
args[#args+1] = query.truncate;
local unlimited = "ALL";
- if engine.params.driver == "SQLite3" then
- sql_query = [[
- DELETE FROM "prosodyarchive"
+ sql_query = [[
+ DELETE FROM "prosodyarchive"
+ WHERE "sort_id" IN (
+ SELECT "sort_id" FROM "prosodyarchive"
WHERE %s
ORDER BY "sort_id" %s
- LIMIT %s OFFSET ?;
- ]];
+ LIMIT %s OFFSET ?
+ );]];
+ if engine.params.driver == "SQLite3" then
+ if engine._have_delete_limit then
+ sql_query = [[
+ DELETE FROM "prosodyarchive"
+ WHERE %s
+ ORDER BY "sort_id" %s
+ LIMIT %s OFFSET ?;
+ ]];
+ end
unlimited = "-1";
elseif engine.params.driver == "MySQL" then
sql_query = [[
@@ -489,15 +499,6 @@ function archive_store:delete(username, query)
LIMIT %s OFFSET ?
) AS limiter on result.sort_id = limiter.sort_id;]];
unlimited = "18446744073709551615";
- else
- sql_query = [[
- DELETE FROM "prosodyarchive"
- WHERE "sort_id" IN (
- SELECT "sort_id" FROM "prosodyarchive"
- WHERE %s
- ORDER BY "sort_id" %s
- LIMIT %s OFFSET ?
- );]];
end
sql_query = string.format(sql_query, t_concat(where, " AND "),
query.reverse and "ASC" or "DESC", unlimited);
@@ -718,6 +719,13 @@ function module.load()
module:log("error", "Old database format detected. Please run: prosodyctl mod_%s upgrade", module.name);
return false, "database upgrade needed";
end
+ if engine.params.driver == "SQLite3" then
+ for row in engine:select("PRAGMA compile_options") do
+ if row[1] == "ENABLE_UPDATE_DELETE_LIMIT" then
+ engine._have_delete_limit = true;
+ end
+ end
+ end
end
end);
engines[sql.db2uri(params)] = engine;