Exemplo n.º 1
0
        public override object ConvertToType(ISessionInterface session, object a, SqlType othType)
        {
            long units;
            int  nanos;

            if (a == null)
            {
                return(null);
            }
            int typeCode = othType.TypeCode;

            if (typeCode > 0x19)
            {
                switch (typeCode)
                {
                case 100:
                    goto Label_023D;

                case 0x65:
                    return(new IntervalMonthData((((IntervalMonthData)a).Units / 12L) * 12L, this));

                case 0x66:
                case 0x6b:
                    return(new IntervalMonthData(((IntervalMonthData)a).Units, this));

                case 0x67:
                    return(new IntervalSecondData((((IntervalSecondData)a).Units / ((long)DTIType.YearToSecondFactors[2])) * DTIType.YearToSecondFactors[2], 0, this));

                case 0x68:
                case 0x69:
                case 0x6c:
                case 0x6d:
                case 0x6f:
                    return(new IntervalSecondData((((IntervalSecondData)a).Units / ((long)DTIType.YearToSecondFactors[base.EndPartIndex])) * DTIType.YearToSecondFactors[base.EndPartIndex], 0, this));

                case 0x6a:
                case 110:
                case 0x70:
                case 0x71:
                {
                    IntervalSecondData data1 = (IntervalSecondData)a;
                    units = data1.Units;
                    nanos = data1.Nanos;
                    if (base.Scale != 0)
                    {
                        nanos = (nanos / DTIType.NanoScaleFactors[base.Scale]) * DTIType.NanoScaleFactors[base.Scale];
                    }
                    else
                    {
                        nanos = 0;
                    }
                    goto Label_022A;
                }

                case 40:
                    a = a.ToString();
                    goto Label_023D;
                }
                goto Label_0251;
            }
            switch (typeCode)
            {
            case -6:
            case 2:
            case 3:
            case 4:
            case 5:
            case 6:
            case 7:
            case 8:
            case 0x19:
            {
                if ((a is decimal) && !NumberType.IsInLongLimits((decimal)a))
                {
                    throw Error.GetError(0xd6b);
                }
                long years = Convert.ToInt64(a);
                switch (base.EndIntervalType)
                {
                case 0x65:
                    return(IntervalMonthData.NewIntervalYear(years, this));

                case 0x66:
                    return(IntervalMonthData.NewIntervalMonth(years, this));

                case 0x67:
                    return(IntervalSecondData.NewIntervalDay(years, this));

                case 0x68:
                    return(IntervalSecondData.NewIntervalHour(years, this));

                case 0x69:
                    return(IntervalSecondData.NewIntervalMinute(years, this));

                case 0x6a:
                {
                    int nanos = 0;
                    if ((base.Scale > 0) && (a is decimal))
                    {
                        nanos = (int)NumberType.ScaledDecimal(a, 9);
                    }
                    return(new IntervalSecondData(years, nanos, this));
                }
                }
                throw Error.GetError(0x15b9);
            }

            case 1:
            case 12:
                goto Label_023D;

            default:
                goto Label_0251;
            }
Label_022A:
            return(new IntervalSecondData(units, nanos, this));

Label_023D:
            return(session.GetScanner().ConvertToDatetimeInterval(session, (string)a, this));

Label_0251:
            throw Error.GetError(0x15b9);
        }