./ct_report/coverage/mongoose_rdbms_timestamp.COVER.html

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