summaryrefslogtreecommitdiff
path: root/src/ejabberd_odbc.erl
diff options
context:
space:
mode:
authorAlexey Shchepin <alexey@process-one.net>2016-02-18 17:38:25 +0300
committerAlexey Shchepin <alexey@process-one.net>2016-03-02 00:12:49 +0300
commit2d042f078e6d23a947819c1bb9629be501c6d9c2 (patch)
tree211658919f6e09de6c3ce1599e3842a29c41a616 /src/ejabberd_odbc.erl
parentUpdate mod_roster and ejabberd_auth_odbc SQL queries to the new API (diff)
New parse transform for ?SQL_UPSERT and ?SQL_UPSERT_T
Diffstat (limited to 'src/ejabberd_odbc.erl')
-rw-r--r--src/ejabberd_odbc.erl14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/ejabberd_odbc.erl b/src/ejabberd_odbc.erl
index b430d920..4f818f51 100644
--- a/src/ejabberd_odbc.erl
+++ b/src/ejabberd_odbc.erl
@@ -475,6 +475,12 @@ execute_bloc(F) ->
Res -> {atomic, Res}
end.
+execute_fun(F) when is_function(F, 0) ->
+ F();
+execute_fun(F) when is_function(F, 2) ->
+ State = get(?STATE_KEY),
+ F(State#state.db_type, State#state.db_version).
+
sql_query_internal([{_, _} | _] = Queries) ->
State = get(?STATE_KEY),
case select_sql_query(Queries, State) of
@@ -529,6 +535,11 @@ sql_query_internal(#sql_query{} = Query) ->
{updated, 0};
_Else -> Res
end;
+sql_query_internal(F) when is_function(F) ->
+ case catch execute_fun(F) of
+ {'EXIT', Reason} -> {error, Reason};
+ Res -> Res
+ end;
sql_query_internal(Query) ->
State = get(?STATE_KEY),
?DEBUG("SQL: \"~s\"", [Query]),
@@ -615,6 +626,9 @@ pgsql_execute_sql_query(SQLQuery, State) ->
Args = (SQLQuery#sql_query.args)(pgsql_execute_escape()),
ExecuteRes =
pgsql:execute(State#state.db_ref, SQLQuery#sql_query.hash, Args),
+% {T, ExecuteRes} =
+% timer:tc(pgsql, execute, [State#state.db_ref, SQLQuery#sql_query.hash, Args]),
+% io:format("T ~s ~p~n", [SQLQuery#sql_query.hash, T]),
Res = pgsql_execute_to_odbc(ExecuteRes),
sql_query_format_res(Res, SQLQuery).