Browse Source

handle parse/describe replies

Anton Lebedevich 13 years ago
parent
commit
d6896d51a1
2 changed files with 33 additions and 2 deletions
  1. 30 1
      src/pgsql_sock.erl
  2. 3 1
      src/pgsql_wire.erl

+ 30 - 1
src/pgsql_sock.erl

@@ -130,7 +130,6 @@ handle_cast(Req = {{_, _}, {parse, Name, Sql, Types}}, State) ->
     send(State, $P, [Name, 0, Sql, 0, Bin]),
     send(State, $D, [$S, Name, 0]),
     send(State, $H, []),
-    S = #statement{name = Name},
     {noreply, State#state{queue = queue:in(Req, Queue)}};
 
 handle_cast(cancel, State = #state{backend = {Pid, Key}}) ->
@@ -291,6 +290,36 @@ initializing({error, _} = Error, State) ->
 initializing(Other, State) ->
     on_message(Other, State).
 
+%% ParseComplete
+on_message({$1, <<>>}, State) ->
+    {noreply, State};
+
+%% ParameterDescription
+on_message({$t, <<_Count:?int16, Bin/binary>>}, State) ->
+    Types = [pgsql_types:oid2type(Oid) || <<Oid:?int32>> <= Bin],
+    notify(State, {types, Types}),
+    {noreply, State};
+
+%% RowDescription
+on_message({$T, <<Count:?int16, Bin/binary>>}, State) ->
+    #state{queue = Q} = State,
+    Columns = pgsql_wire:decode_columns(Count, Bin),
+    Columns2 = [C#column{format = pgsql_wire:format(C#column.type)} || C <- Columns],
+    notify(State, {columns, Columns2}),
+    {noreply, State#state{queue = queue:drop(Q)}};
+
+%% NoData
+on_message({$n, <<>>}, State) ->
+    #state{queue = Q} = State,
+    notify(State, no_data),
+    {noreply, State#state{queue = queue:drop(Q)}};
+
+on_message(Error = {error, _}, State) ->
+    #state{queue = Q} = State,
+    notify(State, Error),
+    %% TODO wrong for squery at least
+    {noreply, State#state{queue = queue:drop(Q)}};
+
 %% NoticeResponse
 on_message({$N, Data}, State) ->
     notify_async(State, {notice, pgsql_wire:decode_error(Data)}),

+ 3 - 1
src/pgsql_wire.erl

@@ -3,9 +3,11 @@
 -export([decode_message/1,
          decode_error/1,
          decode_strings/1,
+         decode_columns/2,
          encode/1,
          encode/2,
-         encode_types/1]).
+         encode_types/1,
+         format/1]).
 
 -include("pgsql.hrl").
 -include("pgsql_binary.hrl").