Beispiel #1
0
        public static void Serialize(SqlTypeCode typeCode)
        {
            var type   = new SqlDateTimeType(typeCode);
            var result = BinarySerializeUtil.Serialize(type);

            Assert.Equal(type, result);
        }
        public static void CastToBinary(object value, SqlTypeCode typeCode, int size)
        {
            var type     = SqlTypeUtil.FromValue(value);
            var destType = PrimitiveTypes.Binary(typeCode, size);

            Assert.NotNull(type);
            Assert.IsType <SqlNumericType>(type);

            var number = (SqlNumber)SqlValueUtil.FromObject(value);

            Assert.True(type.CanCastTo(number, destType));
            var result = type.Cast(number, destType);

            Assert.IsAssignableFrom <ISqlBinary>(result);

            var binary = (ISqlBinary)result;

            var memStream = new MemoryStream();

            binary.GetInput().CopyTo(memStream);

            var bytes = memStream.ToArray();

            Assert.NotEmpty(bytes);

            var back = new SqlNumber(bytes);

            Assert.Equal(number, back);
        }
Beispiel #3
0
 private static void AssertDateType(SqlTypeCode sqlType)
 {
     if (!IsDateType(sqlType))
     {
         throw new ArgumentException(String.Format("The SQL type {0} is not a valid DATE", sqlType), "sqlType");
     }
 }
Beispiel #4
0
 private static void AssertIsString(SqlTypeCode sqlType)
 {
     if (!IsStringType(sqlType))
     {
         throw new ArgumentException(String.Format("The type {0} is not a valid STRING type.", sqlType), "sqlType");
     }
 }
 private static void AssertIsNumeric(SqlTypeCode typeCode)
 {
     if (!IsNumericType(typeCode))
     {
         throw new ArgumentException($"The type '{typeCode}' is not a valid NUMERIC type.");
     }
 }
 public ColumnAttribute(string name, SqlTypeCode type, int size, int scale)
 {
     ColumnName = name;
     SqlType = type;
     Size = size;
     Scale = scale;
 }
 public ColumnAttribute(string name, SqlTypeCode type, int size, int scale)
 {
     ColumnName = name;
     SqlType    = type;
     Size       = size;
     Scale      = scale;
 }
        private static int DiscoverPrecision(SqlTypeCode typeCode)
        {
            switch (typeCode)
            {
            case SqlTypeCode.TinyInt:
                return(TinyIntPrecision);

            case SqlTypeCode.SmallInt:
                return(SmallIntPrecision);

            case SqlTypeCode.Integer:
                return(IntegerPrecision);

            case SqlTypeCode.BigInt:
                return(BigIntPrecision);

            case SqlTypeCode.Float:
            case SqlTypeCode.Real:
                return(FloatPrecision);

            case SqlTypeCode.Double:
                return(DoublePrecision);

            case SqlTypeCode.Decimal:
                return(DecimalPrecision);

            case SqlTypeCode.VarNumeric:
                return(-1);

            default:
                throw new ArgumentException($"Type {typeCode} requires an explicit precision");
            }
        }
Beispiel #9
0
        public void GetRuntimeType(SqlTypeCode code, Type expectedType)
        {
            var type = PrimitiveTypes.Interval(code);
            var objType = type.GetRuntimeType();

            Assert.AreEqual(expectedType, objType);
        }
Beispiel #10
0
        public void GetRuntimeType(SqlTypeCode code, Type expectedType)
        {
            var type    = PrimitiveTypes.Interval(code);
            var objType = type.GetRuntimeType();

            Assert.AreEqual(expectedType, objType);
        }
        private static string GetTypeName(SqlTypeCode typeCode)
        {
            if (!IsPrimitive(typeCode))
            {
                throw new ArgumentException($"The type with code {typeCode} is not primitive");
            }

            switch (typeCode)
            {
            case SqlTypeCode.LongVarChar:
                return("LONG VARCHAR");

            case SqlTypeCode.LongVarBinary:
                return("LONG VARBINARY");

            case SqlTypeCode.YearToMonth:
                return("YEAR TO MONTH");

            case SqlTypeCode.DayToSecond:
                return("DAY TO SECOND");

            default:
                return(typeCode.ToString().ToUpperInvariant());
            }
        }
 public NumericType(SqlTypeCode typeCode, int precision, int scale)
     : base("NUMERIC", typeCode)
 {
     AssertIsNumeric(typeCode);
     Precision = precision;
     Scale     = scale;
 }
