sql_call(Host, Msg) ->
case get(?STATE_KEY) of
undefined ->
- (?GEN_FSM):sync_send_event(ejabberd_odbc_sup:get_random_pid(Host),
- {sql_cmd, Msg, now()},
- ?TRANSACTION_TIMEOUT);
+ case ejabberd_odbc_sup:get_random_pid(Host) of
+ none -> ?WARNING_MSG("SQL calling unknown host: ~p~n", [Host]);
+ Pid ->
+ (?GEN_FSM):sync_send_event(Pid,{sql_cmd, Msg, now()},
+ ?TRANSACTION_TIMEOUT)
+ end;
_State -> nested_op(Msg)
end.
[R#sql_pool.pid || R <- Rs].
get_random_pid(Host) ->
- Pids = get_pids(Host),
- lists:nth(erlang:phash(now(), length(Pids)), Pids).
+ case get_pids(Host) of
+ [] -> none;
+ Pids -> lists:nth(erlang:phash(now(), length(Pids)), Pids)
+ end.
add_pid(Host, Pid) ->
F = fun () ->