Example #1
0
        public object CastOrConvertToType(ISessionInterface session, object a, SqlType otherType, bool cast)
        {
            switch (otherType.TypeCode)
            {
            case 40:
            {
                IClobData data      = (IClobData)a;
                long      precision = data.Length(session);
                if ((base.Precision != 0) && (precision > base.Precision))
                {
                    if (data.NonSpaceLength(session) > base.Precision)
                    {
                        if (!cast)
                        {
                            throw Error.GetError(0xd49);
                        }
                        session.AddWarning(Error.GetError(0x3ec));
                    }
                    precision = base.Precision;
                }
                switch (base.TypeCode)
                {
                case 40:
                    if ((base.Precision != 0) && (precision > base.Precision))
                    {
                        return(data.GetClob(session, 0L, base.Precision));
                    }
                    return(a);

                case 100:
                case 1:
                case 12:
                    if (precision > 0x7fffffffL)
                    {
                        if (!cast)
                        {
                            throw Error.GetError(0xd49);
                        }
                        precision = 0x7fffffffL;
                    }
                    a = data.GetSubString(session, 0L, (int)precision);
                    return(this.ConvertToTypeLimits(session, a));
                }
                throw Error.RuntimeError(0xc9, "CharacterType");
            }

            case 100:
            case 1:
            case 12:
            {
                string s      = (string)a;
                int    length = s.Length;
                if ((base.Precision != 0) && (length > base.Precision))
                {
                    if (StringUtil.RightTrimSize(s) > base.Precision)
                    {
                        if (!cast)
                        {
                            throw Error.GetError(0xd49);
                        }
                        session.AddWarning(Error.GetError(0x3ec));
                    }
                    a = s.Substring(0, (int)base.Precision);
                }
                int typeCode = base.TypeCode;
                if (typeCode <= 12)
                {
                    switch (typeCode)
                    {
                    case 1:
                        return(this.ConvertToTypeLimits(session, a));

                    case 12:
                        return(a);
                    }
                    break;
                }
                if (typeCode == 40)
                {
                    ClobDataId id1 = session.CreateClob((long)s.Length);
                    id1.SetString(session, 0L, s);
                    return(id1);
                }
                if (typeCode != 100)
                {
                    break;
                }
                return(a);
            }

            case 0x457:
                throw Error.GetError(0x15b9);

            default:
            {
                string str2 = otherType.ConvertToString(a);
                if ((base.Precision != 0) && (str2.Length > base.Precision))
                {
                    throw Error.GetError(0xd49);
                }
                a = str2;
                return(this.ConvertToTypeLimits(session, a));
            }
            }
            throw Error.RuntimeError(0xc9, "CharacterType");
        }