Пример #1
0
 public override bool CanConvertFrom(SqlType othType)
 {
     return((((othType.TypeCode == 0) || othType.IsCharacterType()) || othType.IsNumberType()) || (othType.IsIntervalType() && (this.IsYearMonthIntervalType() == ((IntervalType)othType).IsYearMonthIntervalType())));
 }
Пример #2
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);
        }
Пример #3
0
 public override object Divide(object a, object b, SqlType aType, SqlType bType)
 {
     return(this.MultiplyOrDivide(a, b, true));
 }
Пример #4
0
 public override int Compare(Session session, object a, object b, SqlType otherType, bool forEquality)
 {
     if (a != b)
     {
         if (a == null)
         {
             return(-1);
         }
         if (b == null)
         {
             return(1);
         }
         Guid   guid    = (Guid)a;
         Guid   guid2   = (Guid)b;
         byte[] buffer  = guid.ToByteArray();
         byte[] buffer2 = guid2.ToByteArray();
         int    num2    = buffer[10].CompareTo(buffer2[10]);
         if (num2 != 0)
         {
             return(num2);
         }
         num2 = buffer[11].CompareTo(buffer2[11]);
         if (num2 != 0)
         {
             return(num2);
         }
         num2 = buffer[12].CompareTo(buffer2[12]);
         if (num2 != 0)
         {
             return(num2);
         }
         num2 = buffer[13].CompareTo(buffer2[13]);
         if (num2 != 0)
         {
             return(num2);
         }
         num2 = buffer[14].CompareTo(buffer2[14]);
         if (num2 != 0)
         {
             return(num2);
         }
         num2 = buffer[15].CompareTo(buffer2[15]);
         if (num2 != 0)
         {
             return(num2);
         }
         num2 = buffer[8].CompareTo(buffer2[8]);
         if (num2 != 0)
         {
             return(num2);
         }
         num2 = buffer[9].CompareTo(buffer2[9]);
         if (num2 != 0)
         {
             return(num2);
         }
         num2 = buffer[6].CompareTo(buffer2[6]);
         if (num2 != 0)
         {
             return(num2);
         }
         num2 = buffer[7].CompareTo(buffer2[7]);
         if (num2 != 0)
         {
             return(num2);
         }
         num2 = buffer[4].CompareTo(buffer2[4]);
         if (num2 != 0)
         {
             return(num2);
         }
         num2 = buffer[5].CompareTo(buffer2[5]);
         if (num2 != 0)
         {
             return(num2);
         }
         num2 = buffer[0].CompareTo(buffer2[0]);
         if (num2 != 0)
         {
             return(num2);
         }
         num2 = buffer[1].CompareTo(buffer2[1]);
         if (num2 != 0)
         {
             return(num2);
         }
         num2 = buffer[2].CompareTo(buffer2[2]);
         if (num2 != 0)
         {
             return(num2);
         }
         num2 = buffer[3].CompareTo(buffer2[3]);
         if (num2 != 0)
         {
             return(num2);
         }
     }
     return(0);
 }
Пример #5
0
        public override object Subtract(object a, object b, SqlType aType, SqlType otherType)
        {
            if ((a == null) || (b == null))
            {
                return(null);
            }
            switch (base.TypeCode)
            {
            case 0x65:
            case 0x66:
            case 0x6b:
            {
                IntervalMonthData data  = a as IntervalMonthData;
                IntervalMonthData data2 = b as IntervalMonthData;
                if ((data == null) || (data2 == null))
                {
                    TimestampData data3 = a as TimestampData;
                    TimestampData data4 = b as TimestampData;
                    if ((data3 == null) || (data4 == null))
                    {
                        throw Error.RuntimeError(0xc9, "IntervalType");
                    }
                    bool isYear = base.TypeCode == 0x65;
                    return(new IntervalMonthData((long)DateTimeType.SubtractMonths(data3, data4, isYear), this));
                }
                return(new IntervalMonthData(data.Units - data2.Units, this));
            }

            case 0x67:
            case 0x68:
            case 0x69:
            case 0x6a:
            case 0x6c:
            case 0x6d:
            case 110:
            case 0x6f:
            case 0x70:
            case 0x71:
            {
                IntervalSecondData data5 = a as IntervalSecondData;
                IntervalSecondData data6 = b as IntervalSecondData;
                if ((data5 == null) || (data6 == null))
                {
                    TimeData data7 = a as TimeData;
                    TimeData data8 = b as TimeData;
                    if ((data7 != null) && (data8 != null))
                    {
                        long num4 = data7.GetSeconds() - data8.GetSeconds();
                        return(new IntervalSecondData(num4, data7.GetNanos() - data8.GetNanos(), this, true));
                    }
                    TimestampData data9  = a as TimestampData;
                    TimestampData data10 = b as TimestampData;
                    if ((data9 != null) && (data10 != null))
                    {
                        long num6 = data9.GetSeconds() - data10.GetSeconds();
                        return(new IntervalSecondData(num6, data9.GetNanos() - data10.GetNanos(), this, true));
                    }
                    break;
                }
                long seconds = data5.Units - data6.Units;
                return(new IntervalSecondData(seconds, data5.Nanos - data6.Nanos, this, true));
            }
            }
            throw Error.RuntimeError(0xc9, "IntervalType");
        }
