Пример #1
0
        public override object ConvertSQLToCSharp(ISessionInterface session, object a)
        {
            IClobData data1  = (IClobData)a;
            int       length = (int)data1.Length(session);

            return(new string(data1.GetChars(session, 0L, length)));
        }
Пример #2
0
        public object RPad(Session session, object data, int width, string paddingChar)
        {
            if ((data == null) || (width < 0))
            {
                return(null);
            }
            if (string.IsNullOrEmpty(paddingChar))
            {
                return(data);
            }
            if (base.TypeCode == 40)
            {
                IClobData data2 = (IClobData)data;
                string    str   = data2.GetSubString(session, 0L, (int)data2.Length(session));
                if (str.Length > width)
                {
                    return(str.Substring(0, width));
                }
                str = (paddingChar.Length > 1) ? PadRight(str, width, paddingChar) : str.PadRight(width, paddingChar[0]);
                ClobDataId id1 = session.CreateClob((long)str.Length);
                id1.SetString(session, 0L, str);
                return(id1);
            }
            string str2 = (string)data;

            if (str2.Length > width)
            {
                return(str2.Substring(0, width));
            }
            if (paddingChar.Length > 1)
            {
                return(PadRight(str2, width, paddingChar));
            }
            return(str2.PadRight(width, paddingChar[0]));
        }
Пример #3
0
        public virtual long Position(ISessionInterface session, object data, object otherData, SqlType otherType, long offset)
        {
            if ((data == null) || (otherData == null))
            {
                return(-1L);
            }
            string str = (string)data;

            if (otherType.TypeCode == 40)
            {
                IClobData data2 = (IClobData)otherData;
                long      num2  = data2.Length(session);
                if ((offset + num2) > str.Length)
                {
                    return(-1L);
                }
                string str2 = data2.GetSubString(session, 0L, (int)num2);
                return((long)str.IndexOf(str2, (int)offset));
            }
            if (!otherType.IsCharacterType())
            {
                throw Error.RuntimeError(0xc9, "CharacterType");
            }
            string str3   = (string)otherData;
            long   length = str3.Length;

            if ((offset + length) > str.Length)
            {
                return(-1L);
            }
            return(str.IndexOf(str3, (int)offset));
        }
Пример #4
0
 public object Lower(Session session, object data)
 {
     if (data == null)
     {
         return(null);
     }
     if (base.TypeCode == 40)
     {
         IClobData data2 = (IClobData)data;
         string    s     = data2.GetSubString(session, 0L, (int)data2.Length(session));
         s = this._collation.ToLowerCase(s);
         ClobDataId id1 = session.CreateClob((long)s.Length);
         id1.SetString(session, 0L, s);
         return(id1);
     }
     return(this._collation.ToLowerCase((string)data));
 }
Пример #5
0
        public override object Concat(Session session, object a, object b)
        {
            string str;
            string str2;

            if ((a == null) || (b == null))
            {
                return(null);
            }
            IClobData data = a as IClobData;

            if (data != null)
            {
                str = data.GetSubString(session, 0L, (int)data.Length(session));
            }
            else
            {
                str = a.ToString();
            }
            IClobData data2 = b as IClobData;

            if (data2 != null)
            {
                str2 = data2.GetSubString(session, 0L, (int)data2.Length(session));
            }
            else
            {
                str2 = b.ToString();
            }
            if (base.TypeCode == 40)
            {
                ClobDataId id1 = session.CreateClob((long)(str.Length + str2.Length));
                id1.SetString(session, 0L, str);
                id1.SetString(session, (long)str.Length, str2);
                return(id1);
            }
            return(str + str2);
        }
Пример #6
0
        public object Trim(ISessionInterface session, object data, string trim, bool leading, bool trailing)
        {
            string str;

            if (data == null)
            {
                return(null);
            }
            IClobData data2 = data as IClobData;

            if (data2 != null)
            {
                str = data2.GetSubString(session, 0L, (int)data2.Length(session));
            }
            else
            {
                str = (string)data;
            }
            if (leading & trailing)
            {
                str = str.Trim(trim.ToCharArray());
            }
            else if (leading)
            {
                str = str.TrimStart(trim.ToCharArray());
            }
            else if (trailing)
            {
                str = str.TrimEnd(trim.ToCharArray());
            }
            if (base.TypeCode == 40)
            {
                ClobDataId id1 = session.CreateClob((long)str.Length);
                id1.SetString(session, 0L, str);
                return(id1);
            }
            return(str);
        }
Пример #7
0
        public object Substring(ISessionInterface session, object data, long offset, long length, bool hasLength, bool trailing)
        {
            IClobData data2 = null;
            string    str   = null;
            long      num;
            long      num2;

            if (base.TypeCode == 40)
            {
                data2 = (IClobData)data;
                num   = data2.Length(session);
            }
            else
            {
                str = (string)data;
                num = str.Length;
            }
            if (offset < 0L)
            {
                offset += num + 1L;
            }
            if (trailing)
            {
                num2 = num;
                if (length > num)
                {
                    offset = 0L;
                    length = num;
                }
                else
                {
                    offset = num - length;
                }
            }
            else if (hasLength)
            {
                num2 = offset + length;
            }
            else
            {
                num2 = (num > offset) ? num : offset;
            }
            if (num2 < offset)
            {
                throw Error.GetError(0xd67);
            }
            if (((offset > num2) || (num2 < 0L)) || (offset > num))
            {
                offset = 0L;
                return(string.Empty);
            }
            if (offset < 0L)
            {
                offset = 0L;
            }
            if (num2 > num)
            {
                num2 = num;
            }
            length = num2 - offset;
            if (base.TypeCode == 40)
            {
                string     str2 = data2.GetSubString(session, offset, (int)length);
                ClobDataId id1  = session.CreateClob(length);
                id1.SetString(session, 0L, str2);
                return(id1);
            }
            return(str.Substring((int)offset, (int)length));
        }
Пример #8
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");
        }