public static void TryParseFull(string s,
                                        int year,
                                        int month,
                                        int day,
                                        int hour,
                                        int minute,
                                        int second,
                                        int millis,
                                        int offsetHour,
                                        int offsetMinute,
                                        bool expected)
        {
            SqlDateTime date;

            Assert.Equal(expected, SqlDateTime.TryParse(s, out date));

            Assert.Equal(year, date.Year);
            Assert.Equal(month, date.Month);
            Assert.Equal(day, date.Day);
            Assert.Equal(hour, date.Hour);
            Assert.Equal(minute, date.Minute);
            Assert.Equal(second, date.Second);
            Assert.Equal(millis, date.Millisecond);
            Assert.Equal(offsetHour, date.Offset.Hours);
            Assert.Equal(offsetMinute, date.Offset.Minutes);
        }
示例#2
0
        public SqlDateTime ToSqlDateTime(IFormatProvider provider)
        {
            SqlDateTime value;

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

            return(value);
        }
        private ISqlValue ToDateTime(SqlString value, SqlType destType)
        {
            if (value == null)
            {
                throw new InvalidCastException();
            }

            SqlDateTime date;

            if (!SqlDateTime.TryParse(value.Value, out date))
            {
                throw new InvalidCastException();
            }

            return(destType.NormalizeValue(date));
        }
示例#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);
            }
        }