Beispiel #13
0
 public NumericType(SqlTypeCode typeCode, int precision, int scale)
     : base("NUMERIC", typeCode)
 {
     AssertIsNumeric(typeCode);
     Precision = precision;
     Scale = scale;
 }
        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 Serialize(SqlTypeCode typeCode, int precision, int scale)
        {
            var type   = new SqlNumericType(typeCode, precision, scale);
            var result = BinarySerializeUtil.Serialize(type);

            Assert.Equal(type, result);
        }
 private static void AssertIsBoolean(SqlTypeCode sqlType)
 {
     if (!IsBooleanType(sqlType))
     {
         throw new ArgumentException(String.Format("The SQL type {0} is not BOOLEAN.", sqlType));
     }
 }
Beispiel #17
0
 private static void AssertIsBoolean(SqlTypeCode sqlType)
 {
     if (!IsBooleanType(sqlType))
     {
         throw new ArgumentException($"The SQL type {sqlType} is not BOOLEAN.");
     }
 }
 private static void AssertIsNumeric(SqlTypeCode typeCode)
 {
     if (!IsNumericType(typeCode))
     {
         throw new ArgumentException(String.Format("The type '{0}' is not a valid NUMERIC type.", typeCode));
     }
 }
Beispiel #19
0
 public NumericType(SqlTypeCode sqlType, int size, byte scale)
     : base("NUMERIC", sqlType)
 {
     AssertIsNumeric(sqlType);
     Size = size;
     Scale = scale;
 }
        public static void BinaryTypesEqual(SqlTypeCode typeCode1, int size1, SqlTypeCode typeCode2, int size2, bool expected)
        {
            var type1 = new SqlBinaryType(typeCode1, size1);
            var type2 = new SqlBinaryType(typeCode2, size2);

            Assert.Equal(expected, type1.Equals(type2));
        }
        public static void Serialize(SqlTypeCode typeCode, int size)
        {
            var type   = new SqlBinaryType(typeCode, size);
            var result = BinarySerializeUtil.Serialize(type);

            Assert.Equal(type, result);
        }
Beispiel #22
0
 private static void AssertDateType(SqlTypeCode sqlType)
 {
     if (!IsDateType(sqlType))
     {
         throw new ArgumentException($"The SQL type {sqlType} is not a valid DATETIME", nameof(sqlType));
     }
 }
Beispiel #23
0
 internal static bool IsDateType(SqlTypeCode sqlType)
 {
     return(sqlType == SqlTypeCode.Date ||
            sqlType == SqlTypeCode.Time ||
            sqlType == SqlTypeCode.TimeStamp ||
            sqlType == SqlTypeCode.DateTime);
 }
 private static void AssertIsInterval(SqlTypeCode sqlType)
 {
     if (!IsIntervalType(sqlType))
     {
         throw new ArgumentException(String.Format("SQL Type {0} is not a valid INTERVAL.", sqlType.ToString().ToUpperInvariant()));
     }
 }
Beispiel #25
0
        public static void Cast(object value, SqlTypeCode destTypeCode, int p, int s, object expected)
        {
            var srcType  = SqlTypeUtil.FromValue(value);
            var destType = PrimitiveTypes.Type(destTypeCode, new { precision = p, scale = s, maxSize = p, size = p });

            Cast(srcType, value, destType, expected);
        }
Beispiel #26
0
        public void BooleanTypesEqual(SqlTypeCode typeCode1, SqlTypeCode typeCode2, bool expected)
        {
            var type1 = new SqlBooleanType(typeCode1);
            var type2 = new SqlBooleanType(typeCode2);

            Assert.Equal(expected, type1.Equals(type2));
        }
Beispiel #27
0
        public static void GetRuntime(SqlTypeCode code, Type expectedType)
        {
            var type = PrimitiveTypes.Numeric(code);

            var runtimeType = type.GetRuntimeType();
            Assert.AreEqual(expectedType, runtimeType);
        }
Beispiel #28
0
 public NumericType(SqlTypeCode typeCode, int size, byte scale)
     : base("NUMERIC", typeCode)
 {
     AssertIsNumeric(typeCode);
     Size  = size;
     Scale = scale;
 }
 private static void AssertIsBinary(SqlTypeCode sqlType)
 {
     if (!IsBinaryType(sqlType))
     {
         throw new ArgumentException(String.Format("The SQL type {0} is not a BINARY", sqlType));
     }
 }
 private static bool IsBinaryType(SqlTypeCode sqlType)
 {
     return(sqlType == SqlTypeCode.Binary ||
            sqlType == SqlTypeCode.VarBinary ||
            sqlType == SqlTypeCode.LongVarBinary ||
            sqlType == SqlTypeCode.Blob);
 }
