Browse Source

Actually add support for binary int4range and int8range.

Alexander Sedov 8 years ago
parent
commit
f324274dae
3 changed files with 5 additions and 19 deletions
  1. 2 0
      src/epgsql_binary.erl
  2. 1 0
      test/data/test_schema.sql
  3. 2 19
      test/epgsql_tests.erl

+ 2 - 0
src/epgsql_binary.erl

@@ -332,4 +332,6 @@ supports({array, inet})   -> true;
 supports({array, record}) -> true;
 supports({array, record}) -> true;
 supports({array, json})   -> true;
 supports({array, json})   -> true;
 supports({array, jsonb})   -> true;
 supports({array, jsonb})   -> true;
+supports(int4range)       -> true;
+supports(int8range)       -> true;
 supports(_Type)       -> false.
 supports(_Type)       -> false.

+ 1 - 0
test/data/test_schema.sql

@@ -65,6 +65,7 @@ CREATE TABLE test_table2 (
   c_cidr cidr,
   c_cidr cidr,
   c_inet inet,
   c_inet inet,
   c_int4range int4range,
   c_int4range int4range,
+  c_int8range int8range,
   c_json json,
   c_json json,
   c_jsonb jsonb);
   c_jsonb jsonb);
 
 

+ 2 - 19
test/epgsql_tests.erl

@@ -959,7 +959,7 @@ range_type_test(Module) ->
       Module,
       Module,
       9.2,
       9.2,
       fun(_C) ->
       fun(_C) ->
-          check_type(Module, int4range, "int4range(10, 20)", <<"[10,20)">>,
+          check_type(Module, int4range, "int4range(10, 20)", {10, 20},
                      [{1, 58}, {-1, 12}, {-985521, 5412687}, {minus_infinity, 0},
                      [{1, 58}, {-1, 12}, {-985521, 5412687}, {minus_infinity, 0},
                       {984655, plus_infinity}, {minus_infinity, plus_infinity}])
                       {984655, plus_infinity}, {minus_infinity, plus_infinity}])
       end,
       end,
@@ -970,7 +970,7 @@ range8_type_test(Module) ->
       Module,
       Module,
       9.2,
       9.2,
       fun(_C) ->
       fun(_C) ->
-          check_type(Module, int8range, "int8range(10, 20)", <<"[10,20)">>,
+          check_type(Module, int8range, "int8range(10, 20)", {10, 20},
                      [{1, 58}, {-1, 12}, {-985521, 5412687}, {minus_infinity, 0},
                      [{1, 58}, {-1, 12}, {-985521, 5412687}, {minus_infinity, 0},
                       {984655, plus_infinity}, {minus_infinity, plus_infinity}])
                       {984655, plus_infinity}, {minus_infinity, plus_infinity}])
       end,
       end,
@@ -1120,25 +1120,8 @@ compare(Type, V1 = {_, _, MS}, {D2, {H2, M2, S2}}) when Type == timestamp;
                                                         Type == timestamptz ->
                                                         Type == timestamptz ->
     {D1, {H1, M1, S1}} = calendar:now_to_universal_time(V1),
     {D1, {H1, M1, S1}} = calendar:now_to_universal_time(V1),
     ({D1, H1, M1} =:= {D2, H2, M2}) and (abs(S1 + MS/1000000 - S2) < 0.000000000000001);
     ({D1, H1, M1} =:= {D2, H2, M2}) and (abs(S1 + MS/1000000 - S2) < 0.000000000000001);
-compare(int4range, {Lower, Upper}, Result) ->
-  translate_infinities(Lower, Upper) =:= Result;
-compare(int8range, {Lower, Upper}, Result) ->
-  translate_infinities(Lower, Upper) =:= Result;
 compare(_Type, V1, V2)     -> V1 =:= V2.
 compare(_Type, V1, V2)     -> V1 =:= V2.
 
 
-translate_infinities(Lower, Upper) ->
-  iolist_to_binary([lower(Lower), [","], upper(Upper)]).
-
-lower(minus_infinity) ->
-  "(";
-lower(Val) ->
-  io_lib:format("[~p", [Val]).
-
-upper(plus_infinity) ->
-  ")";
-upper(Val) ->
-  io_lib:format("~p)", [Val]).
-
 format_hstore({Hstore}) -> Hstore;
 format_hstore({Hstore}) -> Hstore;
 format_hstore(Hstore) ->
 format_hstore(Hstore) ->
     [{format_hstore_key(Key), format_hstore_value(Value)} || {Key, Value} <- Hstore].
     [{format_hstore_key(Key), format_hstore_value(Value)} || {Key, Value} <- Hstore].