Skip to content

Commit

Permalink
Result set rows will return as tuples
Browse files Browse the repository at this point in the history
  • Loading branch information
maxlapshin committed Jan 9, 2010
1 parent 10909aa commit 42c772c
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/pgsql_util.erl
Original file line number Diff line number Diff line change
Expand Up @@ -241,20 +241,22 @@ decode_oid(Oid) ->


decode_row(Types, Values) ->
decode_row(Types, Values, []).
decode_row(Types, Values, {}).
decode_row([], [], Out) ->
{ok, lists:reverse(Out)};
{ok, Out};
decode_row([Type|TypeTail], [Value|ValueTail], Out0) ->
Out1 = decode_col(Type, Value),
decode_row(TypeTail, ValueTail, [Out1|Out0]).
decode_row(TypeTail, ValueTail, erlang:append_element(Out0, Out1)).

decode_col(_, null) ->
null;
decode_col(#desc{format=text, type=Int}, Value)
when Int =:= int2; Int =:= int4; Int =:= int8 ->
list_to_integer(binary_to_list(Value));
decode_col(#desc{format=text, type=varchar}, Value) ->
binary_to_list(Value);
Value;
decode_col(#desc{format=text, type=bpchar}, Value) ->
Value;
decode_col(#desc{format=text, type=Float}, Value)
when Float =:= float4; Float =:= float8 ->
list_to_float(binary_to_list(Value));
Expand Down

0 comments on commit 42c772c

Please sign in to comment.