Class NpgsqlDataReader
Reads a forward-only stream of rows from a data source.
Implements
Inherited Members
Namespace: Npgsql
Assembly: Npgsql.dll
Syntax
public sealed class NpgsqlDataReader : DbDataReader, IEnumerable, IDataReader, IDataRecord, IDisposable, IAsyncDisposable, IDbColumnSchemaGenerator
Properties
| Improve this DocDepth
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 |
---|---|
Int32 |
Overrides
| Improve this DocFieldCount
Gets the number of columns in the current row.
Declaration
public override int FieldCount { get; }
Property Value
Type | Description |
---|---|
Int32 |
Overrides
| Improve this DocHasRows
Gets a value that indicates whether this DbDataReader contains one or more rows.
Declaration
public override bool HasRows { get; }
Property Value
Type | Description |
---|---|
Boolean |
Overrides
| Improve this DocIsClosed
Gets a value indicating whether the data reader is closed.
Declaration
public override bool IsClosed { get; }
Property Value
Type | Description |
---|---|
Boolean |
Overrides
| Improve this DocIsOnRow
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 |
---|---|
Boolean |
Item[Int32]
Gets the value of the specified column as an instance of Object.
Declaration
public override object this[int ordinal] { get; }
Parameters
Type | Name | Description |
---|---|---|
Int32 | ordinal | The zero-based column ordinal. |
Property Value
Type | Description |
---|---|
Object | The value of the specified column. |
Overrides
| Improve this DocItem[String]
Gets the value of the specified column as an instance of Object.
Declaration
public override object this[string name] { get; }
Parameters
Type | Name | Description |
---|---|---|
String | name | The name of the column. |
Property Value
Type | Description |
---|---|
Object | The value of the specified column. |
Overrides
| Improve this DocRecordsAffected
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 |
---|---|
Int32 |
Overrides
| Improve this DocStatements
Returns details about each statement that this reader will or has executed.
Declaration
public IReadOnlyList<NpgsqlStatement> Statements { get; }
Property Value
Type | Description |
---|---|
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
| Improve this DocClose()
Closes the NpgsqlDataReader reader, allowing a new command to be executed.
Declaration
public override void Close()
Overrides
| Improve this DocCloseAsync()
Closes the NpgsqlDataReader reader, allowing a new command to be executed.
Declaration
public override Task CloseAsync()
Returns
Type | Description |
---|---|
Task |
Overrides
| Improve this DocDispose(Boolean)
Releases the resources used by the NpgsqlDataReader.
Declaration
protected override void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
Boolean | disposing |
Overrides
| Improve this DocDisposeAsync()
Releases the resources used by the NpgsqlDataReader.
Declaration
public override ValueTask DisposeAsync()
Returns
Type | Description |
---|---|
ValueTask |
Overrides
| Improve this DocGetBoolean(Int32)
Gets the value of the specified column as a Boolean.
Declaration
public override bool GetBoolean(int ordinal)
Parameters
Type | Name | Description |
---|---|---|
Int32 | ordinal | The zero-based column ordinal. |
Returns
Type | Description |
---|---|
Boolean | The value of the specified column. |
Overrides
| Improve this DocGetByte(Int32)
Gets the value of the specified column as a byte.
Declaration
public override byte GetByte(int ordinal)
Parameters
Type | Name | Description |
---|---|---|
Int32 | ordinal | The zero-based column ordinal. |
Returns
Type | Description |
---|---|
Byte | The value of the specified column. |
Overrides
| Improve this DocGetBytes(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 |
---|---|---|
Int32 | ordinal | The zero-based column ordinal. |
Int64 | dataOffset | The index within the row from which to begin the read operation. |
Byte[] | buffer | The buffer into which to copy the data. |
Int32 | bufferOffset | The index with the buffer to which the data will be copied. |
Int32 | length | The maximum number of characters to read. |
Returns
Type | Description |
---|---|
Int64 | The actual number of bytes read. |
Overrides
| Improve this DocGetChar(Int32)
Gets the value of the specified column as a single character.
Declaration
public override char GetChar(int ordinal)
Parameters
Type | Name | Description |
---|---|---|
Int32 | ordinal | The zero-based column ordinal. |
Returns
Type | Description |
---|---|
Char | The value of the specified column. |
Overrides
| Improve this DocGetChars(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 |
---|---|---|
Int32 | ordinal | The zero-based column ordinal. |
Int64 | dataOffset | The index within the row from which to begin the read operation. |
Char[] | buffer | The buffer into which to copy the data. |
Int32 | bufferOffset | The index with the buffer to which the data will be copied. |
Int32 | length | The maximum number of characters to read. |
Returns
Type | Description |
---|---|
Int64 | The actual number of characters read. |
Overrides
| Improve this DocGetColumnSchema()
Returns schema information for the columns in the current resultset.
Declaration
public ReadOnlyCollection<NpgsqlDbColumn> GetColumnSchema()
Returns
Type | Description |
---|---|
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 |
---|---|---|
Int32 | ordinal | The zero-based column index. |
Returns
Type | Description |
---|---|
String |
Overrides
| Improve this DocGetDataTypeOID(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 |
---|---|---|
Int32 | ordinal | The zero-based column index. |
Returns
Type | Description |
---|---|
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 |
---|---|---|
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 GetProviderSpecificValue(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 DateTime object.
Declaration
public override DateTime GetDateTime(int ordinal)
Parameters
Type | Name | Description |
---|---|---|
Int32 | ordinal | The zero-based column ordinal. |
Returns
Type | Description |
---|---|
DateTime | The value of the specified column. |
Overrides
| Improve this DocGetDecimal(Int32)
Gets the value of the specified column as a Decimal object.
Declaration
public override decimal GetDecimal(int ordinal)
Parameters
Type | Name | Description |
---|---|---|
Int32 | ordinal | The zero-based column ordinal. |
Returns
Type | Description |
---|---|
Decimal | The value of the specified column. |
Overrides
| Improve this DocGetDouble(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 |
---|---|---|
Int32 | ordinal | The zero-based column ordinal. |
Returns
Type | Description |
---|---|
Double | The value of the specified column. |
Overrides
| Improve this DocGetEnumerator()
Returns an IEnumerator that can be used to iterate through the rows in the data reader.
Declaration
public override IEnumerator GetEnumerator()
Returns
Type | Description |
---|---|
IEnumerator | An IEnumerator that can be used to iterate through the rows in the data reader. |
Overrides
| Improve this DocGetFieldType(Int32)
Gets the data type of the specified column.
Declaration
public override Type GetFieldType(int ordinal)
Parameters
Type | Name | Description |
---|---|---|
Int32 | ordinal | The zero-based column ordinal. |
Returns
Type | Description |
---|---|
Type | The data type of the specified column. |
Overrides
| Improve this DocGetFieldValue<T>(Int32)
Synchronously gets the value of the specified column as a type.
Declaration
public override T GetFieldValue<T>(int ordinal)
Parameters
Type | Name | Description |
---|---|---|
Int32 | ordinal | The column to be retrieved. |
Returns
Type | Description |
---|---|
T | The column to be retrieved. |
Type Parameters
Name | Description |
---|---|
T | Synchronously gets the value of the specified column as a type. |
Overrides
| Improve this DocGetFieldValueAsync<T>(Int32, CancellationToken)
Asynchronously gets the value of the specified column as a type.
Declaration
public override Task<T> GetFieldValueAsync<T>(int ordinal, CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
Int32 | ordinal | The type of the value to be returned. |
CancellationToken | cancellationToken | The token to monitor for cancellation requests. |
Returns
Type | Description |
---|---|
Task<T> |
Type Parameters
Name | Description |
---|---|
T | The type of the value to be returned. |
Overrides
| Improve this DocGetFloat(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 |
---|---|---|
Int32 | ordinal | The zero-based column ordinal. |
Returns
Type | Description |
---|---|
Single | The value of the specified column. |
Overrides
| Improve this DocGetGuid(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 |
---|---|---|
Int32 | ordinal | The zero-based column ordinal. |
Returns
Type | Description |
---|---|
Guid | The value of the specified column. |
Overrides
| Improve this DocGetInt16(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 |
---|---|---|
Int32 | ordinal | The zero-based column ordinal. |
Returns
Type | Description |
---|---|
Int16 | The value of the specified column. |
Overrides
| Improve this DocGetInt32(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 |
---|---|---|
Int32 | ordinal | The zero-based column ordinal. |
Returns
Type | Description |
---|---|
Int32 | The value of the specified column. |
Overrides
| Improve this DocGetInt64(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 |
---|---|---|
Int32 | ordinal | The zero-based column ordinal. |
Returns
Type | Description |
---|---|
Int64 | The value of the specified column. |
Overrides
| Improve this DocGetInterval(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 |
---|---|---|
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 GetProviderSpecificValue(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 |
---|---|---|
Int32 | ordinal | The zero-based column ordinal. |
Returns
Type | Description |
---|---|
String | The name of the specified column. |
Overrides
| Improve this DocGetOrdinal(String)
Gets the column ordinal given the name of the column.
Declaration
public override int GetOrdinal(string name)
Parameters
Type | Name | Description |
---|---|---|
String | name | The name of the column. |
Returns
Type | Description |
---|---|
Int32 | The zero-based column ordinal. |
Overrides
| Improve this DocGetPostgresType(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 |
---|---|---|
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 |
---|---|---|
Int32 | ordinal | The zero-based column ordinal. |
Returns
Type | Description |
---|---|
Type | The Type object that describes the data type of the specified column. |
Overrides
| Improve this DocGetProviderSpecificValue(Int32)
Gets the value of the specified column as an instance of Object.
Declaration
public override object GetProviderSpecificValue(int ordinal)
Parameters
Type | Name | Description |
---|---|---|
Int32 | ordinal | The zero-based column ordinal. |
Returns
Type | Description |
---|---|
Object | The value of the specified column. |
Overrides
| Improve this DocGetProviderSpecificValues(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 |
---|---|---|
Object[] | values | An array of Object into which to copy the attribute columns. |
Returns
Type | Description |
---|---|
Int32 | The number of instances of Object in the array. |
Overrides
| Improve this DocGetSchemaTable()
Returns a System.Data.DataTable that describes the column metadata of the DataReader.
Declaration
public override DataTable GetSchemaTable()
Returns
Type | Description |
---|---|
DataTable |
Overrides
| Improve this DocGetStream(Int32)
Retrieves data as a Stream.
Declaration
public override Stream GetStream(int ordinal)
Parameters
Type | Name | Description |
---|---|---|
Int32 | ordinal | The zero-based column ordinal. |
Returns
Type | Description |
---|---|
Stream | The returned object. |
Overrides
| Improve this DocGetStreamAsync(Int32)
Retrieves data as a Stream.
Declaration
public Task<Stream> GetStreamAsync(int ordinal)
Parameters
Type | Name | Description |
---|---|---|
Int32 | ordinal | The zero-based column ordinal. |
Returns
Type | Description |
---|---|
Task<Stream> | The returned object. |
GetStreamAsync(Int32, CancellationToken)
Retrieves data as a Stream.
Declaration
public Task<Stream> GetStreamAsync(int ordinal, CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
Int32 | ordinal | The zero-based column ordinal. |
CancellationToken | cancellationToken | The token to monitor for cancellation requests. The default value is None. |
Returns
Type | Description |
---|---|
Task<Stream> | The returned object. |
GetString(Int32)
Gets the value of the specified column as an instance of String.
Declaration
public override string GetString(int ordinal)
Parameters
Type | Name | Description |
---|---|---|
Int32 | ordinal | The zero-based column ordinal. |
Returns
Type | Description |
---|---|
String | The value of the specified column. |
Overrides
| Improve this DocGetTextReader(Int32)
Retrieves data as a TextReader.
Declaration
public override TextReader GetTextReader(int ordinal)
Parameters
Type | Name | Description |
---|---|---|
Int32 | ordinal | The zero-based column ordinal. |
Returns
Type | Description |
---|---|
TextReader | The returned object. |
Overrides
| Improve this DocGetTextReaderAsync(Int32)
Retrieves data as a TextReader.
Declaration
public Task<TextReader> GetTextReaderAsync(int ordinal)
Parameters
Type | Name | Description |
---|---|---|
Int32 | ordinal | The zero-based column ordinal. |
Returns
Type | Description |
---|---|
Task<TextReader> | The returned object. |
GetTextReaderAsync(Int32, CancellationToken)
Retrieves data as a TextReader.
Declaration
public Task<TextReader> GetTextReaderAsync(int ordinal, CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
Int32 | ordinal | The zero-based column ordinal. |
CancellationToken | cancellationToken | The token to monitor for cancellation requests. The default value is None. |
Returns
Type | Description |
---|---|
Task<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 |
---|---|---|
Int32 | ordinal | The zero-based column ordinal. |
Returns
Type | Description |
---|---|
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 |
---|---|---|
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 GetProviderSpecificValue(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
GetValue(Int32)
Gets the value of the specified column as an instance of Object.
Declaration
public override object GetValue(int ordinal)
Parameters
Type | Name | Description |
---|---|---|
Int32 | ordinal | The zero-based column ordinal. |
Returns
Type | Description |
---|---|
Object | The value of the specified column. |
Overrides
| Improve this DocGetValues(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 |
---|---|---|
Object[] | values | An array of Object into which to copy the attribute columns. |
Returns
Type | Description |
---|---|
Int32 | The number of instances of Object in the array. |
Overrides
| Improve this DocIsDBNull(Int32)
Gets a value that indicates whether the column contains nonexistent or missing values.
Declaration
public override bool IsDBNull(int ordinal)
Parameters
Type | Name | Description |
---|---|---|
Int32 | ordinal | The zero-based column ordinal. |
Returns
Type | Description |
---|---|
Boolean | true if the specified column is equivalent to DBNull; otherwise false. |
Overrides
| Improve this DocIsDBNullAsync(Int32, CancellationToken)
An asynchronous version of IsDBNull(Int32), which gets a value that indicates whether the column contains non-existent or missing values.
The cancellationToken
parameter is currently ignored.
Declaration
public override Task<bool> IsDBNullAsync(int ordinal, CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
Int32 | ordinal | The zero-based column to be retrieved. |
CancellationToken | cancellationToken | The token to monitor for cancellation requests. |
Returns
Type | Description |
---|---|
Task<Boolean> | true if the specified column value is equivalent to DBNull otherwise false. |
Overrides
| Improve this DocNextResult()
Advances the reader to the next result when reading the results of a batch of statements.
Declaration
public override bool NextResult()
Returns
Type | Description |
---|---|
Boolean |
Overrides
| Improve this DocNextResultAsync(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 |
---|---|---|
CancellationToken | cancellationToken | The token to monitor for cancellation requests. |
Returns
Type | Description |
---|---|
Task<Boolean> | A task representing the asynchronous operation. |
Overrides
| Improve this DocRead()
Advances the reader to the next record in a result set.
Declaration
public override bool Read()
Returns
Type | Description |
---|---|
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 |
---|---|---|
CancellationToken | cancellationToken | The token to monitor for cancellation requests. |
Returns
Type | Description |
---|---|
Task<Boolean> | A task representing the asynchronous operation. |
Overrides
Events
| Improve this DocReaderClosed
Is raised whenever Close() is called.
Declaration
public event EventHandler ReaderClosed
Event Type
Type | Description |
---|---|
EventHandler |
Explicit Interface Implementations
| Improve this DocIDbColumnSchemaGenerator.GetColumnSchema()
Declaration
ReadOnlyCollection<DbColumn> IDbColumnSchemaGenerator.GetColumnSchema()
Returns
Type | Description |
---|---|
ReadOnlyCollection<DbColumn> |