Browse Source

handle an error in the middle of execute_batch

Anton Lebedevich 12 years ago
parent
commit
a8ae354347
2 changed files with 8 additions and 6 deletions
  1. 1 1
      src/pgsql_sock.erl
  2. 7 5
      test_src/pgsql_tests.erl

+ 1 - 1
src/pgsql_sock.erl

@@ -618,7 +618,7 @@ on_message({$Z, <<Status:8>>}, State) ->
 
 on_message(Error = {error, _}, State) ->
     State2 = case command_tag(State) of
-                 C when C == squery; C == equery ->
+                 C when C == squery; C == equery; C == execute_batch ->
                      add_result(State, Error, Error);
                  _ ->
                      sync_required(finish(State, Error))

+ 7 - 5
test_src/pgsql_tests.erl

@@ -164,11 +164,13 @@ batch_error_test(Module) ->
       Module,
       fun(C) ->
               {ok, S} = Module:parse(C, "insert into test_table1(id, value) values($1, $2)"),
-              [{ok, 1}, {ok, 1}, {ok, 1}] =
-                  Module:execute_batch(C, [{S, [3, "batch_error 3"]},
-                                           {S, [2, "batch_error 2"]}, % duplicate key here
-                                           {S, [5, "batch_error 5"]}
-                                           ])
+              [{ok, 1}, {error, _}] =
+                  Module:execute_batch(
+                    C,
+                    [{S, [3, "batch_error 3"]},
+                     {S, [2, "batch_error 2"]}, % duplicate key error
+                     {S, [5, "batch_error 5"]}  % won't be executed
+                    ])
       end).
 
 extended_select_test(Module) ->