diff --git a/README b/README index c24c499..4f99f77 100644 --- a/README +++ b/README @@ -20,7 +20,8 @@ Erlang PostgreSQL Database Client ok = pgsql:close(C). The timeout parameter will trigger an {error, timeout} result when the - server fails to respond within Timeout milliseconds. + server fails to respond within Timeout milliseconds. This timeout applies + to the initial connection attempt and any subsequent queries. * Simple Query diff --git a/src/pgsql_binary.erl b/src/pgsql_binary.erl index a5d0909..782a92a 100644 --- a/src/pgsql_binary.erl +++ b/src/pgsql_binary.erl @@ -30,6 +30,8 @@ encode(boolarray, L) when is_list(L) -> encode_array(bool, L); encode(int2array, L) when is_list(L) -> encode_array(int2, L); encode(int4array, L) when is_list(L) -> encode_array(int4, L); encode(int8array, L) when is_list(L) -> encode_array(int8, L); +encode(float4array, L) when is_list(L) -> encode_array(float4, L); +encode(float8array, L) when is_list(L) -> encode_array(float8, L); encode(chararray, L) when is_list(L) -> encode_array(bpchar, L); encode(textarray, L) when is_list(L) -> encode_array(text, L); encode(Type, L) when is_list(L) -> encode(Type, list_to_binary(L)); @@ -54,6 +56,8 @@ decode(boolarray, B) -> decode_array(B); decode(int2array, B) -> decode_array(B); decode(int4array, B) -> decode_array(B); decode(int8array, B) -> decode_array(B); +decode(float4array, B) -> decode_array(B); +decode(float8array, B) -> decode_array(B); decode(chararray, B) -> decode_array(B); decode(textarray, B) -> decode_array(B); decode(_Other, Bin) -> Bin. @@ -61,7 +65,7 @@ decode(_Other, Bin) -> Bin. encode_array(Type, A) -> {Data, {NDims, Lengths}} = encode_array(Type, A, 0, []), Oid = pgsql_types:type2oid(Type), - Lens = [<> || N <- lists:reverse(Lengths)], + Lens = [<> || N <- lists:reverse(Lengths)], Hdr = <>, Bin = iolist_to_binary([Hdr, Lens, Data]), <<(byte_size(Bin)):?int32, Bin/binary>>. @@ -130,6 +134,8 @@ supports(boolarray) -> true; supports(int2array) -> true; supports(int4array) -> true; supports(int8array) -> true; +supports(float4array) -> true; +supports(float8array) -> true; supports(chararray) -> true; supports(textarray) -> true; supports(_Type) -> false. diff --git a/src/pgsql_types.erl b/src/pgsql_types.erl index b4a1d5b..d81971c 100644 --- a/src/pgsql_types.erl +++ b/src/pgsql_types.erl @@ -46,6 +46,7 @@ oid2type(1009) -> textarray; oid2type(1014) -> chararray; oid2type(1016) -> int8array; oid2type(1021) -> float4array; +oid2type(1022) -> float8array; oid2type(1033) -> aclitem; oid2type(1263) -> cstringarray; oid2type(1042) -> bpchar; @@ -129,6 +130,7 @@ type2oid(textarray) -> 1009; type2oid(chararray) -> 1014; type2oid(int8array) -> 1016; type2oid(float4array) -> 1021; +type2oid(float8array) -> 1022; type2oid(aclitem) -> 1033; type2oid(cstringarray) -> 1263; type2oid(bpchar) -> 1042; diff --git a/test_src/pgsql_tests.erl b/test_src/pgsql_tests.erl index d2814ed..8404549 100644 --- a/test_src/pgsql_tests.erl +++ b/test_src/pgsql_tests.erl @@ -427,19 +427,26 @@ misc_type_test() -> array_type_test() -> with_connection( fun(C) -> - Select = fun(Type, V) -> - Query = "select $1::" ++ Type, - {ok, _Cols, [{V}]} = pgsql:equery(C, Query, [V]) + {ok, _, [{[1, 2]}]} = pgsql:equery(C, "select ($1::int[])[1:2]", [[1, 2, 3]]), + Select = fun(Type, A) -> + Query = "select $1::" ++ atom_to_list(Type) ++ "[]", + {ok, _Cols, [{A2}]} = pgsql:equery(C, Query, [A]), + case lists:all(fun({V, V2}) -> compare(Type, V, V2) end, lists:zip(A, A2)) of + true -> ok; + false -> ?assertMatch(A, A2) + end end, - Select("int2[]", []), - Select("int2[]", [1, 2, 3, 4]), - Select("int2[]", [[1], [2], [3], [4]]), - Select("int2[]", [[[[[[1, 2]]]]]]), - Select("bool[]", [true]), - Select("char[]", [$a, $b, $c]), - Select("int4[]", [[1, 2]]), - Select("int8[]", [[[[1, 2]], [[3, 4]]]]), - Select("text[]", [<<"one">>, <<"two>">>]) + Select(int2, []), + Select(int2, [1, 2, 3, 4]), + Select(int2, [[1], [2], [3], [4]]), + Select(int2, [[[[[[1, 2]]]]]]), + Select(bool, [true]), + Select(char, [$a, $b, $c]), + Select(int4, [[1, 2]]), + Select(int8, [[[[1, 2]], [[3, 4]]]]), + Select(text, [<<"one">>, <<"two>">>]), + Select(float4, [0.0, 1.0, 0.123]), + Select(float8, [0.0, 1.0, 0.123]) end). text_format_test() ->