internal override DataRowMessage Load(NpgsqlBuffer buf)
 {
     buf.Ensure(sizeof(short));
     NumColumns = buf.ReadInt16();
     Buffer = buf;
     Column = -1;
     ColumnLen = -1;
     PosInColumn = 0;
     return this;
 }
Beispiel #2
0
        /// <summary>
        /// Starts reading a single row, must be invoked before reading any columns.
        /// </summary>
        /// <returns>
        /// The number of columns in the row. -1 if there are no further rows.
        /// Note: This will currently be the same value for all rows, but this may change in the future.
        /// </returns>
        public int StartRow()
        {
            CheckDisposed();
            if (_isConsumed)
            {
                return(-1);
            }

            // The very first row (i.e. _column == -1) is included in the header's CopyData message.
            // Otherwise we need to read in a new CopyData row (the docs specify that there's a CopyData
            // message per row).
            if (_column == NumColumns)
            {
                _leftToReadInDataMsg = _connector.ReadExpecting <CopyDataMessage>().Length;
            }
            else if (_column != -1)
            {
                throw new InvalidOperationException("Already in the middle of a row");
            }
            _buf.Ensure(2);
            _leftToReadInDataMsg -= 2;
            var numColumns = _buf.ReadInt16();

            if (numColumns == -1)
            {
                Contract.Assume(_leftToReadInDataMsg == 0);
                _connector.ReadExpecting <CopyDoneMessage>();
                _connector.ReadExpecting <CommandCompleteMessage>();
                _connector.ReadExpecting <ReadyForQueryMessage>();
                _column     = -1;
                _isConsumed = true;
                return(-1);
            }
            Contract.Assume(numColumns == NumColumns);

            _column = 0;
            return(NumColumns);
        }