From 1c18deb43934fbba7d1d1ac3542d8e8d136f8e7d Mon Sep 17 00:00:00 2001 From: Brian Cully Date: Sat, 1 Mar 2008 17:51:58 -0500 Subject: 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. --- src/mysqlerl.erl | 6 ++++-- src/mysqlerl.hrl | 1 + src/mysqlerl_connection.erl | 8 +++----- 3 files changed, 8 insertions(+), 7 deletions(-) create mode 100644 src/mysqlerl.hrl (limited to 'src') 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", -- cgit v1.2.3