public static void Serialize(SqlTypeCode typeCode, int precision, int scale) { var type = new SqlNumericType(typeCode, precision, scale); var result = BinarySerializeUtil.Serialize(type); Assert.Equal(type, result); }
public static void IsInstanceOf(SqlTypeCode typeCode, int?precision, byte?scale, object value, bool expected) { var type = new SqlNumericType(typeCode, precision ?? -1, scale ?? -1); var number = SqlValueUtil.FromObject(value); Assert.Equal(expected, type.IsInstanceOf(number)); }
public static void CreateNumericType(SqlTypeCode typeCode, int precision, int scale) { var type = new SqlNumericType(typeCode, precision, scale); Assert.NotNull(type); Assert.Equal(typeCode, type.TypeCode); Assert.Equal(precision, type.Precision); Assert.Equal(scale, type.Scale); Assert.True(type.IsIndexable); Assert.True(type.IsPrimitive); Assert.False(type.IsLargeObject); Assert.False(type.IsReference); }
public static void CastToNumber(string s, SqlTypeCode typeCode, int precision, int scale) { var date = SqlDateTime.Parse(s); var type = new SqlDateTimeType(SqlTypeCode.DateTime); var destType = new SqlNumericType(typeCode, precision, scale); Assert.True(type.CanCastTo(date, destType)); var result = type.Cast(date, destType); Assert.NotNull(result); Assert.IsType <SqlNumber>(result); var value = (SqlNumber)result; var back = new SqlDateTime((long)value); Assert.Equal(date, back); }
private ISqlValue ToNumber(ISqlBinary value, SqlNumericType destType) { if (value == null) { throw new InvalidCastException(); } var precision = destType.Precision; var scale = destType.Scale; if (precision <= 0) { throw new NotSupportedException(); } if (scale <= 0) { scale = 1; } // TODO: handle the cases when precision and/or scale are not set return(new SqlNumber(value.ToArray(), scale, precision)); }
private ISqlValue ToNumeric(SqlNumber number, SqlNumericType destType) { // TODO: should we make some checks here? return(destType.NormalizeValue(number)); }