mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-24 16:23:40 +01:00
Update mod_last SQL queries to the new API
This commit is contained in:
parent
2d042f078e
commit
6d7ce0237a
@ -185,17 +185,11 @@ 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, [<<"seconds">>, <<"state">>],
|
{selected, [{TimeStamp, Status}]} ->
|
||||||
[[STimeStamp, Status]]} ->
|
|
||||||
case catch jlib:binary_to_integer(STimeStamp) of
|
|
||||||
TimeStamp when is_integer(TimeStamp) ->
|
|
||||||
{ok, TimeStamp, Status};
|
{ok, TimeStamp, Status};
|
||||||
Reason -> {error, {invalid_timestamp, Reason}}
|
|
||||||
end;
|
|
||||||
Reason -> {error, {invalid_result, Reason}}
|
Reason -> {error, {invalid_result, Reason}}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
@ -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})}.
|
||||||
|
|
||||||
|
@ -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(
|
||||||
|
Loading…
Reference in New Issue
Block a user