./ct_report/coverage/mongoose_rdbms_timestamp.COVER.html

1 -module(mongoose_rdbms_timestamp).
2 -export([prepare/0,
3 select/0,
4 select/2]).
5 -ignore_xref([select/2]).
6
7 -spec prepare() -> ok.
8 prepare() ->
9 15 mongoose_rdbms:prepare(mim_timestamp, users, [], select_query()),
10 15 ok.
11
12 select_query() ->
13 15 case {mongoose_rdbms:db_engine(global), mongoose_rdbms:db_type()} of
14 {mysql, _} ->
15
:-(
<<"SELECT UNIX_TIMESTAMP()">>;
16 {pgsql, _} ->
17 15 <<"SELECT CAST(extract(epoch from now()) AS integer)">>;
18 {odbc, mssql} ->
19
:-(
<<"SELECT DATEDIFF_BIG(second, '1970-01-01 00:00:00', GETUTCDATE())">>;
20 Other ->
21
:-(
error({prepare_timestamp_query_failed, Other})
22 end.
23
24 -spec select(mongooseim:host_type_or_global(), atom()) -> integer().
25 select() ->
26 14 select(global, default).
27
28 select(HostType, PoolName) ->
29 15 Res = mongoose_rdbms:execute_successfully(HostType, PoolName, mim_timestamp, []),
30 15 mongoose_rdbms:selected_to_integer(Res). %% ensure it is an integer
Line Hits Source