Пример #6
0
 public override bool CanConvertFrom(SqlType othType)
 {
     return((((othType.TypeCode == 0) || othType.IsGuidType()) || othType.IsCharacterType()) || (othType.IsBinaryType() && (othType.Precision == 0x10L)));
 }
Пример #7
0
        public override object ConvertToType(ISessionInterface session, object a, SqlType othType)
        {
            byte[] buffer;
            if (a == null)
            {
                return(a);
            }
            int typeCode = othType.TypeCode;

            if (typeCode <= 12)
            {
                switch (typeCode)
                {
                case -11:
                    return(a);

                case 1:
                case 12:
                    goto Label_0049;
                }
                goto Label_00B3;
            }
            if (typeCode != 40)
            {
                if ((typeCode - 60) <= 1)
                {
                    goto Label_0083;
                }
                if (typeCode == 100)
                {
                    goto Label_0049;
                }
                goto Label_00B3;
            }
            a = SqlType.SqlVarchar.ConvertToType(session, a, othType);
Label_0049:
            a = ((CharacterType)othType).Trim(session, a, " ", true, true);
            try
            {
                return(new Guid((string)a));
            }
            catch (Exception)
            {
                throw Error.RuntimeError(0xc9, "UniqueIdentifier Type");
            }
Label_0083:
            buffer = (byte[])a;
            if (buffer.Length != 0x10)
            {
                return(null);
            }
            try
            {
                return(new Guid(buffer));
            }
            catch (Exception)
            {
                throw Error.RuntimeError(0xc9, "UniqueIdentifier Type");
            }
Label_00B3:
            throw Error.GetError(0xd6e);
        }
Пример #8
0
        public static long Position(ISessionInterface session, IBlobData data, IBlobData otherData, SqlType otherType, long offset)
        {
            if ((data == null) || (otherData == null))
            {
                return(-1L);
            }
            long num2 = data.Length(session);

            if ((offset + num2) > data.Length(session))
            {
                return(-1L);
            }
            return(data.Position(session, otherData, offset));
        }
Пример #9
0
        private object CastOrConvertToType(ISessionInterface session, object a, SqlType otherType, bool cast)
        {
            if (a == null)
            {
                return(null);
            }
            int typeCode = otherType.TypeCode;

            if (typeCode > 12)
            {
                if ((typeCode != 30) && ((typeCode - 60) > 1))
                {
                    goto Label_005A;
                }
                IBlobData data1 = (IBlobData)a;
                goto Label_0065;
            }
            switch (typeCode)
            {
            case 1:
            case 12:
            {
                IBlobData data = session.GetScanner().ConvertToBinary((string)a);
                otherType = GetBinaryType(0x3d, data.Length(session));
                goto Label_0065;
            }
            }
Label_005A:
            throw Error.GetError(0xd8f);
Label_0065:
            if (base.Precision == 0)
            {
                return(null);
            }
            IBlobData data2 = null;

            if ((data2.Length(session) > base.Precision) && (data2.NonZeroLength(session) > base.Precision))
            {
                if (!cast)
                {
                    throw Error.GetError(0xd49);
                }
                session.AddWarning(Error.GetError(0x3ec));
            }
            if (otherType.TypeCode == 30)
            {
                long num2 = data2.Length(session);
                if (num2 > base.Precision)
                {
                    throw Error.GetError(0xd8f);
                }
                data2 = new BinaryData(data2.GetBytes(session, 0L, (int)num2), false);
            }
            int num3 = base.TypeCode;

            if (num3 == 60)
            {
                if (data2.Length(session) > base.Precision)
                {
                    return(new BinaryData(data2.GetBytes(session, 0L, (int)base.Precision), false));
                }
                if (data2.Length(session) < base.Precision)
                {
                    data2 = new BinaryData(ArrayUtil.ResizeArray <byte>(data2.GetBytes(), (int)base.Precision), false);
                }
                return(data2);
            }
            if (num3 != 0x3d)
            {
                throw Error.GetError(0xd8f);
            }
            if (data2.Length(session) > base.Precision)
            {
                data2 = new BinaryData(data2.GetBytes(session, 0L, (int)base.Precision), false);
            }
            return(data2);
        }
Пример #10
0
 public override object ConvertToType(ISessionInterface session, object a, SqlType othType)
 {
     return(this.CastOrConvertToType(session, a, othType, false));
 }