25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-22 16:20:52 +01:00

Update mod_last SQL queries to the new API

This commit is contained in:
Alexey Shchepin 2016-02-18 18:49:14 +03:00
parent 2d042f078e
commit 6d7ce0237a
2 changed files with 22 additions and 34 deletions

View File

@ -185,18 +185,12 @@ get_last(LUser, LServer, riak) ->
Err
end;
get_last(LUser, LServer, odbc) ->
Username = ejabberd_odbc:escape(LUser),
case catch odbc_queries:get_last(LServer, Username) of
{selected, [<<"seconds">>, <<"state">>], []} ->
not_found;
{selected, [<<"seconds">>, <<"state">>],
[[STimeStamp, Status]]} ->
case catch jlib:binary_to_integer(STimeStamp) of
TimeStamp when is_integer(TimeStamp) ->
{ok, TimeStamp, Status};
Reason -> {error, {invalid_timestamp, Reason}}
end;
Reason -> {error, {invalid_result, Reason}}
case catch odbc_queries:get_last(LServer, LUser) of
{selected, []} ->
not_found;
{selected, [{TimeStamp, Status}]} ->
{ok, TimeStamp, Status};
Reason -> {error, {invalid_result, Reason}}
end.
get_last_iq(IQ, SubEl, LUser, LServer) ->
@ -260,12 +254,7 @@ store_last_info(LUser, LServer, TimeStamp, Status,
last_activity_schema())};
store_last_info(LUser, LServer, TimeStamp, Status,
odbc) ->
Username = ejabberd_odbc:escape(LUser),
Seconds =
ejabberd_odbc:escape(iolist_to_binary(integer_to_list(TimeStamp))),
State = ejabberd_odbc:escape(Status),
odbc_queries:set_last_t(LServer, Username, Seconds,
State).
odbc_queries:set_last_t(LServer, LUser, TimeStamp, Status).
%% @spec (LUser::string(), LServer::string()) ->
%% {ok, TimeStamp::integer(), Status::string()} | not_found
@ -286,8 +275,7 @@ remove_user(LUser, LServer, mnesia) ->
F = fun () -> mnesia:delete({last_activity, US}) end,
mnesia:transaction(F);
remove_user(LUser, LServer, odbc) ->
Username = ejabberd_odbc:escape(LUser),
odbc_queries:del_last(LServer, Username);
odbc_queries:del_last(LServer, LUser);
remove_user(LUser, LServer, riak) ->
{atomic, ejabberd_riak:delete(last_activity, {LUser, LServer})}.

View File

@ -122,22 +122,22 @@ update(LServer, Table, Fields, Vals, Where) ->
sql_transaction(LServer, F) ->
ejabberd_odbc:sql_transaction(LServer, F).
get_last(LServer, Username) ->
ejabberd_odbc:sql_query(LServer,
[<<"select seconds, state from last where "
"username='">>,
Username, <<"'">>]).
get_last(LServer, LUser) ->
ejabberd_odbc:sql_query(
LServer,
?SQL("select @(seconds)d, @(state)s from last"
" where username=%(LUser)s")).
set_last_t(LServer, Username, Seconds, State) ->
update(LServer, <<"last">>,
[<<"username">>, <<"seconds">>, <<"state">>],
[Username, Seconds, State],
[<<"username='">>, Username, <<"'">>]).
set_last_t(LServer, LUser, TimeStamp, Status) ->
?SQL_UPSERT(LServer, "last",
["!username=%(LUser)s",
"seconds=%(TimeStamp)d",
"state=%(Status)s"]).
del_last(LServer, Username) ->
ejabberd_odbc:sql_query(LServer,
[<<"delete from last where username='">>, Username,
<<"'">>]).
del_last(LServer, LUser) ->
ejabberd_odbc:sql_query(
LServer,
?SQL("delete from last where username=%(LUser)s")).
get_password(LServer, LUser) ->
ejabberd_odbc:sql_query(