Browse Source

don't stop on error in case of squery, equery

Anton Lebedevich 13 years ago
parent
commit
76e92c5a69
1 changed files with 12 additions and 4 deletions
  1. 12 4
      src/pgsql_sock.erl

+ 12 - 4
src/pgsql_sock.erl

@@ -239,6 +239,10 @@ notify_async(#state{async = Pid}, Msg) ->
         false -> false
         false -> false
     end.
     end.
 
 
+request_tag(#state{queue = Q} = State) ->
+    {_, Req} = queue:get(Q),
+    element(1, Req).
+
 %% -- backend message handling --
 %% -- backend message handling --
 
 
 %% AuthenticationOk
 %% AuthenticationOk
@@ -325,8 +329,7 @@ on_message({$T, <<Count:?int16, Bin/binary>>}, State) ->
     Columns = pgsql_wire:decode_columns(Count, Bin),
     Columns = pgsql_wire:decode_columns(Count, Bin),
     Columns2 = [C#column{format = pgsql_wire:format(C#column.type)} || C <- Columns],
     Columns2 = [C#column{format = pgsql_wire:format(C#column.type)} || C <- Columns],
     notify(State, {columns, Columns2}),
     notify(State, {columns, Columns2}),
-    {_, Req} = queue:get(Q),
-    State2 = case element(1, Req) of
+    State2 = case request_tag(State) of
                  C when C == squery ->
                  C when C == squery ->
                      State#state{columns = Columns2};
                      State#state{columns = Columns2};
                  C when C == parse ->
                  C when C == parse ->
@@ -382,8 +385,13 @@ on_message({$Z, <<_Status:8>>}, State) ->
 on_message(Error = {error, _}, State) ->
 on_message(Error = {error, _}, State) ->
     #state{queue = Q} = State,
     #state{queue = Q} = State,
     notify(State, Error),
     notify(State, Error),
-    %% TODO wrong for squery at least
-    {noreply, State#state{queue = queue:drop(Q)}};
+    State2 = case request_tag(State) of
+                 C when C == squery; C == equery ->
+                     State;
+                 _ ->
+                     State#state{queue = queue:drop(Q)}
+             end,
+    {noreply, State2};
 
 
 %% NoticeResponse
 %% NoticeResponse
 on_message({$N, Data}, State) ->
 on_message({$N, Data}, State) ->