diff options
author | Brian Cully <bjc@kublai.com> | 2008-03-01 17:51:58 -0500 |
---|---|---|
committer | Brian Cully <bjc@kublai.com> | 2008-03-01 17:51:58 -0500 |
commit | 1c18deb43934fbba7d1d1ac3542d8e8d136f8e7d (patch) | |
tree | 9af256089efaf43ee6a1469bdfdb73ceef84b7fb /src | |
parent | a6e20801114898a7f8904071f84702daafc0f0cc (diff) | |
download | mysqlerl-1c18deb43934fbba7d1d1ac3542d8e8d136f8e7d.tar.gz mysqlerl-1c18deb43934fbba7d1d1ac3542d8e8d136f8e7d.zip |
mysqlerl provides the interface for the connection, to avoid
trampolining at the cost of some slight non-obviousness.
Move protocol to .hrl file as a result.
Diffstat (limited to 'src')
-rw-r--r-- | src/mysqlerl.erl | 6 | ||||
-rw-r--r-- | src/mysqlerl.hrl | 1 | ||||
-rw-r--r-- | src/mysqlerl_connection.erl | 8 |
3 files changed, 8 insertions, 7 deletions
diff --git a/src/mysqlerl.erl b/src/mysqlerl.erl index ddc8857..aae7fda 100644 --- a/src/mysqlerl.erl +++ b/src/mysqlerl.erl @@ -4,6 +4,8 @@ -module(mysqlerl). -author('bjc@kublai.com'). +-include("mysqlerl.hrl"). + -export([test_start/0, test_msg/0]). -export([start/0, start/1, stop/0, commit/2, commit/3, @@ -193,5 +195,5 @@ sql_query(Ref, SQLQuery) -> %% Returns: %% {selected, ColNames, Rows} | {error, Reason} %% Rows = rows() -sql_query(_Ref, _SQLQuery, _Timeout) -> - ?NOTIMPLEMENTED. +sql_query(Ref, SQLQuery, Timeout) -> + gen_server:call(Ref, #sql_query{q = SQLQuery}, Timeout). diff --git a/src/mysqlerl.hrl b/src/mysqlerl.hrl new file mode 100644 index 0000000..aabd384 --- /dev/null +++ b/src/mysqlerl.hrl @@ -0,0 +1 @@ +-record(sql_query, {q}). diff --git a/src/mysqlerl_connection.erl b/src/mysqlerl_connection.erl index 35c69b2..cdb19c8 100644 --- a/src/mysqlerl_connection.erl +++ b/src/mysqlerl_connection.erl @@ -1,16 +1,17 @@ -module(mysqlerl_connection). -author('bjc@kublai.com'). +-include("mysqlerl.hrl"). + -behavior(gen_server). --export([start_link/6, stop/1, sql_query/3]). +-export([start_link/6, stop/1]). -export([init/1, terminate/2, code_change/3, handle_call/3, handle_cast/2, handle_info/2]). -record(state, {ref}). -record(port_closed, {reason}). --record(sql_query, {q}). start_link(Host, Port, Database, User, Password, Options) -> gen_server:start_link(?MODULE, [Host, Port, Database, @@ -19,9 +20,6 @@ start_link(Host, Port, Database, User, Password, Options) -> stop(Pid) -> gen_server:cast(Pid, stop). -sql_query(Pid, Query, Timeout) -> - gen_server:call(Pid, #sql_query{q = Query}, Timeout). - init([Host, Port, Database, User, Password, Options]) -> process_flag(trap_exit, true), Cmd = lists:flatten(io_lib:format("~s ~s ~w ~s ~s ~s ~s", |