diff options
author | Christophe Romain <christophe.romain@process-one.net> | 2009-04-24 10:27:31 +0000 |
---|---|---|
committer | Christophe Romain <christophe.romain@process-one.net> | 2009-04-24 10:27:31 +0000 |
commit | bda111b14531e90b3646d254d467b2fdb2236f47 (patch) | |
tree | 30982509a6abc4c2588570c5f855a885b4f1ec16 /src/odbc | |
parent | improve send last published items spawning (diff) |
fix minor pubsub init glitch, and allow ejabberd_odbc to execute bloc of queries without transaction
SVN Revision: 2038
Diffstat (limited to 'src/odbc')
-rw-r--r-- | src/odbc/ejabberd_odbc.erl | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/odbc/ejabberd_odbc.erl b/src/odbc/ejabberd_odbc.erl index d40cb7588..09a0ec8c9 100644 --- a/src/odbc/ejabberd_odbc.erl +++ b/src/odbc/ejabberd_odbc.erl @@ -34,6 +34,7 @@ sql_query/2, sql_query_t/1, sql_transaction/2, + sql_bloc/2, escape/1, escape_like/1, keep_alive/1]). @@ -87,6 +88,11 @@ sql_transaction(Host, F) -> gen_server:call(ejabberd_odbc_sup:get_random_pid(Host), {sql_transaction, F}, ?TRANSACTION_TIMEOUT). +%% SQL bloc, based on a erlang anonymous function (F = fun) +sql_bloc(Host, F) -> + gen_server:call(ejabberd_odbc_sup:get_random_pid(Host), + {sql_bloc, F}, ?TRANSACTION_TIMEOUT). + %% This function is intended to be used from inside an sql_transaction: sql_query_t(Query) -> State = get(?STATE_KEY), @@ -189,6 +195,17 @@ handle_call({sql_transaction, F}, _From, State) -> Reply -> {reply, Reply, State} end; +handle_call({sql_bloc, F}, _From, State) -> + case execute_bloc(State, F) of + % error returned by MySQL driver + {error, "query timed out"} -> + {stop, timeout, State}; + % error returned by MySQL driver + {error, "Failed sending data on socket"++_} = Reply -> + {stop, closed, Reply, State}; + Reply -> + {reply, Reply, State} + end; handle_call(_Request, _From, State) -> Reply = ok, {reply, Reply, State}. @@ -273,6 +290,17 @@ execute_transaction(State, F, NRestarts, _Reason) -> {atomic, Res} end. +execute_bloc(State, F) -> + put(?STATE_KEY, State), + case catch F() of + {aborted, Reason} -> + {aborted, Reason}; + {'EXIT', Reason} -> + {aborted, Reason}; + Res -> + {atomic, Res} + end. + %% == pure ODBC code %% part of init/1 |