Skip to content

Commit

Permalink
allow concurrent pgsql:equery on same connection
Browse files Browse the repository at this point in the history
  • Loading branch information
mabrek committed Jun 19, 2012
1 parent 7c85896 commit dabf972
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
11 changes: 8 additions & 3 deletions README
Expand Up @@ -33,6 +33,8 @@ Asynchronous fork of https://github.com/wg/epgsql
the 3 failing timeout tests.
SSL performance can degrade if the driver process has a large inbox
(thousands of messages).
Usage of unnamed prepared statement and portals leads to unpredicted results
in case of concurrent access to same connection.


* Connect
Expand Down Expand Up @@ -145,14 +147,17 @@ Asynchronous fork of https://github.com/wg/epgsql
bools as true/false, etc. For details see pgsql_binary.erl and the
Data Representation section below.

Ref = apgsql:equery(C, Sql, [Parameters]),
Asynchronous api equery requires you to parse statement beforehand

Ref = apgsql:equery(C, Statement, [Parameters]),
receive
{C, Ref, Res} -> Res
end.
Statement - parsed statement (see parse below)
Res has same format as return value of pgsql:equery.

ipgsql:equery(C, Sql, [Parameters]) sends same set of messages as squery
including final {C, Ref, done}.
ipgsql:equery(C, Statement, [Parameters]) sends same set of messages as
squery including final {C, Ref, done}.


* Parse/Bind/Execute
Expand Down
2 changes: 1 addition & 1 deletion TODO
Expand Up @@ -2,7 +2,7 @@ notify_async sends useful warnings, don't hide them if no async listeners
call with timeouts (query cancellation?)
describe portal test
connect on start?
text format support
text column format support
remove parse before equery (needs text column format)
selectable date return format
like erlang:now()
Expand Down
3 changes: 2 additions & 1 deletion src/pgsql.erl
Expand Up @@ -58,7 +58,8 @@ equery(C, Sql) ->

%% TODO add fast_equery command that doesn't need parsed statement
equery(C, Sql, Parameters) ->
case parse(C, Sql) of
Name = ["equery-", atom_to_list(node()), pid_to_list(self())],
case parse(C, Name, Sql, []) of
{ok, #statement{types = Types} = S} ->
Typed_Parameters = lists:zip(Types, Parameters),
gen_server:call(C, {equery, S, Typed_Parameters}, infinity);
Expand Down
2 changes: 1 addition & 1 deletion src/pgsql_sock.erl
Expand Up @@ -158,7 +158,7 @@ command({equery, Statement, Parameters}, State) ->
Bin2 = pgsql_wire:encode_formats(Columns),
send(State, $B, ["", 0, StatementName, 0, Bin1, Bin2]),
send(State, $E, ["", 0, <<0:?int32>>]),
send(State, $C, [$S, "", 0]),
send(State, $C, [$S, StatementName, 0]),
send(State, $S, []),
{noreply, State};

Expand Down

0 comments on commit dabf972

Please sign in to comment.