Beispiel #31
0
	    public static void ParseString(string s, SqlTypeCode typeCode) {
            var type = SqlType.Parse(s);

            Assert.NotNull(type);
            Assert.Equal(typeCode, type.TypeCode);
            Assert.IsType<SqlDateTimeType>(type);
        }
Beispiel #32
0
        public void GetString(SqlTypeCode typeCode, string expected)
        {
            var type = new SqlBooleanType(typeCode);

            var s = type.ToString();

            Assert.Equal(expected, s);
        }
Beispiel #33
0
        public void ParseString(string input, SqlTypeCode typeCode)
        {
            var sqlType = SqlType.Parse(input);

            Assert.IsNotNull(sqlType);
            Assert.IsInstanceOf<DateType>(sqlType);
            Assert.AreEqual(typeCode, sqlType.TypeCode);
        }
Beispiel #34
0
        public static void Cast(SqlTypeCode srcTypeCode, int p1, int s1, object value, SqlTypeCode destTypeCode, int p2, int s2,
                                object expected)
        {
            var srcType  = PrimitiveTypes.Type(srcTypeCode, new { precision = p1, scale = s1, maxSize = p1, size = p1 });
            var destType = PrimitiveTypes.Type(destTypeCode, new { precision = p2, scale = s2, maxSize = p2, size = p2 });

            Cast(srcType, value, destType, expected);
        }
Beispiel #35
0
		public static void GetValidDateTimeType(SqlTypeCode typeCode) {
			var type = new SqlDateTimeType(typeCode);
			Assert.Equal(typeCode, type.TypeCode);
			Assert.True(type.IsIndexable);
			Assert.True(type.IsPrimitive);
			Assert.False(type.IsLargeObject);
			Assert.False(type.IsReference);
		}
Beispiel #36
0
        public void Serialize(SqlTypeCode typeCode)
        {
            var type = new SqlBooleanType(typeCode);

            var result = BinarySerializeUtil.Serialize(type);

            Assert.Equal(type, result);
        }
Beispiel #37
0
        public void ParseString(string input, SqlTypeCode expected)
        {
            var type = SqlType.Parse(input);

            Assert.IsNotNull(type);
            Assert.IsInstanceOf<IntervalType>(type);

            Assert.AreEqual(expected, type.TypeCode);
        }
Beispiel #38
0
        public static void ParseString(string input, SqlTypeCode expectedTypeCode, int expectedSize)
        {
            var sqlType = SqlType.Parse(input);

            Assert.IsNotNull(sqlType);
            Assert.IsInstanceOf<BinaryType>(sqlType);
            Assert.AreEqual(expectedTypeCode, sqlType.TypeCode);

            var binType = (BinaryType) sqlType;
            Assert.AreEqual(expectedSize, binType.MaxSize);
        }
Beispiel #39
0
        public static SqlType Resolve(SqlTypeCode typeCode, string typeName, DataTypeMeta[] metadata, ITypeResolver resolver)
        {
            if (PrimitiveTypes.IsPrimitive(typeCode))
                return PrimitiveTypes.Resolve(typeCode, typeName, metadata);

            if (resolver == null)
                throw new NotSupportedException(String.Format("Cannot resolve type '{0}' without context.", typeName));

            var resolveCcontext = new TypeResolveContext(typeCode, typeName, metadata);
            return resolver.ResolveType(resolveCcontext);
        }
Beispiel #40
0
        public void CastToString(SqlTypeCode typeCode, bool value, string expected)
        {
            var type = PrimitiveTypes.Boolean(typeCode);

            var boolean = new SqlBoolean(value);

            var casted = type.CastTo(boolean, PrimitiveTypes.String());

            Assert.IsInstanceOf<SqlString>(casted);
            Assert.AreEqual(expected, casted.ToString());
        }
Beispiel #41
0
        public StringType(SqlTypeCode typeCode, int maxSize, Encoding encoding, CultureInfo locale)
            : base("STRING", typeCode)
        {
            if (encoding == null)
                throw new ArgumentNullException("encoding");

            AssertIsString(typeCode);
            MaxSize = maxSize;
            Locale = locale;
            Encoding = encoding;
        }
