anchor.diff:  
   -include("imem_meta.hrl").
   
  --export([ value_cast/8
  +-export([ value_to_db/8
  +        , db_to_string/4
           ]).
   
   -export([ pretty_type/1
  
positive.code: 
  %% ----- CAST Data from DB to string ------------------
  
  date_to_string(Datetime) ->
      date_to_string(Datetime, eu).
  
  
negative.code:         RO = true,
          RW = false,
          DefFun = fun() -> [{},{}] end,
          ?assertEqual(OldString, value_to_db(Item,OldString,StringType,Len,Prec,Def,RO,"NewVal")),
  
          ?assertEqual(<<"NewVal">>, value_to_db(Item,OldString,StringType,Len,Prec,Def,RW,<<"NewVal">>)),
          ?assertEqual([], value_to_db(Item,OldString,StringType,Len,Prec,Def,RW,"")),
          ?assertEqual({}, value_to_db(Item,OldString,StringType,Len,Prec,Def,RW,{})),
          ?assertEqual([atom,atom], value_to_db(Item,OldString,StringType,Len,Prec,Def,RW,[atom,atom])),
          ?assertEqual(12, value_to_db(Item,OldString,StringType,Len,Prec,Def,RW,12)),
          ?assertEqual(-3.14, value_to_db(Item,OldString,StringType,Len,Prec,Def,RW,-3.14)),
  
          ?assertEqual(OldString, value_to_db(Item,OldString,StringType,Len,Prec,Def,RW,OldString)),
          ?assertException(throw,{ClEr,{"Data conversion format error",{0,{string,3,"NewVal"}}}}, value_to_db(Item,OldString,StringType,Len,Prec,Def,RW,"NewVal")),
          ?assertEqual("NewVal", value_to_db(Item,OldString,StringType,6,Prec,Def,RW,"NewVal")),
          ?assertEqual("[NewVal]", value_to_db(Item,OldString,StringType,8,Prec,Def,RW,"[NewVal]")),
          ?assertEqual(default, value_to_db(Item,OldString,StringType,Len,Prec,Def,RW,"default")),
  
          ?assertEqual([{},{}], value_to_db(Item,OldString,StringType,Len,Prec,DefFun,RW,"[{},{}]")),
  
          ?assertEqual(oldValue, value_to_db(Item,oldValue,StringType,Len,Prec,Def,RW,"oldValue")),
          ?assertEqual('OldValue', value_to_db(Item,'OldValue',StringType,Len,Prec,Def,RW,"'OldValue'")),
          ?assertEqual(-15, value_to_db(Item,-15,StringType,Len,Prec,Def,RW,"-15")),
  
          IntegerType = integer,
          OldInteger = 17,
          ?assertEqual(OldString, value_to_db(Item,OldString,IntegerType,Len,Prec,Def,RW,"OldString")),
          ?assertEqual(OldInteger, value_to_db(Item,OldInteger,IntegerType,Len,Prec,Def,RW,"17")),
          ?assertEqual(default, value_to_db(Item,OldInteger,IntegerType,Len,Prec,Def,RW,"default")),
          ?assertEqual(18, value_to_db(Item,OldInteger,IntegerType,Len,Prec,Def,RW,"18")),
          ?assertEqual(-18, value_to_db(Item,OldInteger,IntegerType,Len,Prec,Def,RW,"-18")),
          ?assertEqual(100, value_to_db(Item,OldInteger,IntegerType,Len,-2,Def,RW,"149")),
          ?assertEqual(200, value_to_db(Item,OldInteger,IntegerType,Len,-2,Def,RW,"150")),
          ?assertEqual(-100, value_to_db(Item,OldInteger,IntegerType,4,-2,Def,RW,"-149")),
          ?assertEqual(-200, value_to_db(Item,OldInteger,IntegerType,4,-2,Def,RW,"-150")),
          ?assertEqual(-200, value_to_db(Item,OldInteger,IntegerType,100,0,Def,RW,"300-500")),
          ?assertEqual(12, value_to_db(Item,OldInteger,IntegerType,20,0,Def,RW,"120/10.0")),
          ?assertEqual(12, value_to_db(Item,OldInteger,IntegerType,20,0,Def,RW,"120/10.0001")),
          ?assertException(throw, {ClEr,{"Data conversion format error",{0,{integer,3,1,"1234"}}}}, value_to_db(Item,OldInteger,IntegerType,Len,Prec,Def,RW,"1234")),
          ?assertException(throw, {ClEr,{"Data conversion format error",{0,{integer,"-"}}}}, value_to_db(Item,OldInteger,IntegerType,Len,Prec,Def,RW,"-")),
          ?assertException(throw, {ClEr,{"Data conversion format error",{0,{integer,""}}}}, value_to_db(Item,OldInteger,IntegerType,Len,Prec,Def,RW,"")),
          ?assertException(throw, {ClEr,{"Data conversion format error",{0,{integer,3,1,"-100"}}}}, value_to_db(Item,OldInteger,IntegerType,Len,Prec,Def,RW,"-100")),
          ?assertException(throw, {ClEr,{"Data conversion format error",{0,{integer,3,1,"9999"}}}}, value_to_db(Item,OldInteger,IntegerType,Len,Prec,Def,RW,"9999")),
  
          FloatType = float,
          OldFloat = -1.2,
          ?assertEqual(8.1, value_to_db(Item,OldFloat,FloatType,Len,Prec,Def,RW,"8.1")),
          ?assertEqual(18.0, value_to_db(Item,OldFloat,FloatType,Len,Prec,Def,RW,"18")),
          ?assertEqual(1.1, value_to_db(Item,OldFloat,FloatType,Len,Prec,Def,RW,"1.12")),
          ?assertEqual(-1.1, value_to_db(Item,OldFloat,FloatType,Len,Prec,Def,RW,"-1.14")),
          ?assertEqual(-1.1, value_to_db(Item,OldFloat,FloatType,Len,Prec,Def,RW,"-1.1234567")),
          ?assertEqual(-1.12, value_to_db(Item,OldFloat,FloatType,Len,2,Def,RW,"-1.1234567")),
          ?assertEqual(-1.123, value_to_db(Item,OldFloat,FloatType,Len,3,Def,RW,"-1.1234567")),
          ?assertEqual(-1.1235, value_to_db(Item,OldFloat,FloatType,Len,4,Def,RW,"-1.1234567")),
          %% ?assertEqual(-1.12346, value_to_db(Item,OldFloat,FloatType,Len,5,Def,RW,"-1.1234567")),  %% fails due to single precision math
          %% ?assertEqual(-1.123457, value_to_db(Item,OldFloat,FloatType,Len,6,Def,RW,"-1.1234567")), %% fails due to single precision math
          ?assertEqual(100.0, value_to_db(Item,OldFloat,FloatType,Len,-2,Def,RW,"149")),
          ?assertEqual(-100.0, value_to_db(Item,OldFloat,FloatType,Len,-2,Def,RW,"-149")),
          ?assertEqual(-200.0, value_to_db(Item,OldFloat,FloatType,Len,-2,Def,RW,"-150")),
          %% ?assertEqual(0.6, value_to_db(Item,OldFloat,FloatType,Len,Prec,Def,RW,"0.56")),
          %% ?assertEqual(0.6, value_to_db(Item,OldFloat,FloatType,Len,Prec,Def,RW,"0.5678")),
          %% ?assertEqual(0.6, value_to_db(Item,OldFloat,FloatType,Len,Prec,Def,RW,"0.5678910111")),
          %% ?assertEqual(0.6, value_to_db(Item,OldFloat,FloatType,Len,Prec,Def,RW,"0.56789101112131415")),
          ?assertEqual(1234.5, value_to_db(Item,OldFloat,FloatType,Len,Prec,Def,RW,"1234.5")),
          %% ?assertEqual(1234.6, value_to_db(Item,OldFloat,FloatType,Len,Prec,Def,RW,"1234.56")),
          %% ?assertEqual(1234.6, value_to_db(Item,OldFloat,FloatType,Len,Prec,Def,RW,"1234.5678")),
          %% ?assertEqual(1234.6, value_to_db(Item,OldFloat,FloatType,Len,Prec,Def,RW,"1234.5678910111")),
          %% ?assertEqual(1234.6, value_to_db(Item,OldFloat,FloatType,Len,Prec,Def,RW,"1234.56789101112131415")),
  
          DecimalType = decimal,
          OldDecimal = -123,
          ?assertEqual(81, value_to_db(Item,OldDecimal,DecimalType,Len,Prec,Def,RW,"8.1")),
          ?assertEqual(180, value_to_db(Item,OldDecimal,DecimalType,Len,Prec,Def,RW,"18.001")),
          ?assertEqual(1, value_to_db(Item,OldDecimal,DecimalType,1,0,Def,RW,"1.12")),
          ?assertException(throw, {ClEr,{"Data conversion format error",{0,{decimal,5,5,"-1.123"}}}}, value_to_db(Item,OldDecimal,DecimalType,5,5,Def,RW,"-1.123")),
          ?assertEqual(-112300, value_to_db(Item,OldDecimal,DecimalType,7,5,Def,RW,"-1.123")),
          ?assertEqual(-112346, value_to_db(Item,OldDecimal,DecimalType,7,5,Def,RW,"-1.1234567")),
          ?assertException(throw, {ClEr,{"Data conversion format error",{0,{decimal,5,Prec,"1234567.89"}}}}, value_to_db(Item,OldDecimal,DecimalType,5,Prec,Def,RW,"1234567.89")),
  
          ETermType = eterm,
          OldETerm = {-1.2,[a,b,c]},
          ?assertEqual(OldETerm, value_to_db(Item,OldETerm,ETermType,Len,Prec,Def,RW,OldETerm)),
          ?assertEqual(default, value_to_db(Item,OldETerm,ETermType,Len,Prec,Def,RW,"default")),
          ?assertEqual([a,b], value_to_db(Item,OldETerm,ETermType,Len,Prec,Def,RW,"[a,b]")),
          ?assertEqual(-1.1234567, value_to_db(Item,OldETerm,ETermType,Len,Prec,Def,RW,"-1.1234567")),
          ?assertEqual({[1,2,3]}, value_to_db(Item,OldETerm,ETermType,Len,Prec,Def,RW,"{[1,2,3]}")),
          ?assertException(throw, {ClEr,{"Data conversion format error",{0,{eTerm,"[a|]"}}}}, value_to_db(Item,OldETerm,ETermType,Len,Prec,Def,RW,"[a|]")),
  
          ?assertEqual({1,2,3}, value_to_db(Item,OldETerm,eTuple,Len,Prec,Def,RW,"{1,2,3}")),
          ?assertEqual({}, value_to_db(Item,OldETerm,eTuple,0,Prec,Def,RW,"{}")),
          ?assertEqual({1}, value_to_db(Item,OldETerm,eTuple,0,Prec,Def,RW,"{1}")),
          ?assertEqual({1,2}, value_to_db(Item,OldETerm,eTuple,0,Prec,Def,RW,"{1,2}")),
          ?assertException(throw, {ClEr,{"Data conversion format error",{0,{eTuple,Len,"[a]"}}}}, value_to_db(Item,OldETerm,etuple,Len,Prec,Def,RW,"[a]")),
          ?assertException(throw, {ClEr,{"Data conversion format error",{0,{eTuple,Len,"{a}"}}}}, value_to_db(Item,OldETerm,etuple,Len,Prec,Def,RW,"{a}")),
  
          ?assertEqual([a,b,c], value_to_db(Item,OldETerm,elist,Len,Prec,Def,RW,"[a,b,c]")),
          ?assertException(throw, {ClEr,{"Data conversion format error",{0,{eList,Len,"[a]"}}}}, value_to_db(Item,OldETerm,elist,Len,Prec,Def,RW,"[a]")),
          ?assertEqual([], value_to_db(Item,[],eList,Len,Prec,Def,RW,"[]")),
          ?assertEqual([], value_to_db(Item,OldETerm,eList,Len,Prec,[],RW,"[]")),
          ?assertEqual([], value_to_db(Item,OldETerm,eList,0,Prec,Def,RW,"[]")),
          ?assertEqual([a], value_to_db(Item,OldETerm,eList,0,Prec,Def,RW,"[a]")),
          ?assertEqual([a,b], value_to_db(Item,OldETerm,eList,0,Prec,Def,RW,"[a,b]")),
  
          ?assertEqual({10,132,7,92}, value_to_db(Item,OldETerm,eipaddr,0,Prec,Def,RW,"10.132.7.92")),
          ?assertEqual({0,0,0,0}, value_to_db(Item,OldETerm,eipaddr,4,Prec,Def,RW,"0.0.0.0")),
          ?assertEqual({255,255,255,255}, value_to_db(Item,OldETerm,eipaddr,4,Prec,Def,RW,"255.255.255.255")),
          ?assertException(throw, {ClEr,{"Data conversion format error",{0,{eIpaddr,0,"1.2.3.4.5"}}}}, value_to_db(Item,OldETerm,eipaddr,0,0,Def,RW,"1.2.3.4.5")),
          ?assertException(throw, {ClEr,{"Data conversion format error",{0,{eIpaddr,4,"1.2.-1.4"}}}}, value_to_db(Item,OldETerm,eipaddr,4,0,Def,RW,"1.2.-1.4")),
          ?assertException(throw, {ClEr,{"Data conversion format error",{0,{eIpaddr,6,"1.256.1.4"}}}}, value_to_db(Item,OldETerm,eipaddr,6,0,Def,RW,"1.256.1.4")),
          ?assertException(throw, {ClEr,{"Data conversion format error",{0,{eIpaddr,8,"1.2.1.4"}}}}, value_to_db(Item,OldETerm,eipaddr,8,0,Def,RW,"1.2.1.4")),
  
          Fun = fun(X) -> X*X end,
          io:format(user, "Fun ~p~n", [Fun]),
          Res = value_to_db(Item,OldETerm,efun,1,Prec,Def,RW,"fun(X) -> X*X end"),
          io:format(user, "Run ~p~n", [Res]),
          ?assertEqual(Fun(4), Res(4)),
  
  