Skip to content

Commit

Permalink
Merge pull request #11 from zmstone/fix-improve-error
Browse files Browse the repository at this point in the history
chore: improve error context
  • Loading branch information
zmstone authored Sep 30, 2024
2 parents 343d96a + d4191c2 commit bdc5036
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/commands/epgsql_cmd_prepared_query2.erl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ execute(Sock, #pquery2{name = Name, params = Params} = State) ->
},
{finish, {error, Error}, Sock};
#statement{types = Types} = Stmt ->
TypedParams = lists:zip(Types, Params),
TypedParams = zip(Name, Types, Params),
#statement{name = StatementName, columns = Columns} = Stmt,
Codec = epgsql_sock:get_codec(Sock),
Bin1 = epgsql_wire:encode_parameters(TypedParams, Codec),
Expand All @@ -58,6 +58,19 @@ execute(Sock, #pquery2{name = Name, params = Params} = State) ->
{send_multi, Commands, Sock, State#pquery2{stmt = Stmt}}
end.

zip(Name, Types, Params) ->
case length(Types) =:= length(Params) of
true ->
lists:zip(Types, Params);
false ->
error(#{cause => "prepared_data_types_and_column_count_mismatch",
name => Name,
types => Types,
type_count => length(Types),
column_count => length(Params)
})
end.

%% prepared query
handle_message(?BIND_COMPLETE, <<>>, Sock, #pquery2{stmt = Stmt} = State) ->
#statement{columns = Columns} = Stmt,
Expand Down

0 comments on commit bdc5036

Please sign in to comment.