diff options
author | Brian Cully <bjc@kublai.com> | 2008-03-01 17:01:46 -0500 |
---|---|---|
committer | Brian Cully <bjc@kublai.com> | 2008-03-01 17:01:46 -0500 |
commit | 876136763a49adc76eb4e9fe4a7a9dc78fb9a171 (patch) | |
tree | 8ef468ccb423395aca8977b7502a46e0b0b962de /src/mysqlerl_connection.erl | |
parent | 36fad7d7f6e0797dc0f6fae0fe6e3497ed9e46d6 (diff) | |
download | mysqlerl-876136763a49adc76eb4e9fe4a7a9dc78fb9a171.tar.gz mysqlerl-876136763a49adc76eb4e9fe4a7a9dc78fb9a171.zip |
Use erl_interface instead of custom protocol.
Diffstat (limited to 'src/mysqlerl_connection.erl')
-rw-r--r-- | src/mysqlerl_connection.erl | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/mysqlerl_connection.erl b/src/mysqlerl_connection.erl index 52a6300..fb0479c 100644 --- a/src/mysqlerl_connection.erl +++ b/src/mysqlerl_connection.erl @@ -9,6 +9,8 @@ handle_call/3, handle_cast/2, handle_info/2]). -define(QUERY_MSG, 0). +-define(COMMIT_MSG, 1). +-define(ROLLBACK_MSG, 2). -define(EXTENDED_MSG, 255). -record(state, {ref}). @@ -30,7 +32,7 @@ init([Host, Port, Database, User, Password, Options]) -> Cmd = lists:flatten(io_lib:format("~s ~s ~w ~s ~s ~s ~s", [helper(), Host, Port, Database, User, Password, Options])), - Ref = open_port({spawn, Cmd}, [{packet, 4}]), + Ref = open_port({spawn, Cmd}, [{packet, 4}, binary]), {ok, #state{ref = Ref}}. terminate(#port_closed{reason = Reason}, #state{ref = Ref}) -> @@ -69,7 +71,10 @@ helper() -> handle_query(Ref, Query) -> io:format("DEBUG: got query: ~p~n", [Query]), - port_command(Ref, [?QUERY_MSG | Query]), + make_request(Ref, {sql_query, Query}). + +make_request(Ref, Req) -> + port_command(Ref, term_to_binary(Req)), receive {Ref, {data, Res}} -> {ok, Res}; Other -> |