aboutsummaryrefslogtreecommitdiffstats
path: root/src/mysqlerl.erl
diff options
context:
space:
mode:
authorBrian Cully <bjc@kublai.com>2008-03-02 17:44:34 -0500
committerBrian Cully <github.20.shmit@spamgourmet.com>2008-03-02 17:44:34 -0500
commit52a4f21f1aa608b327af5d2e83cf0c0a29ff7c7e (patch)
tree0e3c3e48c3d192d736e07718b88032f5e5a5cf82 /src/mysqlerl.erl
parent2891b40b3a7799f67ba83c4914500cba7ca8aa1c (diff)
downloadmysqlerl-52a4f21f1aa608b327af5d2e83cf0c0a29ff7c7e.tar.gz
mysqlerl-52a4f21f1aa608b327af5d2e83cf0c0a29ff7c7e.zip
Handle timeouts.
Pass timeout down to port level, and if the communication times out, kill the port and let the supervisor restart it. Also stub in select_count and param_query, conveniently used to test timing out.
Diffstat (limited to 'src/mysqlerl.erl')
-rw-r--r--src/mysqlerl.erl20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/mysqlerl.erl b/src/mysqlerl.erl
index a5df819..113efee 100644
--- a/src/mysqlerl.erl
+++ b/src/mysqlerl.erl
@@ -115,7 +115,7 @@ first(Ref) ->
%% {selected, ColNames, Rows} | {error, Reason}
%% Rows = rows()
first(Ref, Timeout) ->
- gen_server:call(Ref, #sql_first{}, Timeout).
+ conn_fwd(Ref, #sql_first{}, Timeout).
last(Ref) ->
last(Ref, infinity).
@@ -127,7 +127,7 @@ last(Ref) ->
%% {selected, ColNames, Rows} | {error, Reason}
%% Rows = rows()
last(Ref, Timeout) ->
- gen_server:call(Ref, #sql_last{}, Timeout).
+ conn_fwd(Ref, #sql_last{}, Timeout).
next(Ref) ->
next(Ref, infinity).
@@ -139,7 +139,7 @@ next(Ref) ->
%% {selected, ColNames, Rows} | {error, Reason}
%% Rows = rows()
next(Ref, Timeout) ->
- gen_server:call(Ref, #sql_next{}, Timeout).
+ conn_fwd(Ref, #sql_next{}, Timeout).
prev(Ref) ->
prev(Ref, infinity).
@@ -151,7 +151,7 @@ prev(Ref) ->
%% {selected, ColNames, Rows} | {error, Reason}
%% Rows = rows()
prev(Ref, Timeout) ->
- gen_server:call(Ref, #sql_prev{}, Timeout).
+ conn_fwd(Ref, #sql_prev{}, Timeout).
select_count(Ref, SQLQuery) ->
select_count(Ref, SQLQuery, infinity).
@@ -164,7 +164,7 @@ select_count(Ref, SQLQuery) ->
%% {ok, NrRows} | {error, Reason}
%% NrRows = n_rows()
select_count(Ref, SQLQuery, Timeout) ->
- gen_server:call(Ref, #sql_select_count{q = SQLQuery}, Timeout).
+ conn_fwd(Ref, #sql_select_count{q = SQLQuery}, Timeout).
select(Ref, Pos, N) ->
select(Ref, Pos, N, infinity).
@@ -177,7 +177,7 @@ select(Ref, Pos, N) ->
%% {selected, ColNames, Rows} | {error, Reason}
%% Rows = rows()
select(Ref, Pos, N, Timeout) ->
- gen_server:call(Ref, #sql_select{pos = Pos, n = N}, Timeout).
+ conn_fwd(Ref, #sql_select{pos = Pos, n = N}, Timeout).
param_query(Ref, SQLQuery, Params) ->
param_query(Ref, SQLQuery, Params, infinity).
@@ -191,8 +191,7 @@ param_query(Ref, SQLQuery, Params) ->
%% {selected, ColNames, Rows} | {error, Reason}
%% Rows = rows()
param_query(Ref, SQLQuery, Params, Timeout) ->
- gen_server:call(Ref, #sql_param_query{q = SQLQuery, params = Params},
- Timeout).
+ conn_fwd(Ref, #sql_param_query{q = SQLQuery, params = Params}, Timeout).
sql_query(Ref, SQLQuery) ->
sql_query(Ref, SQLQuery, infinity).
@@ -205,7 +204,10 @@ sql_query(Ref, SQLQuery) ->
%% {selected, ColNames, Rows} | {error, Reason}
%% Rows = rows()
sql_query(Ref, SQLQuery, Timeout) ->
- gen_server:call(Ref, #sql_query{q = SQLQuery}, Timeout).
+ conn_fwd(Ref, #sql_query{q = SQLQuery}, Timeout).
+
+conn_fwd(Ref, Msg, Timeout) ->
+ gen_server:call(Ref, {Msg, Timeout}, infinity).
%% Convert type needs some love! Cover all bases here instead of
%% fudging.