Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/processone/ejabberd.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeniy Khramtsov <ekhramtsov@process-one.net>2016-03-24 15:03:19 +0300
committerEvgeniy Khramtsov <ekhramtsov@process-one.net>2016-03-29 11:34:00 +0300
commit7a9e93839a9ff8f2cb098fcbd75d2669520521bb (patch)
tree909ddfe1da44de9c0d12ee58616627d20da0bc5e /src/mod_mam.erl
parent54ddc990c27224c7a05822bbac2d616a973f2f15 (diff)
Fix some LIMIT related problems with MSSQL
Diffstat (limited to 'src/mod_mam.erl')
-rw-r--r--src/mod_mam.erl14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/mod_mam.erl b/src/mod_mam.erl
index 38642c0c6..d212f63c6 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],