Beispiel #42
0
        public static void CreateFrom(SqlTypeCode code, int precision, int scale, object value)
        {
            var type = PrimitiveTypes.Numeric(code, precision, scale);

            var result = type.CreateFrom(value);
            Assert.IsNotNull(result);
            Assert.IsFalse(result.IsNull);
            Assert.IsInstanceOf<SqlNumber>(result);

            var number = (SqlNumber) result;
            Assert.AreEqual(scale, number.Scale);
            Assert.AreEqual(precision, number.Precision);
        }
        public TypeResolveContext(SqlTypeCode typeCode, string typeName, DataTypeMeta[] meta)
        {
            TypeCode = typeCode;
            TypeName = typeName;

            this.meta = new Dictionary<string, DataTypeMeta>(StringComparer.OrdinalIgnoreCase);

            if (meta != null) {
                foreach (var typeMeta in meta) {
                    this.meta[typeMeta.Name] = typeMeta;
                }
            }
        }
Beispiel #44
0
 internal static bool IsDateType(SqlTypeCode sqlType)
 {
     return sqlType == SqlTypeCode.Date ||
            sqlType == SqlTypeCode.Time ||
            sqlType == SqlTypeCode.TimeStamp ||
            sqlType == SqlTypeCode.DateTime;
 }
Beispiel #45
0
 private static void AssertDateType(SqlTypeCode sqlType)
 {
     if (!IsDateType(sqlType))
         throw new ArgumentException(String.Format("The SQL type {0} is not a valid DATE", sqlType), "sqlType");
 }
Beispiel #46
0
 private static int GetFloatSize(SqlTypeCode sqlType)
 {
     switch (sqlType) {
         default:
             return 0;
         case SqlTypeCode.Real:
             return 4;
         case SqlTypeCode.Float:
         case SqlTypeCode.Double:
             return 8;
     }
 }
Beispiel #47
0
 private static int GetIntSize(SqlTypeCode sqlType)
 {
     switch (sqlType) {
         case SqlTypeCode.TinyInt:
             return 1;
         case SqlTypeCode.SmallInt:
             return 2;
         case SqlTypeCode.Integer:
             return 4;
         case SqlTypeCode.BigInt:
             return 8;
         default:
             return 0;
     }
 }
Beispiel #48
0
 internal static bool IsNumericType(SqlTypeCode typeCode)
 {
     return typeCode == SqlTypeCode.TinyInt ||
            typeCode == SqlTypeCode.SmallInt ||
            typeCode == SqlTypeCode.Integer ||
            typeCode == SqlTypeCode.BigInt ||
            typeCode == SqlTypeCode.Real ||
            typeCode == SqlTypeCode.Float ||
            typeCode == SqlTypeCode.Double ||
            typeCode == SqlTypeCode.Decimal ||
            typeCode == SqlTypeCode.Numeric;
 }
Beispiel #49
0
 private static void AssertIsNumeric(SqlTypeCode typeCode)
 {
     if (!IsNumericType(typeCode))
         throw new ArgumentException(String.Format("The type '{0}' is not a valid NUMERIC type.", typeCode));
 }
Beispiel #50
0
 public NumericType(SqlTypeCode typeCode)
     : this(typeCode, -1)
 {
 }
Beispiel #51
0
 public static StringType String(SqlTypeCode sqlType, int maxSize, Encoding encoding, CultureInfo locale)
 {
     return new StringType(sqlType, maxSize, encoding, locale);
 }
Beispiel #52
0
 public static DateType DateTime(SqlTypeCode sqlType)
 {
     return new DateType(sqlType);
 }
Beispiel #53
0
 public static StringType String(SqlTypeCode sqlType, Encoding encoding)
 {
     return String(sqlType, StringType.DefaultMaxSize, encoding);
 }
Beispiel #54
0
 public static StringType String(SqlTypeCode sqlType, int maxSize, Encoding encoding)
 {
     return String(sqlType, maxSize, encoding, null);
 }
Beispiel #55
0
 public static BinaryType Binary(SqlTypeCode sqlType, int maxSize)
 {
     return new BinaryType(sqlType, maxSize);
 }
Beispiel #56
0
 public static BinaryType Binary(SqlTypeCode sqlType)
 {
     return Binary(sqlType, -1);
 }
Beispiel #57
0
 public DateType(SqlTypeCode typeCode)
     : base("DATE", typeCode)
 {
     AssertDateType(typeCode);
 }
Beispiel #58
0
 public NumericType(SqlTypeCode typeCode, int size)
     : this(typeCode, size, 0)
 {
 }
Beispiel #59
0
 public static BooleanType Boolean(SqlTypeCode sqlType)
 {
     return new BooleanType(sqlType);
 }
Beispiel #60
0
 public static StringType String(SqlTypeCode sqlType, Encoding encoding, CultureInfo locale)
 {
     return String(sqlType, StringType.DefaultMaxSize, encoding, locale);
 }