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

View File

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