public static SqlType FromValue(object value)
        {
            if (value is SqlNumber)
            {
                var number = (SqlNumber)value;
                if (number.Scale == 0)
                {
                    if (number.Precision <= 3)
                    {
                        return(PrimitiveTypes.TinyInt());
                    }
                    if (number.Precision <= 5)
                    {
                        return(PrimitiveTypes.SmallInt());
                    }
                    if (number.Precision <= 10)
                    {
                        return(PrimitiveTypes.Integer());
                    }
                    if (number.Precision <= 19)
                    {
                        return(PrimitiveTypes.BigInt());
                    }
                }
                else
                {
                    if (number.Precision <= 8)
                    {
                        return(PrimitiveTypes.Float());
                    }
                    if (number.Precision <= 12)
                    {
                        return(PrimitiveTypes.Double());
                    }

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

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

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

            if (value is double)
            {
                return(PrimitiveTypes.Double());
            }
            if (value is float)
            {
                return(PrimitiveTypes.Float());
            }
            if (value is int)
            {
                return(PrimitiveTypes.Integer());
            }
            if (value is long)
            {
                return(PrimitiveTypes.BigInt());
            }
            if (value is byte)
            {
                return(PrimitiveTypes.TinyInt());
            }
            if (value is short)
            {
                return(PrimitiveTypes.SmallInt());
            }

            if (value is string)
            {
                return(PrimitiveTypes.String());
            }

            throw new NotSupportedException();
        }
 public static SqlObject Double(double value)
 {
     return(new SqlObject(PrimitiveTypes.Double(), (SqlNumber)value));
 }
Exemple #3
0
 private static void BinaryOp(Func <SqlType, Func <ISqlValue, ISqlValue, SqlBoolean> > selector, object value1, object value2, bool expected)
 {
     OperatorsUtil.Binary(PrimitiveTypes.Double(), selector, value1, value2, expected);
 }