diff options
Diffstat (limited to '')
-rw-r--r-- | src/mod_mam.erl | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/mod_mam.erl b/src/mod_mam.erl index 38642c0c..d212f63c 100644 --- a/src/mod_mam.erl +++ b/src/mod_mam.erl @@ -1260,7 +1260,7 @@ make_matchspec(LUser, LServer, Start, End, none) -> Msg end). -make_sql_query(User, _LServer, Start, End, With, RSM) -> +make_sql_query(User, LServer, Start, End, With, RSM) -> {Max, Direction, ID} = case RSM of #rsm_in{} -> {RSM#rsm_in.max, @@ -1269,11 +1269,19 @@ make_sql_query(User, _LServer, Start, End, With, RSM) -> none -> {none, none, <<>>} end, - LimitClause = if is_integer(Max), Max >= 0 -> + ODBCType = ejabberd_config:get_option( + {odbc_type, LServer}, + ejabberd_odbc:opt_type(odbc_type)), + LimitClause = if is_integer(Max), Max >= 0, ODBCType /= mssql -> [<<" limit ">>, jlib:integer_to_binary(Max+1)]; true -> [] end, + TopClause = if is_integer(Max), Max >= 0, ODBCType == mssql -> + [<<" TOP ">>, jlib:integer_to_binary(Max+1)]; + true -> + [] + end, WithClause = case With of {text, <<>>} -> []; @@ -1320,7 +1328,7 @@ make_sql_query(User, _LServer, Start, End, With, RSM) -> end, SUser = ejabberd_odbc:escape(User), - Query = [<<"SELECT timestamp, xml, peer, kind, nick" + Query = [<<"SELECT ">>, TopClause, <<" timestamp, xml, peer, kind, nick" " FROM archive WHERE username='">>, SUser, <<"'">>, WithClause, StartClause, EndClause, PageClause], |