Просмотр исходного кода

Merge pull request #61 from egobrain/array-of-record

Array of record type support
David N. Welton 9 лет назад
Родитель
Сommit
f12520bfc2
3 измененных файлов с 5 добавлено и 0 удалено
  1. 1 0
      src/epgsql_binary.erl
  2. 2 0
      src/epgsql_types.erl
  3. 2 0
      test/epgsql_tests.erl

+ 1 - 0
src/epgsql_binary.erl

@@ -301,4 +301,5 @@ supports({array, varchar}) -> true;
 supports({array, uuid})   -> true;
 supports({array, cidr})   -> true;
 supports({array, inet})   -> true;
+supports({array, record}) -> true;
 supports(_Type)       -> false.

+ 2 - 0
src/epgsql_types.erl

@@ -91,6 +91,7 @@ oid2type(2280)  -> language_handler;
 oid2type(2281)  -> internal;
 oid2type(2282)  -> opaque;
 oid2type(2283)  -> anyelement;
+oid2type(2287)  -> {array, record};
 oid2type(2776)  -> anynonarray;
 oid2type(2950)  -> uuid;
 oid2type(2951)  -> {array, uuid};
@@ -187,6 +188,7 @@ type2oid(language_handler)      -> 2280;
 type2oid(internal)              -> 2281;
 type2oid(opaque)                -> 2282;
 type2oid(anyelement)            -> 2283;
+type2oid({array, record})       -> 2287;
 type2oid(anynonarray)           -> 2776;
 type2oid(uuid)                  -> 2950;
 type2oid({array, uuid})         -> 2951;

+ 2 - 0
test/epgsql_tests.erl

@@ -599,6 +599,8 @@ array_type_test(Module) ->
       Module,
       fun(C) ->
           {ok, _, [{[1, 2]}]} = Module:equery(C, "select ($1::int[])[1:2]", [[1, 2, 3]]),
+          {ok, _, [{[{1, <<"one">>}, {2, <<"two">>}]}]} =
+              Module:equery(C, "select Array(select (id, value) from test_table1)", []),
           Select = fun(Type, A) ->
                        Query = "select $1::" ++ atom_to_list(Type) ++ "[]",
                        {ok, _Cols, [{A2}]} = Module:equery(C, Query, [A]),