コード例 #1
0
ファイル: NpgsqlDataReader.cs プロジェクト: timoch/Npgsql-fdb
        /// <summary>
        /// Iterate through the objects returned through from the server.
        /// If it's a CompletedResponse the rowsaffected count is updated appropriately,
        /// and we iterate again, otherwise we return it (perhaps updating our cache of pending
        /// rows if appropriate).
        /// </summary>
        /// <returns>The next <see cref="IServerResponseObject"/> we will deal with.</returns>
        private IServerResponseObject GetNextResponseObject(bool cleanup = false)
        {
            try
            {
                CurrentRow = null;
                if (_pendingRow != null)
                {
                    _pendingRow.Dispose();
                }
                _pendingRow = null;
                while (_dataEnumerator.MoveNext())
                {
                    IServerResponseObject respNext = _dataEnumerator.Current;

                    if (respNext is RowReader)
                    {
                        RowReader reader = respNext as RowReader;

                        if (cleanup)
                        {
                            // V3 rows can dispose by simply reading MessageLength bytes.
                            reader.Dispose();

                            return reader;
                        }
                        else
                        {
                            return _pendingRow = BuildRow(new ForwardsOnlyRow(reader));
                        }
                    }
                    else if (respNext is CompletedResponse)
                    {
                        CompletedResponse cr = respNext as CompletedResponse;
                        if (cr.RowsAffected.HasValue)
                        {
                            _nextRecordsAffected = (_nextRecordsAffected ?? 0) + cr.RowsAffected.Value;
                        }
                        _nextInsertOID = cr.LastInsertedOID ?? _nextInsertOID;
                    }
                    else
                    {
                        return respNext;
                    }
                }
                CleanUp(true);
                return null;
            }
            catch
            {
                CleanUp(true);
                throw;
            }
        }
コード例 #2
0
ファイル: NpgsqlDataReader.cs プロジェクト: timoch/Npgsql-fdb
        private NpgsqlRow GetNextRow(bool clearPending)
        {
            if (_pendingDescription != null)
            {
                return null;
            }
            if (((_behavior & CommandBehavior.SingleRow) != 0 && CurrentRow != null && _pendingDescription == null) ||
                ((_behavior & CommandBehavior.SchemaOnly) != 0))
            {
                if (!clearPending)
                {
                    return null;
                }
                //We should only have one row, and we've already had it. Move to end
                //of recordset.
                CurrentRow = null;
                for (object skip = GetNextResponseObject();
                     skip != null && (_pendingDescription = skip as NpgsqlRowDescription) == null;
                     skip = GetNextResponseObject())
                {
                    if (skip is NpgsqlRow)
                    {
                        (skip as NpgsqlRow).Dispose();
                    }
                }

                return null;
            }
            if (_pendingRow != null)
            {
                NpgsqlRow ret = _pendingRow;
                if (clearPending)
                {
                    _pendingRow = null;
                }
                if (!_hasRows)
                {
                    // when rows are found, store that this result has rows.
                    _hasRows = (ret != null);
                }
                return ret;
            }
            CurrentRow = null;
            object objNext = GetNextResponseObject();
            if (clearPending)
            {
                _pendingRow = null;
            }
            if (objNext is NpgsqlRowDescription)
            {
                _pendingDescription = objNext as NpgsqlRowDescription;
                return null;
            }
            if (!_hasRows)
            {
                // when rows are found, store that this result has rows.
                _hasRows = objNext is NpgsqlRow;
            }
            return objNext as NpgsqlRow;
        }