Пример #1
0
        internal ulong PlpBytesLeft(TdsParserStateObject stateObj)
        {
            if ((stateObj._longlen != 0) && (stateObj._longlenleft == 0))
                stateObj.ReadPlpLength(false);

            return stateObj._longlenleft;
        }
Пример #2
0
        internal int ReadPlpAnsiChars(ref char[] buff, int offst, int len, SqlMetaDataPriv metadata, TdsParserStateObject stateObj)
        {
            int charsRead = 0;
            int charsLeft = 0;
            int bytesRead = 0;
            int totalcharsRead = 0;

            if (stateObj._longlen == 0)
            {
                Debug.Assert(stateObj._longlenleft == 0);
                return 0;       // No data
            }

            Debug.Assert(((ulong)stateObj._longlen != TdsEnums.SQL_PLP_NULL),
                    "Out of sync plp read request");

            Debug.Assert((buff == null && offst == 0) || (buff.Length >= offst + len), "Invalid length sent to ReadPlpAnsiChars()!");
            charsLeft = len;

            if (stateObj._longlenleft == 0)
            {
                stateObj.ReadPlpLength(false);
                if (stateObj._longlenleft == 0)
                {// Data read complete
                    stateObj._plpdecoder = null;
                    return 0;
                }
            }

            if (stateObj._plpdecoder == null)
            {
                Encoding enc = metadata.encoding;

                if (enc == null)
                {
                    if (null == _defaultEncoding)
                    {
                        ThrowUnsupportedCollationEncountered(stateObj);
                    }

                    enc = _defaultEncoding;
                }
                stateObj._plpdecoder = enc.GetDecoder();
            }

            while (charsLeft > 0)
            {
                bytesRead = (int)Math.Min(stateObj._longlenleft, (ulong)charsLeft);
                if ((stateObj._bTmp == null) || (stateObj._bTmp.Length < bytesRead))
                {
                    // Grow the array
                    stateObj._bTmp = new byte[bytesRead];
                }

                bytesRead = stateObj.ReadPlpBytesChunk(stateObj._bTmp, 0, bytesRead);

                charsRead = stateObj._plpdecoder.GetChars(stateObj._bTmp, 0, bytesRead, buff, offst);
                charsLeft -= charsRead;
                offst += charsRead;
                totalcharsRead += charsRead;
                if (stateObj._longlenleft == 0)  // Read the next chunk or cleanup state if hit the end
                    stateObj.ReadPlpLength(false);

                if (stateObj._longlenleft == 0)
                { // Data read complete
                    stateObj._plpdecoder = null;
                    break;
                }
            }
            return (totalcharsRead);
        }
 internal ulong GetDataLength(SqlMetaDataPriv colmeta, TdsParserStateObject stateObj)
 {
     if (this._isYukon && colmeta.metaType.IsPlp)
     {
         return stateObj.ReadPlpLength(true);
     }
     return (ulong) this.GetTokenLength(colmeta.tdsType, stateObj);
 }
 internal ulong SkipPlpValue(ulong cb, TdsParserStateObject stateObj)
 {
     ulong num2 = 0L;
     if (stateObj._longlenleft == 0L)
     {
         stateObj.ReadPlpLength(false);
     }
     while ((num2 < cb) && (stateObj._longlenleft > 0L))
     {
         int num;
         if (stateObj._longlenleft > 0x7fffffffL)
         {
             num = 0x7fffffff;
         }
         else
         {
             num = (int) stateObj._longlenleft;
         }
         num = ((cb - num2) < num) ? ((int) (cb - num2)) : num;
         this.SkipBytes(num, stateObj);
         stateObj._longlenleft -= num;
         num2 += num;
         if (stateObj._longlenleft == 0L)
         {
             stateObj.ReadPlpLength(false);
         }
     }
     return num2;
 }
 internal int ReadPlpUnicodeChars(ref char[] buff, int offst, int len, TdsParserStateObject stateObj)
 {
     int num = 0;
     int num2 = 0;
     int num3 = 0;
     if (stateObj._longlen != 0L)
     {
         num2 = len;
         if ((buff == null) && (stateObj._longlen != 18446744073709551614L))
         {
             buff = new char[Math.Min((int) stateObj._longlen, len)];
         }
         if (stateObj._longlenleft != 0L)
         {
             goto Label_0150;
         }
         stateObj.ReadPlpLength(false);
         if (stateObj._longlenleft != 0L)
         {
             goto Label_0150;
         }
     }
     return 0;
 Label_0150:
     while (num2 > 0)
     {
         num = (int) Math.Min((stateObj._longlenleft + 1L) >> 1, (ulong) num2);
         if ((buff == null) || (buff.Length < (offst + num)))
         {
             char[] dst = new char[offst + num];
             if (buff != null)
             {
                 Buffer.BlockCopy(buff, 0, dst, 0, offst * 2);
             }
             buff = dst;
         }
         if (num > 0)
         {
             num = this.ReadPlpUnicodeCharsChunk(buff, offst, num, stateObj);
             num2 -= num;
             offst += num;
             num3 += num;
         }
         if ((stateObj._longlenleft == 1L) && (num2 > 0))
         {
             byte num5 = stateObj.ReadByte();
             stateObj._longlenleft -= (ulong) 1L;
             stateObj.ReadPlpLength(false);
             byte num4 = stateObj.ReadByte();
             stateObj._longlenleft -= (ulong) 1L;
             buff[offst] = (char) (((num4 & 0xff) << 8) + (num5 & 0xff));
             offst++;
             num++;
             num2--;
             num3++;
         }
         if (stateObj._longlenleft == 0L)
         {
             stateObj.ReadPlpLength(false);
         }
         if (stateObj._longlenleft == 0L)
         {
             return num3;
         }
     }
     return num3;
 }
 internal int ReadPlpAnsiChars(ref char[] buff, int offst, int len, SqlMetaDataPriv metadata, TdsParserStateObject stateObj)
 {
     int num3 = 0;
     int num2 = 0;
     int num = 0;
     int num4 = 0;
     if (stateObj._longlen == 0L)
     {
         return 0;
     }
     num2 = len;
     if (stateObj._longlenleft == 0L)
     {
         stateObj.ReadPlpLength(false);
         if (stateObj._longlenleft == 0L)
         {
             return 0;
         }
     }
     Encoding encoding = metadata.encoding;
     if (encoding == null)
     {
         if (this._defaultEncoding == null)
         {
             this.ThrowUnsupportedCollationEncountered(stateObj);
         }
         encoding = this._defaultEncoding;
     }
     while (num2 > 0)
     {
         num = (int) Math.Min(stateObj._longlenleft, (ulong) num2);
         if ((stateObj._bTmp == null) || (stateObj._bTmp.Length < num))
         {
             stateObj._bTmp = new byte[num];
         }
         num = stateObj.ReadPlpBytesChunk(stateObj._bTmp, 0, num);
         num3 = encoding.GetChars(stateObj._bTmp, 0, num, buff, offst);
         num2 -= num3;
         offst += num3;
         num4 += num3;
         if (stateObj._longlenleft == 0L)
         {
             stateObj.ReadPlpLength(false);
         }
         if (stateObj._longlenleft == 0L)
         {
             return num4;
         }
     }
     return num4;
 }