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();
        }