Class SpannerDataReader
Reads a forward-only stream of rows from a data source.
Inherited Members
Namespace: Google.Cloud.Spanner.Data
Assembly: Google.Cloud.Spanner.Data.dll
Syntax
public sealed class SpannerDataReader : DbDataReader, IEnumerable, IDataReader, IDataRecord, IDisposable, IAsyncDisposable
Properties
Depth
Gets a value indicating the depth of nesting for the current row.
Declaration
public override int Depth { get; }
Property Value
Type | Description |
---|---|
int | The depth of nesting for the current row. |
Overrides
FieldCount
Gets the number of columns in the current row.
Declaration
public override int FieldCount { get; }
Property Value
Type | Description |
---|---|
int | The number of columns in the current row. |
Overrides
Exceptions
Type | Condition |
---|---|
NotSupportedException | There is no current connection to an instance of SQL Server. |
HasRows
Gets a value that indicates whether the SpannerDataReader contains one or more rows. If any rows have been read, this will continue to return true even when there are no more rows.
Declaration
public override bool HasRows { get; }
Property Value
Type | Description |
---|---|
bool |
Overrides
IsClosed
Gets a value indicating whether the DbDataReader is closed.
Declaration
public override bool IsClosed { get; }
Property Value
Type | Description |
---|---|
bool | true if the DbDataReader is closed; otherwise, false. |
Overrides
Exceptions
Type | Condition |
---|---|
InvalidOperationException | The DbDataReader is closed. |
this[int]
Gets the value of the specified column as an instance of object.
Declaration
public override object this[int i] { get; }
Parameters
Type | Name | Description |
---|---|---|
int | i |
Property Value
Type | Description |
---|---|
object | The value of the specified column. |
Overrides
Exceptions
Type | Condition |
---|---|
IndexOutOfRangeException | The column index is out of range. |
this[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
Exceptions
Type | Condition |
---|---|
IndexOutOfRangeException | No column with the specified name was found. |
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 |
---|---|
int | The number of rows changed, inserted, or deleted. -1 for SELECT statements; 0 if no rows were affected or the statement failed. |
Overrides
Methods
Close()
Closes the DbDataReader object.
Declaration
public override void Close()
Overrides
Dispose(bool)
Releases the managed resources used by the DbDataReader and optionally releases the unmanaged resources.
Declaration
protected override void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
bool | disposing | true to release managed and unmanaged resources; false to release only unmanaged resources. |
Overrides
GetBoolean(int)
Gets the value of the specified column as a Boolean.
Declaration
public override bool GetBoolean(int i)
Parameters
Type | Name | Description |
---|---|---|
int | i |
Returns
Type | Description |
---|---|
bool | The value of the specified column. |
Overrides
Exceptions
Type | Condition |
---|---|
IndexOutOfRangeException | The column index is out of range. |
InvalidCastException | The specified cast is not valid. |
GetByte(int)
Gets the value of the specified column as a byte.
Declaration
public override byte GetByte(int i)
Parameters
Type | Name | Description |
---|---|---|
int | i |
Returns
Type | Description |
---|---|
byte | The value of the specified column. |
Overrides
Exceptions
Type | Condition |
---|---|
IndexOutOfRangeException | The column index is out of range. |
InvalidCastException | The specified cast is not valid. |
GetBytes(int, long, byte[], int, int)
Reads a specified number of bytes from the specified column starting at a specified index and writes them to a buffer starting at a specified position in the buffer.
Declaration
public override long GetBytes(int ordinal, long fieldOffset, byte[] buffer, int bufferOffset, int length)
Parameters
Type | Name | Description |
---|---|---|
int | ordinal | The zero-based column ordinal. |
long | fieldOffset | |
byte[] | buffer | The buffer into which to copy the data. |
int | bufferOffset | The index with the buffer to which the data will be copied. |
int | length | The maximum number of characters to read. |
Returns
Type | Description |
---|---|
long | The actual number of bytes read. |
Overrides
Exceptions
Type | Condition |
---|---|
IndexOutOfRangeException | The column index is out of range. |
InvalidCastException | The specified cast is not valid. |
GetChar(int)
Gets the value of the specified column as a single character.
Declaration
public override char GetChar(int i)
Parameters
Type | Name | Description |
---|---|---|
int | i |
Returns
Type | Description |
---|---|
char | The value of the specified column. |
Overrides
Exceptions
Type | Condition |
---|---|
IndexOutOfRangeException | The column index is out of range. |
InvalidCastException | The specified cast is not valid. |
GetChars(int, long, char[], int, int)
Reads a specified number of characters from a specified column starting at a specified index, and writes them to a buffer starting at a specified position.
Declaration
public override long GetChars(int i, long fieldoffset, char[] buffer, int bufferoffset, int length)
Parameters
Type | Name | Description |
---|---|---|
int | i | |
long | fieldoffset | |
char[] | buffer | The buffer into which to copy the data. |
int | bufferoffset | |
int | length | The maximum number of characters to read. |
Returns
Type | Description |
---|---|
long | The actual number of characters read. |
Overrides
GetDataTypeName(int)
Gets name of the data type of the specified column.
Declaration
public override string GetDataTypeName(int i)
Parameters
Type | Name | Description |
---|---|---|
int | i |
Returns
Type | Description |
---|---|
string | The name of the data type. |
Overrides
Exceptions
Type | Condition |
---|---|
IndexOutOfRangeException | The column index is out of range. |
GetDateTime(int)
Gets the value of the specified column as a DateTime object.
Declaration
public override DateTime GetDateTime(int i)
Parameters
Type | Name | Description |
---|---|---|
int | i |
Returns
Type | Description |
---|---|
DateTime | The value of the specified column. |
Overrides
Exceptions
Type | Condition |
---|---|
IndexOutOfRangeException | The column index is out of range. |
InvalidCastException | The specified cast is not valid. |
GetDecimal(int)
Gets the value of the specified column as a decimal.
Declaration
public override decimal GetDecimal(int i)
Parameters
Type | Name | Description |
---|---|---|
int | i |
Returns
Type | Description |
---|---|
decimal | The value of the specified column. |
Overrides
Exceptions
Type | Condition |
---|---|
IndexOutOfRangeException | The column index is out of range. |
InvalidCastException | The specified cast is not valid. |
GetDouble(int)
Gets the value of the specified column as a double-precision floating point number.
Declaration
public override double GetDouble(int i)
Parameters
Type | Name | Description |
---|---|---|
int | i |
Returns
Type | Description |
---|---|
double | The value of the specified column. |
Overrides
Exceptions
Type | Condition |
---|---|
InvalidCastException | The specified cast is not valid. |
GetEnumerator()
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
GetFieldType(int)
Gets the data type of the specified column.
Declaration
public override Type GetFieldType(int i)
Parameters
Type | Name | Description |
---|---|---|
int | i |
Returns
Type | Description |
---|---|
Type | The data type of the specified column. |
Overrides
Exceptions
Type | Condition |
---|---|
IndexOutOfRangeException | The column index is out of range. |
InvalidCastException | The specified cast is not valid. |
GetFieldValue<T>(int)
Gets the value of the specified column as the requested type.
Declaration
public override T GetFieldValue<T>(int ordinal)
Parameters
Type | Name | Description |
---|---|---|
int | ordinal | The zero-based column ordinal. |
Returns
Type | Description |
---|---|
T | The value of the specified column. |
Type Parameters
Name | Description |
---|---|
T | The type of the value to be returned. |
Overrides
Exceptions
Type | Condition |
---|---|
InvalidOperationException | The connection was dropped or closed during data retrieval. |
IndexOutOfRangeException | The column index is out of range. |
InvalidCastException | The value returned by the database doesn't match or cannot be cast to T. |
GetFieldValue<T>(string)
Gets the value of the specified column as type T.
Declaration
public T GetFieldValue<T>(string columnName)
Parameters
Type | Name | Description |
---|---|---|
string | columnName | The name of the column whose value will be returned. Must not be null. |
Returns
Type | Description |
---|---|
T | The value of the column at the current row, converted to type T. |
Type Parameters
Name | Description |
---|---|
T | The expected return type. If possible the return type will be converted to this type. If conversion is requested between incompatible types, an InvalidOperationException will be thrown. If the conversion fails due to the contents returned (for example a string representing a boolean does not have either 'true' or 'false') then a FormatException exception will be thrown as documented by the Convert class. |
GetFloat(int)
Gets the value of the specified column as a single-precision floating point number.
Declaration
public override float GetFloat(int i)
Parameters
Type | Name | Description |
---|---|---|
int | i |
Returns
Type | Description |
---|---|
float | The value of the specified column. |
Overrides
Exceptions
Type | Condition |
---|---|
IndexOutOfRangeException | The column index is out of range. |
InvalidCastException | The specified cast is not valid. |
GetGuid(int)
Gets the value of the specified column as a globally unique identifier (GUID).
Declaration
public override Guid GetGuid(int i)
Parameters
Type | Name | Description |
---|---|---|
int | i |
Returns
Type | Description |
---|---|
Guid | The value of the specified column. |
Overrides
Exceptions
Type | Condition |
---|---|
IndexOutOfRangeException | The column index is out of range. |
InvalidCastException | The specified cast is not valid. |
GetInt16(int)
Gets the value of the specified column as a 16-bit signed integer.
Declaration
public override short GetInt16(int i)
Parameters
Type | Name | Description |
---|---|---|
int | i |
Returns
Type | Description |
---|---|
short | The value of the specified column. |
Overrides
Exceptions
Type | Condition |
---|---|
IndexOutOfRangeException | The column index is out of range. |
InvalidCastException | The specified cast is not valid. |
GetInt32(int)
Gets the value of the specified column as a 32-bit signed integer.
Declaration
public override int GetInt32(int i)
Parameters
Type | Name | Description |
---|---|---|
int | i |
Returns
Type | Description |
---|---|
int | The value of the specified column. |
Overrides
Exceptions
Type | Condition |
---|---|
IndexOutOfRangeException | The column index is out of range. |
InvalidCastException | The specified cast is not valid. |
GetInt64(int)
Gets the value of the specified column as a 64-bit signed integer.
Declaration
public override long GetInt64(int i)
Parameters
Type | Name | Description |
---|---|---|
int | i |
Returns
Type | Description |
---|---|
long | The value of the specified column. |
Overrides
Exceptions
Type | Condition |
---|---|
IndexOutOfRangeException | The column index is out of range. |
InvalidCastException | The specified cast is not valid. |
GetJsonValue(int)
Gets the value of the specified column as a pure Protobuf type.
Declaration
public Value GetJsonValue(int i)
Parameters
Type | Name | Description |
---|---|---|
int | i | The index of the column whose value will be returned. |
Returns
Type | Description |
---|---|
Value | The raw protobuf as a Value. |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | The reader is not currently positioned on a valid row. |
GetName(int)
Gets the name of the column, given the zero-based column ordinal.
Declaration
public override string GetName(int i)
Parameters
Type | Name | Description |
---|---|---|
int | i |
Returns
Type | Description |
---|---|
string | The name of the specified column. |
Overrides
GetNumeric(int)
Gets the value of the specified column as type Google.Cloud.Spanner.V1.SpannerNumeric.
Declaration
public SpannerNumeric GetNumeric(int i)
Parameters
Type | Name | Description |
---|---|---|
int | i | The index of the column to retrieve. |
Returns
Type | Description |
---|---|
SpannerNumeric | The value converted to a Google.Cloud.Spanner.V1.SpannerNumeric. |
GetOrdinal(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 |
---|---|
int | The zero-based column ordinal. |
Overrides
Exceptions
Type | Condition |
---|---|
IndexOutOfRangeException | The name specified is not a valid column name. |
GetOrdinalAsync(string, CancellationToken)
Returns the column ordinal given the name of the column, asynchronously requesting metadata from the database if necessary.
Declaration
public Task<int> GetOrdinalAsync(string name, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
string | name | The name of the column. |
CancellationToken | cancellationToken | A cancellation token to cancel reading metadata. Defaults to None. |
Returns
Type | Description |
---|---|
Task<int> | The zero-based column ordinal. |
GetPgNumeric(int)
Gets the value of the specified column as type Google.Cloud.Spanner.V1.PgNumeric.
Declaration
public PgNumeric GetPgNumeric(int i)
Parameters
Type | Name | Description |
---|---|---|
int | i | The index of the column to retrieve. |
Returns
Type | Description |
---|---|
PgNumeric | The value converted to a Google.Cloud.Spanner.V1.PgNumeric. |
GetReadTimestamp()
Gets the read timestamp if ReturnReadTimestamp was true
else returns null
.
Declaration
public Timestamp GetReadTimestamp()
Returns
Type | Description |
---|---|
Timestamp | The value converted to a Timestamp, or |
Remarks
The read timestamp can be read before Read() or ReadAsync(CancellationToken) is called.
GetReadTimestampAsync(CancellationToken)
Gets the read timestamp if ReturnReadTimestamp was true
else returns null
.
Declaration
public Task<Timestamp> GetReadTimestampAsync(CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
CancellationToken | cancellationToken |
Returns
Type | Description |
---|---|
Task<Timestamp> | The value converted to a Timestamp, or |
GetSchemaTable()
When enabled, returns the schema of the query as a DataTable. This feature needs to be enabled in the connection string via the EnableGetSchemaTable property.
Declaration
public override DataTable GetSchemaTable()
Returns
Type | Description |
---|---|
DataTable | A |
Overrides
Remarks
DbDataAdapter will use this method automatically, but there is not enough information
available for it to do so to reliably manage data sets. This method returns null
by default to
avoid this causing problems.
When the EnableGetSchemaTable
property in the connection string is set to true
, a
DataTable
is returned with the following columns populated:
- ColumnName (String): The name of the column
- ColumnOrdinal (Int32): The ordinal value of the column
- DataType (Type): The default CLR type of the column
- ProviderType (SpannerDbType): The Spanner-specific data type of the column
- ColumnSize
- NumericPrecision
- NumericScale
GetSpannerDate(int)
Gets the value of the specified column as type Google.Cloud.Spanner.V1.SpannerDate.
Declaration
public SpannerDate GetSpannerDate(int i)
Parameters
Type | Name | Description |
---|---|---|
int | i | The index of the column to retrieve. |
Returns
Type | Description |
---|---|
SpannerDate | The value converted to a Google.Cloud.Spanner.V1.SpannerDate. |
GetString(int)
Gets the value of the specified column as an instance of string.
Declaration
public override string GetString(int i)
Parameters
Type | Name | Description |
---|---|---|
int | i |
Returns
Type | Description |
---|---|
string | The value of the specified column. |
Overrides
Exceptions
Type | Condition |
---|---|
IndexOutOfRangeException | The column index is out of range. |
InvalidCastException | The specified cast is not valid. |
GetTimestamp(int)
Gets the value of the specified column as type Timestamp.
Declaration
public Timestamp GetTimestamp(int i)
Parameters
Type | Name | Description |
---|---|---|
int | i | The index of the column to retrieve. |
Returns
Type | Description |
---|---|
Timestamp | The value converted to a Timestamp. |
GetValue(int)
Gets the value of the specified column as an instance of object.
Declaration
public override object GetValue(int i)
Parameters
Type | Name | Description |
---|---|---|
int | i |
Returns
Type | Description |
---|---|
object | The value of the specified column. |
Overrides
Exceptions
Type | Condition |
---|---|
IndexOutOfRangeException | The column index is out of range. |
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 |
---|---|---|
object[] | values | An array of object into which to copy the attribute columns. |
Returns
Type | Description |
---|---|
int | The number of instances of object in the array. |
Overrides
IsDBNull(int)
Gets a value that indicates whether the column contains nonexistent or missing values.
Declaration
public override bool IsDBNull(int i)
Parameters
Type | Name | Description |
---|---|---|
int | i |
Returns
Type | Description |
---|---|
bool | true if the specified column is equivalent to DBNull; otherwise, false. |
Overrides
Exceptions
Type | Condition |
---|---|
IndexOutOfRangeException | The column index is out of range. |
NextResult()
Advances the reader to the next result when reading the results of a batch of statements.
Declaration
public override bool NextResult()
Returns
Type | Description |
---|---|
bool |
Overrides
Read()
Advances the reader to the next record in a result set.
Declaration
public override bool Read()
Returns
Type | Description |
---|---|
bool |
Overrides
ReadAsync(CancellationToken)
Reads the next row of values from Cloud Spanner. Important: Cloud Spanner supports limited cancellation of this task.
Declaration
public override Task<bool> ReadAsync(CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
CancellationToken | cancellationToken | A cancellation token to cancel the read. Cloud Spanner currently supports limited cancellation while advancing the read to the next row. |
Returns
Type | Description |
---|---|
Task<bool> | True if another row was read. |