aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBrian Cully <bjc@kublai.com>2008-03-01 13:49:54 -0500
committerBrian Cully <bjc@kublai.com>2008-03-01 13:49:54 -0500
commit65a91998c41e759a279e1f5f8ec2232dbf5048b8 (patch)
tree8e703d35b60d9bee21a82d085f676194b786a6c3 /src
parenta38cab8f9ef88925dd755a32be8972dff1e37175 (diff)
downloadmysqlerl-65a91998c41e759a279e1f5f8ec2232dbf5048b8.tar.gz
mysqlerl-65a91998c41e759a279e1f5f8ec2232dbf5048b8.zip
handle_call as dispatcher
Diffstat (limited to 'src')
-rw-r--r--src/mysqlerl_connection.erl35
1 files changed, 26 insertions, 9 deletions
diff --git a/src/mysqlerl_connection.erl b/src/mysqlerl_connection.erl
index aa73d23..ca44252 100644
--- a/src/mysqlerl_connection.erl
+++ b/src/mysqlerl_connection.erl
@@ -45,15 +45,10 @@ terminate(Reason, State) ->
code_change(_OldVsn, State, _Extra) ->
{ok, State}.
-handle_call({test, Str}, _From, #state{ref = Ref} = State) ->
- io:format("DEBUG: got test message: ~p~n", [Str]),
- port_command(Ref, Str),
- receive
- {Ref, {data, Res}} ->
- {reply, {ok, Res}, State};
- Other ->
- error_logger:warning_msg("Got unknown message: ~p~n", [Other])
- end;
+handle_call(#sql_query{q = Query}, _From, State) ->
+ {reply, handle_query(State#state.ref, Query), State};
+handle_call({test, Str}, _From, State) ->
+ {reply, handle_test(State#state.ref, Str), State};
handle_call(Request, From, State) ->
io:format("DEBUG: got unknown call from ~p: ~p~n", [From, Request]),
{noreply, State}.
@@ -73,3 +68,25 @@ helper() ->
{error, bad_name} -> PrivDir = filename:join(["..", "priv"])
end,
filename:join([PrivDir, "mysqlerl"]).
+
+handle_query(Ref, Query) ->
+ io:format("DEBUG: got query: ~p~n", [Query]),
+ port_command(Ref, Query),
+ receive
+ {Ref, {data, Res}} -> {ok, Res};
+ Other ->
+ error_logger:warning_msg("Got unknown query response: ~p~n",
+ [Other]),
+ {badreply, Other}
+ end.
+
+handle_test(Ref, Str) ->
+ io:format("DEBUG: got test message: ~p~n", [Str]),
+ port_command(Ref, Str),
+ receive
+ {Ref, {data, Res}} -> {ok, Res};
+ Other ->
+ error_logger:warning_msg("Got unknown test response: ~p~n",
+ [Other]),
+ {badreply, Other}
+ end.