Class NpgsqlDataReader
Reads a forward-only stream of rows from a data source.
Inheritance
Implements
Inherited Members
Namespace: Npgsql
Assembly: Npgsql.dll
Syntax
public abstract class NpgsqlDataReader : DbDataReader, IDataReader, IDisposable, IDataRecord, IEnumerable
Fields
Behavior
The behavior of the command with which this reader was executed.
Declaration
protected CommandBehavior Behavior
Field Value
Type | Description |
---|---|
System.Data.CommandBehavior |
Properties
Depth
Gets a value indicating the depth of nesting for the current row. Always returns zero.
Declaration
public override int Depth { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Overrides
FieldCount
Gets the number of columns in the current row.
Declaration
public override int FieldCount { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Overrides
HasRows
Gets a value that indicates whether this DbDataReader contains one or more rows.
Declaration
public override bool HasRows { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Overrides
IsClosed
Gets a value indicating whether the data reader is closed.
Declaration
public override bool IsClosed { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Overrides
IsOnRow
Indicates whether the reader is currently positioned on a row, i.e. whether reading a column is possible. This property is different from HasRows in that HasRows will return true even if attempting to read a column will fail, e.g. before Read() has been called
Declaration
public bool IsOnRow { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Item[Int32]
Gets the value of the specified column as an instance of System.Object.
Declaration
public override object this[int ordinal] { get; }
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | ordinal | The zero-based column ordinal. |
Property Value
Type | Description |
---|---|
System.Object | The value of the specified column. |
Overrides
Item[String]
Gets the value of the specified column as an instance of System.Object.
Declaration
public override object this[string name] { get; }
Parameters
Type | Name | Description |
---|---|---|
System.String | name | The name of the column. |
Property Value
Type | Description |
---|---|
System.Object | The value of the specified column. |
Overrides
RecordsAffected
Gets the number of rows changed, inserted, or deleted by execution of the SQL statement.
Declaration
public override int RecordsAffected { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Overrides
Statements
Returns details about each statement that this reader will or has executed.
Declaration
public IReadOnlyList<NpgsqlStatement> Statements { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IReadOnlyList<NpgsqlStatement> |
Remarks
Note that some fields (i.e. rows and oid) are only populated as the reader traverses the result.
For commands with multiple queries, this exposes the number of rows affected on a statement-by-statement basis, unlike RecordsAffected which exposes an aggregation across all statements.
Methods
Close()
Closes the NpgsqlDataReader reader, allowing a new command to be executed.
Declaration
public override void Close()
Overrides
CloseAsync()
Closes the NpgsqlDataReader reader, allowing a new command to be executed.
Declaration
public Task CloseAsync()
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task |
Dispose(Boolean)
Releases the resources used by the NpgsqlDataReader.
Declaration
protected override void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | disposing |
Overrides
GetBoolean(Int32)
Gets the value of the specified column as a Boolean.
Declaration
public override bool GetBoolean(int ordinal)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | ordinal | The zero-based column ordinal. |
Returns
Type | Description |
---|---|
System.Boolean | The value of the specified column. |
Overrides
GetByte(Int32)
Gets the value of the specified column as a byte.
Declaration
public override byte GetByte(int ordinal)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | ordinal | The zero-based column ordinal. |
Returns
Type | Description |
---|---|
System.Byte | The value of the specified column. |
Overrides
GetBytes(Int32, Int64, Byte[], Int32, Int32)
Reads a stream of bytes from the specified column, starting at location indicated by dataOffset, into the buffer, starting at the location indicated by bufferOffset.
Declaration
public override long GetBytes(int ordinal, long dataOffset, byte[] buffer, int bufferOffset, int length)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | ordinal | The zero-based column ordinal. |
System.Int64 | dataOffset | The index within the row from which to begin the read operation. |
System.Byte[] | buffer | The buffer into which to copy the data. |
System.Int32 | bufferOffset | The index with the buffer to which the data will be copied. |
System.Int32 | length | The maximum number of characters to read. |
Returns
Type | Description |
---|---|
System.Int64 | The actual number of bytes read. |
Overrides
GetChar(Int32)
Gets the value of the specified column as a single character.
Declaration
public override char GetChar(int ordinal)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | ordinal | The zero-based column ordinal. |
Returns
Type | Description |
---|---|
System.Char | The value of the specified column. |
Overrides
GetChars(Int32, Int64, Char[], Int32, Int32)
Reads a stream of characters from the specified column, starting at location indicated by dataOffset, into the buffer, starting at the location indicated by bufferOffset.
Declaration
public override long GetChars(int ordinal, long dataOffset, char[] buffer, int bufferOffset, int length)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | ordinal | The zero-based column ordinal. |
System.Int64 | dataOffset | The index within the row from which to begin the read operation. |
System.Char[] | buffer | The buffer into which to copy the data. |
System.Int32 | bufferOffset | The index with the buffer to which the data will be copied. |
System.Int32 | length | The maximum number of characters to read. |
Returns
Type | Description |
---|---|
System.Int64 | The actual number of characters read. |
Overrides
GetColumnSchema()
Returns schema information for the columns in the current resultset.
Declaration
public ReadOnlyCollection<NpgsqlDbColumn> GetColumnSchema()
Returns
Type | Description |
---|---|
System.Collections.ObjectModel.ReadOnlyCollection<NpgsqlDbColumn> |
GetDataTypeName(Int32)
Gets the data type information for the specified field. This will be the PostgreSQL type name (e.g. double precision), not the .NET type (see GetFieldType(Int32) for that).
Declaration
public override string GetDataTypeName(int ordinal)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | ordinal | The zero-based column index. |
Returns
Type | Description |
---|---|
System.String |
Overrides
GetDataTypeOID(Int32)
Gets the OID for the PostgreSQL type for the specified field, as it appears in the pg_type table.
Declaration
public uint GetDataTypeOID(int ordinal)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | ordinal | The zero-based column index. |
Returns
Type | Description |
---|---|
System.UInt32 |
Remarks
This is a PostgreSQL-internal value that should not be relied upon and should only be used for debugging purposes.
GetDate(Int32)
Gets the value of the specified column as an NpgsqlDate, Npgsql's provider-specific type for dates.
Declaration
public NpgsqlDate GetDate(int ordinal)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | ordinal | The zero-based column ordinal. |
Returns
Type | Description |
---|---|
NpgsqlDate | The value of the specified column. |
Remarks
PostgreSQL's date type represents dates from 4713 BC to 5874897 AD, while .NET's DateTime only supports years from 1 to 1999. If you require years outside this range use this accessor. The standard System.Data.Common.DbDataReader.GetProviderSpecificValue(System.Int32) method will also return this type, but has the disadvantage of boxing the value. See http://www.postgresql.org/docs/current/static/datatype-datetime.html
GetDateTime(Int32)
Gets the value of the specified column as a System.DateTime object.
Declaration
public override DateTime GetDateTime(int ordinal)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | ordinal | The zero-based column ordinal. |
Returns
Type | Description |
---|---|
System.DateTime | The value of the specified column. |
Overrides
GetDecimal(Int32)
Gets the value of the specified column as a System.Decimal object.
Declaration
public override decimal GetDecimal(int ordinal)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | ordinal | The zero-based column ordinal. |
Returns
Type | Description |
---|---|
System.Decimal | The value of the specified column. |
Overrides
GetDouble(Int32)
Gets the value of the specified column as a double-precision floating point number.
Declaration
public override double GetDouble(int ordinal)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | ordinal | The zero-based column ordinal. |
Returns
Type | Description |
---|---|
System.Double | The value of the specified column. |
Overrides
GetEnumerator()
Returns an System.Collections.IEnumerator that can be used to iterate through the rows in the data reader.
Declaration
public override IEnumerator GetEnumerator()
Returns
Type | Description |
---|---|
System.Collections.IEnumerator | An System.Collections.IEnumerator that can be used to iterate through the rows in the data reader. |
Overrides
GetFieldType(Int32)
Gets the data type of the specified column.
Declaration
public override Type GetFieldType(int ordinal)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | ordinal | The zero-based column ordinal. |
Returns
Type | Description |
---|---|
System.Type | The data type of the specified column. |
Overrides
GetFloat(Int32)
Gets the value of the specified column as a single-precision floating point number.
Declaration
public override float GetFloat(int ordinal)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | ordinal | The zero-based column ordinal. |
Returns
Type | Description |
---|---|
System.Single | The value of the specified column. |
Overrides
GetGuid(Int32)
Gets the value of the specified column as a globally-unique identifier (GUID).
Declaration
public override Guid GetGuid(int ordinal)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | ordinal | The zero-based column ordinal. |
Returns
Type | Description |
---|---|
System.Guid | The value of the specified column. |
Overrides
GetInt16(Int32)
Gets the value of the specified column as a 16-bit signed integer.
Declaration
public override short GetInt16(int ordinal)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | ordinal | The zero-based column ordinal. |
Returns
Type | Description |
---|---|
System.Int16 | The value of the specified column. |
Overrides
GetInt32(Int32)
Gets the value of the specified column as a 32-bit signed integer.
Declaration
public override int GetInt32(int ordinal)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | ordinal | The zero-based column ordinal. |
Returns
Type | Description |
---|---|
System.Int32 | The value of the specified column. |
Overrides
GetInt64(Int32)
Gets the value of the specified column as a 64-bit signed integer.
Declaration
public override long GetInt64(int ordinal)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | ordinal | The zero-based column ordinal. |
Returns
Type | Description |
---|---|
System.Int64 | The value of the specified column. |
Overrides
GetInterval(Int32)
Gets the value of the specified column as an NpgsqlTimeSpan, Npgsql's provider-specific type for time spans.
Declaration
public NpgsqlTimeSpan GetInterval(int ordinal)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | ordinal | The zero-based column ordinal. |
Returns
Type | Description |
---|---|
NpgsqlTimeSpan | The value of the specified column. |
Remarks
PostgreSQL's interval type has has a resolution of 1 microsecond and ranges from -178000000 to 178000000 years, while .NET's TimeSpan has a resolution of 100 nanoseconds and ranges from roughly -29247 to 29247 years. If you require values from outside TimeSpan's range use this accessor. The standard ADO.NET System.Data.Common.DbDataReader.GetProviderSpecificValue(System.Int32) method will also return this type, but has the disadvantage of boxing the value. See http://www.postgresql.org/docs/current/static/datatype-datetime.html
GetName(Int32)
Gets the name of the column, given the zero-based column ordinal.
Declaration
public override string GetName(int ordinal)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | ordinal | The zero-based column ordinal. |
Returns
Type | Description |
---|---|
System.String | The name of the specified column. |
Overrides
GetOrdinal(String)
Gets the column ordinal given the name of the column.
Declaration
public override int GetOrdinal(string name)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | The name of the column. |
Returns
Type | Description |
---|---|
System.Int32 | The zero-based column ordinal. |
Overrides
GetPostgresType(Int32)
Gets a representation of the PostgreSQL data type for the specified field. The returned representation can be used to access various information about the field.
Declaration
public PostgresType GetPostgresType(int ordinal)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | ordinal | The zero-based column index. |
Returns
Type | Description |
---|---|
PostgresType |
GetProviderSpecificFieldType(Int32)
Returns the provider-specific field type of the specified column.
Declaration
public override Type GetProviderSpecificFieldType(int ordinal)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | ordinal | The zero-based column ordinal. |
Returns
Type | Description |
---|---|
System.Type | The Type object that describes the data type of the specified column. |
Overrides
GetProviderSpecificValues(Object[])
Gets all provider-specific attribute columns in the collection for the current row.
Declaration
public override int GetProviderSpecificValues(object[] values)
Parameters
Type | Name | Description |
---|---|---|
System.Object[] | values | An array of Object into which to copy the attribute columns. |
Returns
Type | Description |
---|---|
System.Int32 | The number of instances of System.Object in the array. |
Overrides
GetSchemaTable()
Returns a System.Data.DataTable that describes the column metadata of the DataReader.
Declaration
public override DataTable GetSchemaTable()
Returns
Type | Description |
---|---|
System.Data.DataTable |
Overrides
GetStream(Int32)
Retrieves data as a System.IO.Stream.
Declaration
public override Stream GetStream(int ordinal)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | ordinal | The zero-based column ordinal. |
Returns
Type | Description |
---|---|
System.IO.Stream | The returned object. |
Overrides
GetStreamAsync(Int32)
Retrieves data as a System.IO.Stream.
Declaration
public Task<Stream> GetStreamAsync(int ordinal)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | ordinal | The zero-based column ordinal. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.IO.Stream> | The returned object. |
GetString(Int32)
Gets the value of the specified column as an instance of System.String.
Declaration
public override string GetString(int ordinal)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | ordinal | The zero-based column ordinal. |
Returns
Type | Description |
---|---|
System.String | The value of the specified column. |
Overrides
GetTextReader(Int32)
Retrieves data as a System.IO.TextReader.
Declaration
public override TextReader GetTextReader(int ordinal)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | ordinal | The zero-based column ordinal. |
Returns
Type | Description |
---|---|
System.IO.TextReader | The returned object. |
Overrides
GetTextReaderAsync(Int32)
Retrieves data as a System.IO.TextReader.
Declaration
public Task<TextReader> GetTextReaderAsync(int ordinal)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | ordinal | The zero-based column ordinal. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.IO.TextReader> | The returned object. |
GetTimeSpan(Int32)
Gets the value of the specified column as a TimeSpan,
Declaration
public TimeSpan GetTimeSpan(int ordinal)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | ordinal | The zero-based column ordinal. |
Returns
Type | Description |
---|---|
System.TimeSpan | The value of the specified column. |
Remarks
PostgreSQL's interval type has has a resolution of 1 microsecond and ranges from -178000000 to 178000000 years, while .NET's TimeSpan has a resolution of 100 nanoseconds and ranges from roughly -29247 to 29247 years. See http://www.postgresql.org/docs/current/static/datatype-datetime.html
GetTimeStamp(Int32)
Gets the value of the specified column as an NpgsqlDateTime, Npgsql's provider-specific type for date/time timestamps. Note that this type covers both PostgreSQL's "timestamp with time zone" and "timestamp without time zone" types, which differ only in how they are converted upon input/output.
Declaration
public NpgsqlDateTime GetTimeStamp(int ordinal)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | ordinal | The zero-based column ordinal. |
Returns
Type | Description |
---|---|
NpgsqlDateTime | The value of the specified column. |
Remarks
PostgreSQL's timestamp type represents dates from 4713 BC to 5874897 AD, while .NET's DateTime only supports years from 1 to 1999. If you require years outside this range use this accessor. The standard System.Data.Common.DbDataReader.GetProviderSpecificValue(System.Int32) method will also return this type, but has the disadvantage of boxing the value. See http://www.postgresql.org/docs/current/static/datatype-datetime.html
GetValues(Object[])
Populates an array of objects with the column values of the current row.
Declaration
public override int GetValues(object[] values)
Parameters
Type | Name | Description |
---|---|---|
System.Object[] | values | An array of Object into which to copy the attribute columns. |
Returns
Type | Description |
---|---|
System.Int32 | The number of instances of System.Object in the array. |
Overrides
NextResult()
Advances the reader to the next result when reading the results of a batch of statements.
Declaration
public override sealed bool NextResult()
Returns
Type | Description |
---|---|
System.Boolean |
Overrides
NextResultAsync(CancellationToken)
This is the asynchronous version of NextResult.
The cancellationToken
parameter is currently ignored.
Declaration
public override Task<bool> NextResultAsync(CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
System.Threading.CancellationToken | cancellationToken | Currently ignored. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.Boolean> | A task representing the asynchronous operation. |
Overrides
Read()
Advances the reader to the next record in a result set.
Declaration
public override bool Read()
Returns
Type | Description |
---|---|
System.Boolean | true if there are more rows; otherwise false. |
Overrides
Remarks
The default position of a data reader is before the first record. Therefore, you must call Read to begin accessing data.
ReadAsync(CancellationToken)
This is the asynchronous version of Read() The cancellation token is currently ignored.
Declaration
public override Task<bool> ReadAsync(CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
System.Threading.CancellationToken | cancellationToken | Ignored for now. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.Boolean> | A task representing the asynchronous operation. |
Overrides
Events
ReaderClosed
Is raised whenever Close() is called.
Declaration
public event EventHandler ReaderClosed
Event Type
Type | Description |
---|---|
System.EventHandler |