Example #1
0
        public static void TryParse(string s, double expected)
        {
            var expectedResult = (SqlNumber)expected;

            SqlNumber number;

            Assert.True(SqlNumber.TryParse(s, out number));
            Assert.Equal(expectedResult, number);
        }
Example #2
0
        private SqlNumber ToNumber(IFormatProvider provider)
        {
            SqlNumber value;

            if (!SqlNumber.TryParse(Value, provider, out value))
            {
                throw new FormatException();
            }

            return(value);
        }
        private ISqlValue ToNumber(SqlString value, SqlType destType)
        {
            var       locale = Locale ?? CultureInfo.InvariantCulture;
            SqlNumber number;

            if (!SqlNumber.TryParse(value.Value, locale, out number))
            {
                throw new InvalidCastException();
            }

            return(destType.NormalizeValue(number));
        }
Example #4
0
        private static bool TryParseValue(SqlTypeCode typeCode, string s, IFormatProvider provider, out ISqlValue outValue, out Exception error)
        {
            try {
                switch (typeCode)
                {
                case SqlTypeCode.TinyInt:
                case SqlTypeCode.SmallInt:
                case SqlTypeCode.Integer:
                case SqlTypeCode.BigInt:
                case SqlTypeCode.Real:
                case SqlTypeCode.Double:
                case SqlTypeCode.Decimal:
                case SqlTypeCode.Float:
                case SqlTypeCode.Numeric:
                case SqlTypeCode.VarNumeric: {
                    error = null;
                    var result = SqlNumber.TryParse(s, provider, out var value);
                    outValue = value;

                    return(result);
                }

                case SqlTypeCode.Bit:
                case SqlTypeCode.Boolean: {
                    error = null;
                    var result = SqlBoolean.TryParse(s, out var value);
                    outValue = value;

                    return(result);
                }

                case SqlTypeCode.Date:
                case SqlTypeCode.DateTime:
                case SqlTypeCode.TimeStamp: {
                    error = null;
                    var result = SqlDateTime.TryParse(s, out var value);
                    outValue = value;

                    return(result);
                }

                case SqlTypeCode.YearToMonth: {
                    error = null;
                    var result = SqlYearToMonth.TryParse(s, out var value);
                    outValue = value;

                    return(result);
                }

                case SqlTypeCode.DayToSecond: {
                    error = null;
                    var result = SqlDayToSecond.TryParse(s, out var value);
                    outValue = value;

                    return(result);
                }

                default: {
                    error    = new FormatException($"The type {typeCode} does not support parsing");
                    outValue = null;

                    return(false);
                }
                }
            } catch (Exception ex) {
                error    = ex;
                outValue = null;

                return(false);
            }
        }
Example #5
0
        public static void TryInvalidParse(string s)
        {
            SqlNumber number;

            Assert.False(SqlNumber.TryParse(s, out number));
        }