Browse Source

don't unwrap single element list for execute_batch

Anton Lebedevich 12 years ago
parent
commit
9d5700173b
3 changed files with 12 additions and 6 deletions
  1. 3 2
      src/pgsql_sock.erl
  2. 1 4
      test_src/pgsql_incremental.erl
  3. 8 0
      test_src/pgsql_tests.erl

+ 3 - 2
src/pgsql_sock.erl

@@ -597,14 +597,15 @@ on_message({$I, _Bin}, State) ->
 %% ReadyForQuery
 %% ReadyForQuery
 on_message({$Z, <<Status:8>>}, State) ->
 on_message({$Z, <<Status:8>>}, State) ->
     State2 = case command_tag(State) of
     State2 = case command_tag(State) of
-                 %% TODO don't unwrap single element list for execute_batch
-                 C when C == squery; C == execute_batch ->
+                 squery ->
                      case State#state.results of
                      case State#state.results of
                          [Result] ->
                          [Result] ->
                              finish(State, done, Result);
                              finish(State, done, Result);
                          Results ->
                          Results ->
                              finish(State, done, lists:reverse(Results))
                              finish(State, done, lists:reverse(Results))
                      end;
                      end;
+                 execute_batch ->
+                     finish(State, done, lists:reverse(State#state.results));
                  equery ->
                  equery ->
                      case State#state.results of
                      case State#state.results of
                          [Result] ->
                          [Result] ->

+ 1 - 4
test_src/pgsql_incremental.erl

@@ -95,10 +95,7 @@ execute(C, S, PortalName, N) ->
 
 
 execute_batch(C, Batch) ->
 execute_batch(C, Batch) ->
     Ref = ipgsql:execute_batch(C, Batch),
     Ref = ipgsql:execute_batch(C, Batch),
-    case receive_extended_results(C, Ref, []) of
-        [Result] -> Result;
-        Results  -> Results
-    end.
+    receive_extended_results(C, Ref, []).
 
 
 %% statement/portal functions
 %% statement/portal functions
 
 

+ 8 - 0
test_src/pgsql_tests.erl

@@ -173,6 +173,14 @@ batch_error_test(Module) ->
                     ])
                     ])
       end).
       end).
 
 
+single_batch_test(Module) ->
+    with_connection(
+      Module,
+      fun(C) ->
+              {ok, S1} = Module:parse(C, "one", "select $1", [int4]),
+              [{ok, [{1}]}] = Module:execute_batch(C, [{S1, [1]}])
+      end).
+
 extended_select_test(Module) ->
 extended_select_test(Module) ->
     with_connection(
     with_connection(
       Module,
       Module,