Browse files

add support for float4 and float8 arrays

  • Loading branch information...
1 parent fc43477 commit 4c8f96cdc225f5684f557150000ebe1583774f78 @wg committed Mar 7, 2012
Showing with 28 additions and 13 deletions.
  1. +2 −1 README
  2. +6 −0 src/pgsql_binary.erl
  3. +2 −0 src/pgsql_types.erl
  4. +18 −12 test_src/pgsql_tests.erl
View
3 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
View
6 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.
@@ -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.
View
2 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;
View
30 test_src/pgsql_tests.erl
@@ -427,19 +427,25 @@ 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])
+ 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() ->

0 comments on commit 4c8f96c

Please sign in to comment.