Esempio n. 1
0
        // Reads off from the network buffer and caches bytes. Only reads one column value in the current row.
        static internal bool TryCreate(SqlMetaDataPriv metadata, TdsParser parser, TdsParserStateObject stateObj, out SqlCachedBuffer buffer)
        {
            int   cb = 0;
            ulong plplength;

            byte[] byteArr;

            List <byte[]> cachedBytes = new List <byte[]>();

            buffer = null;

            // the very first length is already read.
            if (!parser.TryPlpBytesLeft(stateObj, out plplength))
            {
                return(false);
            }
            // For now we  only handle Plp data from the parser directly.
            Debug.Assert(metadata.metaType.IsPlp, "SqlCachedBuffer call on a non-plp data");
            do
            {
                if (plplength == 0)
                {
                    break;
                }
                do
                {
                    cb      = (plplength > (ulong)_maxChunkSize) ? _maxChunkSize : (int)plplength;
                    byteArr = new byte[cb];
                    if (!stateObj.TryReadPlpBytes(ref byteArr, 0, cb, out cb))
                    {
                        return(false);
                    }
                    Debug.Assert(cb == byteArr.Length);
                    if (cachedBytes.Count == 0)
                    {
                        // Add the Byte order mark if needed if we read the first array
                        AddByteOrderMark(byteArr, cachedBytes);
                    }
                    cachedBytes.Add(byteArr);
                    plplength -= (ulong)cb;
                } while (plplength > 0);
                if (!parser.TryPlpBytesLeft(stateObj, out plplength))
                {
                    return(false);
                }
            } while (plplength > 0);
            Debug.Assert(stateObj._longlen == 0 && stateObj._longlenleft == 0);

            buffer = new SqlCachedBuffer(cachedBytes);
            return(true);
        }
Esempio n. 2
0
 internal virtual void CopyFrom(SqlMetaDataPriv original)
 {
     this.type       = original.type;
     this.tdsType    = original.tdsType;
     this.precision  = original.precision;
     this.scale      = original.scale;
     this.length     = original.length;
     this.collation  = original.collation;
     this.codePage   = original.codePage;
     this.encoding   = original.encoding;
     this.isNullable = original.isNullable;
     this.xmlSchemaCollectionDatabase     = original.xmlSchemaCollectionDatabase;
     this.xmlSchemaCollectionOwningSchema = original.xmlSchemaCollectionOwningSchema;
     this.xmlSchemaCollectionName         = original.xmlSchemaCollectionName;
     this.metaType = original.metaType;
 }