示例#1
0
        internal T Read <T>(NpgsqlBuffer buf, int len, FieldDescription fieldDescription = null)
        {
            T result;

            var asSimpleReader = this as ISimpleTypeReader <T>;

            if (asSimpleReader != null)
            {
                buf.Ensure(len);
                result = asSimpleReader.Read(buf, len, fieldDescription);
            }
            else
            {
                var asChunkingReader = this as IChunkingTypeReader <T>;
                if (asChunkingReader == null)
                {
                    if (fieldDescription == null)
                    {
                        throw new InvalidCastException("Can't cast database type to " + typeof(T).Name);
                    }
                    throw new InvalidCastException(String.Format("Can't cast database type {0} to {1}", fieldDescription.Handler.PgName, typeof(T).Name));
                }

                asChunkingReader.PrepareRead(buf, len, fieldDescription);
                while (!asChunkingReader.Read(out result))
                {
                    buf.ReadMore();
                }
            }

            return(result);
        }
示例#2
0
 internal override DataRowMessage Load(NpgsqlBuffer buf)
 {
     buf.Ensure(sizeof(short));
     NumColumns = buf.ReadInt16();
     Buffer = buf;
     Column = -1;
     ColumnLen = -1;
     PosInColumn = 0;
     return this;
 }
示例#3
0
        void ReadHeader()
        {
            _leftToReadInDataMsg = _connector.ReadExpecting <CopyDataMessage>().Length;
            var headerLen = NpgsqlRawCopyStream.BinarySignature.Length + 4 + 4;

            _buf.Ensure(headerLen);
            if (NpgsqlRawCopyStream.BinarySignature.Any(t => _buf.ReadByte() != t))
            {
                throw new Exception("Invalid COPY binary signature at beginning!");
            }
            var flags = _buf.ReadInt32();

            if (flags != 0)
            {
                throw new NotSupportedException("Unsupported flags in COPY operation (OID inclusion?)");
            }
            _buf.ReadInt32();   // Header extensions, currently unused
            _leftToReadInDataMsg -= headerLen;
        }
示例#4
0
        internal NpgsqlBuffer EnsureOrAllocateTemp(int count)
        {
            if (count <= Size) {
                Ensure(count);
                return this;
            }

            // Worst case: our buffer isn't big enough. For now, allocate a new buffer
            // and copy into it
            // TODO: Optimize with a pool later?
            var tempBuf = new NpgsqlBuffer(Underlying, count, TextEncoding);
            CopyTo(tempBuf);
            Clear();
            tempBuf.Ensure(count);
            return tempBuf;
        }
示例#5
0
        /// <summary>
        /// Reads in the requested bytes into the buffer, or if the buffer isn't big enough, allocates a new
        /// temporary buffer and reads into it. Returns the buffer that contains the data (either itself or the
        /// temp buffer). Used in cases where we absolutely have to have an entire value in memory and cannot
        /// read it in sequentially.
        /// </summary>
        internal NpgsqlBuffer EnsureOrAllocateTemp(int count)
        {
            if (count <= Size) {
                Ensure(count);
                return this;
            }

            // Worst case: our buffer isn't big enough. For now, allocate a new buffer
            // and copy into it
            // TODO: Optimize with a pool later?
            var tempBuf = new NpgsqlBuffer(Underlying, count, TextEncoding);
            CopyTo(tempBuf);
            Clear();
            tempBuf.Ensure(count);
            return tempBuf;
        }