Browse Source

handle equery cast

Anton Lebedevich 13 years ago
parent
commit
f556082292
2 changed files with 14 additions and 1 deletions
  1. 11 0
      src/pgsql_sock.erl
  2. 3 1
      src/pgsql_wire.erl

+ 11 - 0
src/pgsql_sock.erl

@@ -132,6 +132,17 @@ handle_cast(Req = {{_, _}, {parse, Name, Sql, Types}}, State) ->
     send(State, $H, []),
     {noreply, State#state{queue = queue:in(Req, Queue)}};
 
+handle_cast(Req = {{_,_}, {equery, Statement, Parameters}}, State) ->
+    #state{queue = Queue} = State,
+    #statement{name = StatementName, columns = Columns} = Statement,
+    Bin1 = pgsql_wire:encode_parameters(Parameters),
+    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, $S, []),
+    {noreply, State#state{queue = queue:in(Req, Queue)}};
+
 handle_cast(cancel, State = #state{backend = {Pid, Key}}) ->
     {ok, {Addr, Port}} = inet:peername(State#state.sock),
     SockOpts = [{active, false}, {packet, raw}, binary],

+ 3 - 1
src/pgsql_wire.erl

@@ -7,7 +7,9 @@
          encode/1,
          encode/2,
          encode_types/1,
-         format/1]).
+         encode_formats/1,
+         format/1,
+         encode_parameters/1]).
 
 -include("pgsql.hrl").
 -include("pgsql_binary.hrl").