Browse Source

Merge upstream 'wg/master'

Anton Lebedevich 13 years ago
parent
commit
8cebeb9bb9
3 changed files with 28 additions and 13 deletions
  1. 7 1
      src/pgsql_binary.erl
  2. 2 0
      src/pgsql_types.erl
  3. 19 12
      test_src/pgsql_tests.erl

+ 7 - 1
src/pgsql_binary.erl

@@ -31,6 +31,8 @@ encode(boolarray, L) when is_list(L)        -> encode_array(bool, L);
 encode(int2array, L) when is_list(L)        -> encode_array(int2, L);
 encode(int2array, L) when is_list(L)        -> encode_array(int2, L);
 encode(int4array, L) when is_list(L)        -> encode_array(int4, L);
 encode(int4array, L) when is_list(L)        -> encode_array(int4, L);
 encode(int8array, L) when is_list(L)        -> encode_array(int8, 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(chararray, L) when is_list(L)        -> encode_array(bpchar, L);
 encode(textarray, L) when is_list(L)        -> encode_array(text, 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));
 encode(Type, L) when is_list(L)             -> encode(Type, list_to_binary(L));
@@ -55,6 +57,8 @@ decode(boolarray, B)                        -> decode_array(B);
 decode(int2array, B)                        -> decode_array(B);
 decode(int2array, B)                        -> decode_array(B);
 decode(int4array, B)                        -> decode_array(B);
 decode(int4array, B)                        -> decode_array(B);
 decode(int8array, 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(chararray, B)                        -> decode_array(B);
 decode(textarray, B)                        -> decode_array(B);
 decode(textarray, B)                        -> decode_array(B);
 decode(_Other, Bin)                         -> Bin.
 decode(_Other, Bin)                         -> Bin.
@@ -62,7 +66,7 @@ decode(_Other, Bin)                         -> Bin.
 encode_array(Type, A) ->
 encode_array(Type, A) ->
     {Data, {NDims, Lengths}} = encode_array(Type, A, 0, []),
     {Data, {NDims, Lengths}} = encode_array(Type, A, 0, []),
     Oid  = pgsql_types:type2oid(Type),
     Oid  = pgsql_types:type2oid(Type),
-    Lens = [<<N:?int32, 0:?int32>> || N <- lists:reverse(Lengths)],
+    Lens = [<<N:?int32, 1:?int32>> || N <- lists:reverse(Lengths)],
     Hdr  = <<NDims:?int32, 0:?int32, Oid:?int32>>,
     Hdr  = <<NDims:?int32, 0:?int32, Oid:?int32>>,
     Bin  = iolist_to_binary([Hdr, Lens, Data]),
     Bin  = iolist_to_binary([Hdr, Lens, Data]),
     <<(byte_size(Bin)):?int32, Bin/binary>>.
     <<(byte_size(Bin)):?int32, Bin/binary>>.
@@ -131,6 +135,8 @@ supports(boolarray)   -> true;
 supports(int2array)   -> true;
 supports(int2array)   -> true;
 supports(int4array)   -> true;
 supports(int4array)   -> true;
 supports(int8array)   -> true;
 supports(int8array)   -> true;
+supports(float4array) -> true;
+supports(float8array) -> true;
 supports(chararray)   -> true;
 supports(chararray)   -> true;
 supports(textarray)   -> true;
 supports(textarray)   -> true;
 supports(_Type)       -> false.
 supports(_Type)       -> false.

+ 2 - 0
src/pgsql_types.erl

@@ -46,6 +46,7 @@ oid2type(1009) -> textarray;
 oid2type(1014) -> chararray;
 oid2type(1014) -> chararray;
 oid2type(1016) -> int8array;
 oid2type(1016) -> int8array;
 oid2type(1021) -> float4array;
 oid2type(1021) -> float4array;
+oid2type(1022) -> float8array;
 oid2type(1033) -> aclitem;
 oid2type(1033) -> aclitem;
 oid2type(1263) -> cstringarray;
 oid2type(1263) -> cstringarray;
 oid2type(1042) -> bpchar;
 oid2type(1042) -> bpchar;
@@ -129,6 +130,7 @@ type2oid(textarray)             -> 1009;
 type2oid(chararray)             -> 1014;
 type2oid(chararray)             -> 1014;
 type2oid(int8array)             -> 1016;
 type2oid(int8array)             -> 1016;
 type2oid(float4array)           -> 1021;
 type2oid(float4array)           -> 1021;
+type2oid(float8array)           -> 1022;
 type2oid(aclitem)               -> 1033;
 type2oid(aclitem)               -> 1033;
 type2oid(cstringarray)          -> 1263;
 type2oid(cstringarray)          -> 1263;
 type2oid(bpchar)                -> 1042;
 type2oid(bpchar)                -> 1042;

+ 19 - 12
test_src/pgsql_tests.erl

@@ -480,19 +480,26 @@ array_type_test(Module) ->
     with_connection(
     with_connection(
       Module,
       Module,
       fun(C) ->
       fun(C) ->
-          Select = fun(Type, V) ->
-                       Query = "select $1::" ++ Type,
-                       {ok, _Cols, [{V}]} = Module:equery(C, Query, [V])
+          {ok, _, [{[1, 2]}]} = Module:equery(C, "select ($1::int[])[1:2]", [[1, 2, 3]]),
+          Select = fun(Type, A) ->
+                       Query = "select $1::" ++ atom_to_list(Type) ++ "[]",
+                       {ok, _Cols, [{A2}]} = Module: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,
                    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).
       end).
 
 
 text_format_test(Module) ->
 text_format_test(Module) ->