Skip to content

Commit

Permalink
don't unwrap single element list for execute_batch
Browse files Browse the repository at this point in the history
  • Loading branch information
mabrek committed Mar 5, 2013
1 parent 3d08031 commit 9d57001
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/pgsql_sock.erl
Expand Up @@ -597,14 +597,15 @@ on_message({$I, _Bin}, State) ->
%% ReadyForQuery
on_message({$Z, <<Status:8>>}, State) ->
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
[Result] ->
finish(State, done, Result);
Results ->
finish(State, done, lists:reverse(Results))
end;
execute_batch ->
finish(State, done, lists:reverse(State#state.results));
equery ->
case State#state.results of
[Result] ->
Expand Down
5 changes: 1 addition & 4 deletions test_src/pgsql_incremental.erl
Expand Up @@ -95,10 +95,7 @@ execute(C, S, PortalName, N) ->

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

Expand Down
8 changes: 8 additions & 0 deletions test_src/pgsql_tests.erl
Expand Up @@ -173,6 +173,14 @@ batch_error_test(Module) ->
])
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) ->
with_connection(
Module,
Expand Down

0 comments on commit 9d57001

Please sign in to comment.