public static void TypesEqual(int length1, int length2, bool expected)
        {
            var type1 = PrimitiveTypes.Array(length1);
            var type2 = PrimitiveTypes.Array(length2);

            Assert.Equal(expected, type1.Equals(type2));
        }
        public static void SerializeExplicit(int value)
        {
            var type   = PrimitiveTypes.Array(value);
            var result = SqlTypeUtil.Serialize(type);

            Assert.Equal(type, result);
        }
Example #3
0
 public static SqlObject Array(SqlArray array)
 {
     return(new SqlObject(PrimitiveTypes.Array(array.Length), array));
 }
        public static void Create(int value)
        {
            var type = PrimitiveTypes.Array(value);

            Assert.Equal(value, type.Length);
        }
Example #5
0
        private static SqlType GetSqlType(ISqlValue value)
        {
            if (value == null ||
                SqlNull.Value == value)
            {
                throw new ArgumentException();
            }

            if (value is SqlNumber)
            {
                var number = (SqlNumber)value;

                if (number.CanBeInt32)
                {
                    return(PrimitiveTypes.Integer());
                }
                if (number.CanBeInt64)
                {
                    return(PrimitiveTypes.BigInt());
                }

                if (number.Precision == SqlNumericType.FloatPrecision)
                {
                    return(new SqlNumericType(SqlTypeCode.Float, number.Precision, number.Scale));
                }
                if (number.Precision == SqlNumericType.DoublePrecision)
                {
                    return(new SqlNumericType(SqlTypeCode.Double, number.Precision, number.Scale));
                }
                if (number.Precision == SqlNumericType.DecimalPrecision)
                {
                    return(new SqlNumericType(SqlTypeCode.Decimal, number.Precision, number.Scale));
                }

                return(PrimitiveTypes.Numeric(number.Precision, number.Scale));
            }

            if (value is ISqlString)
            {
                // TODO: support the long string
                var length = ((ISqlString)value).Length;

                return(PrimitiveTypes.VarChar((int)length));
            }

            if (value is SqlBinary)
            {
                var bin = (SqlBinary)value;

                return(PrimitiveTypes.VarBinary((int)bin.Length));
            }

            if (value is SqlDateTime)
            {
                return(PrimitiveTypes.TimeStamp());
            }

            if (value is SqlBoolean)
            {
                return(PrimitiveTypes.Boolean());
            }

            if (value is SqlYearToMonth)
            {
                return(PrimitiveTypes.YearToMonth());
            }
            if (value is SqlDayToSecond)
            {
                return(PrimitiveTypes.DayToSecond());
            }

            if (value is SqlArray)
            {
                return(PrimitiveTypes.Array(((SqlArray)value).Length));
            }

            throw new NotSupportedException();
        }