Browse Source

allow concurrent pgsql:equery on same connection

Anton Lebedevich 13 years ago
parent
commit
dabf972f74
4 changed files with 12 additions and 6 deletions
  1. 8 3
      README
  2. 1 1
      TODO
  3. 2 1
      src/pgsql.erl
  4. 1 1
      src/pgsql_sock.erl

+ 8 - 3
README

@@ -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
@@ -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

+ 1 - 1
TODO

@@ -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()

+ 2 - 1
src/pgsql.erl

@@ -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);

+ 1 - 1
src/pgsql_sock.erl

@@ -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};