From e658b0614486255a546a94fc6926348db416783a Mon Sep 17 00:00:00 2001 From: Nelson Vides Date: Tue, 10 Jan 2023 15:49:41 +0100 Subject: [PATCH] Fail to start on MSSQL with delete_domain_limit --- src/inbox/mod_inbox_rdbms.erl | 15 +++++++------ src/mam/mod_mam_muc_rdbms_arch.erl | 25 +++++++++++----------- src/mam/mod_mam_rdbms_arch.erl | 34 +++++++++++++++--------------- 3 files changed, 39 insertions(+), 35 deletions(-) diff --git a/src/inbox/mod_inbox_rdbms.erl b/src/inbox/mod_inbox_rdbms.erl index 68a93819f5..90044f361d 100644 --- a/src/inbox/mod_inbox_rdbms.erl +++ b/src/inbox/mod_inbox_rdbms.erl @@ -98,14 +98,17 @@ prepare_remove_domain(#{delete_domain_limit := infinity}) -> mongoose_rdbms:prepare( inbox_delete_domain, inbox, [lserver], <<"DELETE FROM inbox WHERE lserver = ?">>); prepare_remove_domain(#{delete_domain_limit := Limit}) -> - {MaybeLimitSQL, MaybeLimitMSSQL} = rdbms_queries:get_db_specific_limits_binaries(Limit), - ServerTable = <<"(SELECT * FROM (SELECT ", MaybeLimitMSSQL/binary, - " lserver, luser, remote_bare_jid FROM inbox", - " WHERE lserver = ? ", MaybeLimitSQL/binary, ") AS T)">>, + LimitSQL = case mongoose_rdbms:db_type() of + mssql -> throw(delete_domain_limit_not_supported_for_mssql); + _ -> {MaybeLimitSQL, _} = rdbms_queries:get_db_specific_limits_binaries(Limit), + MaybeLimitSQL + end, + ServerTable = <<"(SELECT * FROM ", + "(SELECT lserver, luser, remote_bare_jid FROM inbox", + " WHERE lserver = ? ", LimitSQL/binary, ") AS T)">>, mongoose_rdbms:prepare( inbox_incr_delete_domain, inbox, [lserver], - <<"DELETE FROM inbox WHERE (lserver, luser, remote_bare_jid) IN ", - ServerTable/binary>>). + <<"DELETE FROM inbox WHERE (lserver, luser, remote_bare_jid) IN ", ServerTable/binary>>). -spec get_inbox(HostType :: mongooseim:host_type(), LUser :: jid:luser(), diff --git a/src/mam/mod_mam_muc_rdbms_arch.erl b/src/mam/mod_mam_muc_rdbms_arch.erl index 778b646d35..c534344c27 100644 --- a/src/mam/mod_mam_muc_rdbms_arch.erl +++ b/src/mam/mod_mam_muc_rdbms_arch.erl @@ -145,20 +145,21 @@ prepare_remove_domain(#{delete_domain_limit := infinity}) -> mongoose_rdbms:prepare(mam_muc_remove_domain_users, mam_server_user, [server], <<"DELETE FROM mam_server_user WHERE server = ? ">>); prepare_remove_domain(#{delete_domain_limit := Limit}) -> - {MaybeLimitSQL, MaybeLimitMSSQL} = rdbms_queries:get_db_specific_limits_binaries(Limit), - IdTable = <<"(SELECT * FROM (SELECT ", MaybeLimitMSSQL/binary, - " msg.room_id, msg.id FROM mam_muc_message msg", - " INNER JOIN mam_server_user msu ON msu.id=msg.room_id", - " WHERE msu.server = ? ", MaybeLimitSQL/binary, ") AS T)">>, + LimitSQL = case mongoose_rdbms:db_type() of + mssql -> throw(delete_domain_limit_not_supported_for_mssql); + _ -> {MaybeLimitSQL, _} = rdbms_queries:get_db_specific_limits_binaries(Limit), + MaybeLimitSQL + end, + IdTable = <<"(SELECT * FROM ", + "(SELECT msg.room_id, msg.id FROM mam_muc_message msg", + " INNER JOIN mam_server_user msu ON msu.id=msg.room_id", + " WHERE msu.server = ? ", LimitSQL/binary, ") AS T)">>, mongoose_rdbms:prepare(mam_muc_incr_remove_domain, mam_muc_message, ['mam_server_user.server'], - <<"DELETE FROM mam_muc_message " - "WHERE (room_id, id) IN ", IdTable/binary>>), - - ServerTable = <<"(SELECT * FROM (SELECT ", MaybeLimitMSSQL/binary, - " id FROM mam_server_user WHERE server = ? ", MaybeLimitSQL/binary, ") as t)">>, + <<"DELETE FROM mam_muc_message WHERE (room_id, id) IN ", IdTable/binary>>), + ServerTable = <<"(SELECT * FROM", + "(SELECT id FROM mam_server_user WHERE server = ? ", LimitSQL/binary, ") as t)">>, mongoose_rdbms:prepare(mam_muc_incr_remove_domain_users, mam_server_user, [server], - <<"DELETE ", MaybeLimitMSSQL/binary, - " FROM mam_server_user WHERE id IN ", ServerTable/binary>>). + <<"DELETE FROM mam_server_user WHERE id IN ", ServerTable/binary>>). %% ---------------------------------------------------------------------- %% Declarative logic diff --git a/src/mam/mod_mam_rdbms_arch.erl b/src/mam/mod_mam_rdbms_arch.erl index 4283d9febe..d9483d97d2 100644 --- a/src/mam/mod_mam_rdbms_arch.erl +++ b/src/mam/mod_mam_rdbms_arch.erl @@ -165,28 +165,28 @@ prepare_remove_domain(#{delete_domain_limit := infinity}) -> mongoose_rdbms:prepare(mam_remove_domain_users, mam_server_user, [server], <<"DELETE FROM mam_server_user WHERE server = ?">>); prepare_remove_domain(#{delete_domain_limit := Limit}) -> - {MaybeLimitSQL, MaybeLimitMSSQL} = rdbms_queries:get_db_specific_limits_binaries(Limit), - IdTable = <<"(SELECT * FROM (SELECT ", MaybeLimitMSSQL/binary, - " msg.user_id, msg.id FROM mam_message msg", - " INNER JOIN mam_server_user msu ON msu.id=msg.user_id", - " WHERE msu.server = ? ", MaybeLimitSQL/binary, ") AS T)">>, + LimitSQL = case mongoose_rdbms:db_type() of + mssql -> throw(delete_domain_limit_not_supported_for_mssql); + _ -> {MaybeLimitSQL, _} = rdbms_queries:get_db_specific_limits_binaries(Limit), + MaybeLimitSQL + end, + IdTable = <<"(SELECT * FROM ", + "(SELECT msg.user_id, msg.id FROM mam_message msg", + " INNER JOIN mam_server_user msu ON msu.id=msg.user_id", + " WHERE msu.server = ? ", LimitSQL/binary, ") AS T)">>, mongoose_rdbms:prepare(mam_incr_remove_domain, mam_message, ['mam_server_user.server'], - <<"DELETE FROM mam_message " - "WHERE (user_id, id) IN ", IdTable/binary>>), - - CfgTable = <<"(SELECT * FROM (SELECT ", MaybeLimitMSSQL/binary, - " cfg.user_id, cfg.remote_jid FROM mam_config cfg", - " INNER JOIN mam_server_user msu ON msu.id=cfg.user_id", - " WHERE msu.server = ? ", MaybeLimitSQL/binary, ") AS T)">>, + <<"DELETE FROM mam_message WHERE (user_id, id) IN ", IdTable/binary>>), + CfgTable = <<"(SELECT * FROM ", + "(SELECT cfg.user_id, cfg.remote_jid FROM mam_config cfg", + " INNER JOIN mam_server_user msu ON msu.id=cfg.user_id", + " WHERE msu.server = ? ", LimitSQL/binary, ") AS T)">>, mongoose_rdbms:prepare(mam_incr_remove_domain_prefs, mam_config, ['mam_server_user.server'], <<"DELETE FROM mam_config " "WHERE (user_id, remote_jid) IN ", CfgTable/binary>>), - - ServerTable = <<"(SELECT * FROM (SELECT ", MaybeLimitMSSQL/binary, - " id FROM mam_server_user WHERE server = ? ", MaybeLimitSQL/binary, ") as t)">>, + ServerTable = <<"(SELECT * FROM ", + "(SELECT id FROM mam_server_user WHERE server = ? ", LimitSQL/binary, ") as t)">>, mongoose_rdbms:prepare(mam_incr_remove_domain_users, mam_server_user, [server], - <<"DELETE ", MaybeLimitMSSQL/binary, - " FROM mam_server_user WHERE id IN ", ServerTable/binary>>). + <<"DELETE FROM mam_server_user WHERE id IN ", ServerTable/binary>>). %% ----------------------------------------------------------------------