MySqlSharp.Provider
Class MySqlDataReader

Provides a means of reading a forward-only stream of rows from a mySQL database.

To create a MySqlDataReader, you must call the MySqlSharp.Provider.MySqlCommand.ExecuteReader method of the MySqlSharp.Provider.MySqlCommand object, rather than directly using a constructor.

While the MySqlDataReader is in use, the associated MySqlSharp.Provider.MySqlConnection is busy serving the MySqlDataReader, and no other operations can be performed on the MySqlSharp.Provider.MySqlConnection other than closing it. This is the case until the MySqlSharp.Provider.MySqlDataReader.Close method of the MySqlDataReader is called. For example, you cannot retrieve output parameters until after you call MySqlSharp.Provider.MySqlDataReader.Close.

Property Summary
int Depth
         Gets a value indicating the depth of nesting for the current row.
int FieldCount
         Gets the number of columns in the current row.
bool IsClosed
         Gets a value indicating whether the data reader is closed.
object Item[int i]
         Gets the value of the specified column in its native format given the column ordinal.
object Item[string fieldName]
         Gets the value of the specified column in its native format given the column name.
int RecordsAffected
         Gets the number of rows changed, inserted, or deleted by execution of the mySQL statement.

Method Summary
void Close()
         Closes the MySqlSharp.Provider.MySqlDataReader object.
void Dispose()
         This member supports the .NET Framework infrastructure and is not intended to be used directly from your code.
bool GetBoolean(int i)
         This member supports the .NET Framework infrastructure and is not intended to be used directly from your code.
byte GetByte(int i)
         Gets the value of the specified column as a Byte.
long GetBytes(int i, long dataIndex, byte[] buffer, int bufferIndex, int length)
         Reads a stream of bytes from the specified column offset into the buffer an array starting at the given buffer offset.
char GetChar(int i)
         This member supports the .NET Framework infrastructure and is not intended to be used directly from your code.
long GetChars(int i, long dataIndex, char[] buffer, int bufferIndex, int length)
         Reads a stream of characters from the specified column offset into the buffer as an array starting at the given buffer offset.
System.Data.IDataReader GetData(int i)
         This member supports the .NET Framework infrastructure and is not intended to be used directly from your code.
string GetDataTypeName(int i)
         Gets the name of the source data type.
System.DateTime GetDateTime(int i)
         Gets the value of the specified column as a System.DateTime object.
decimal GetDecimal(int i)
         Gets the value of the specified column as a System.Decimal object.
double GetDouble(int i)
         Gets the value of the specified column as a double-precision floating point number.
System.Collections.IEnumerator GetEnumerator()
         This member supports the .NET Framework infrastructure and is not intended to be used directly from your code.
System.Type GetFieldType(int i)
         Gets the System.Type information corresponding to the type of System.Object that would be returned from MySqlSharp.Provider.MySqlDataReader.GetValue(System.Int32).
float GetFloat(int i)
         Gets the value of the specified column as a single-precision floating point number.
System.Guid GetGuid(int i)
         This member supports the .NET Framework infrastructure and is not intended to be used directly from your code.
short GetInt16(int i)
         Gets the value of the specified column as a 16-bit signed integer.
int GetInt32(int i)
         Gets the value of the specified column as a 32-bit signed integer.
long GetInt64(int i)
         Gets the value of the specified column as a 64-bit signed integer.
string GetName(int i)
         Gets the name of the specified column.
int GetOrdinal(string name)
         Gets the column ordinal, given the name of the column.
System.Data.DataTable GetSchemaTable()
         This member supports the .NET Framework infrastructure and is not intended to be used directly from your code.
string GetString(int i)
         Gets the value of the specified column as a string.
object GetValue(int i)
         Gets the value of the specified column in its native format.
int GetValues(object[] buffer)
         Gets all attribute columns in the collection for the current row.
bool IsDBNull(int i)
         Gets a value indicating whether the column contains non-existent or missing values.
bool NextResult()
         Advances to the end of the current result and executes the next query.
bool Read()
         Advances the MySqlSharp.Provider.MySqlDataReader to the next record.

Methods inherited from class System.Object
Equals, Finalize, GetHashCode, GetType, MemberwiseClone, ToString


Property Detail

Depth

public int Depth

Gets a value indicating the depth of nesting for the current row.

The outermost table has a depth of zero. The mySQL .NET Data Provider does not support nesting and always returns zero.

Value:
The depth of nesting for the current row.

FieldCount

public int FieldCount

Gets the number of columns in the current row.

Value:
When not positioned in a valid recordset, 0; otherwise the number of columns in the current row. The default is -1.

IsClosed

public bool IsClosed

Gets a value indicating whether the data reader is closed.

IsClosed and MySqlSharp.Provider.MySqlDataReader.RecordsAffected are the only properties that you can call after the MySqlSharp.Provider.MySqlDataReader is closed.

Value:
true if the MySqlSharp.Provider.MySqlDataReader is closed; otherwise, false.

Item

public object this[int i]

Gets the value of the specified column in its native format given the column ordinal.


Item

public object this[string fieldName]

Gets the value of the specified column in its native format given the column name.


RecordsAffected

public int RecordsAffected

Gets the number of rows changed, inserted, or deleted by execution of the mySQL statement.

Value:
The number of rows changed, inserted, or deleted; 0 if no rows were affected or the statement failed; and -1 for SELECT statements.
Method Detail

Close

public void Close()

Closes the MySqlSharp.Provider.MySqlDataReader object.

You must explicitly call the Close method when you are through using the MySqlSharp.Provider.MySqlDataReader to use the associated MySqlSharp.Provider.MySqlConnection for any other purpose.

The Close method executes all the remaining Querys, increasing the amount of time it takes to close a MySqlSharp.Provider.MySqlDataReader that was used to process a large or complicated query. In cases where the remaining querys and the number of records affected by a query are not significant, the amount of time it takes to close the MySqlSharp.Provider.MySqlDataReader can be reduced by calling the MySqlSharp.Provider.MySqlCommand.Cancel method of the associated MySqlSharp.Provider.MySqlCommand object before calling the Close method.


Dispose

public void Dispose()

This member supports the .NET Framework infrastructure and is not intended to be used directly from your code.


GetBoolean

public bool GetBoolean(int i)

This member supports the .NET Framework infrastructure and is not intended to be used directly from your code.


GetByte

public byte GetByte(int i)

Gets the value of the specified column as a Byte.

Parameters:
i - The zero-based column ordinal.
Returns:
The value of the specified column as a Byte.

GetBytes

public long GetBytes(int i,
                     long dataIndex,
                     byte[] buffer,
                     int bufferIndex,
                     int length)

Reads a stream of bytes from the specified column offset into the buffer an array starting at the given buffer offset.

The actual number of bytes read can be less than the requested length, if the end of the field is reached. If you pass a buffer that is a null reference (Nothing in Visual Basic), GetBytes returns the length of the field in bytess.

No conversions are performed, therefore the data retrieved must already be a byte array.

Parameters:
i - The zero-based column ordinal.
dataIndex - The index within the field from which to begin the read operation.
buffer - The buffer into which to read the stream of bytes.
bufferIndex - The index for buffer to begin the read operation.
length - The maximum length to copy into the buffer.
Returns:
The actual number of bytes read.

GetChar

public char GetChar(int i)

This member supports the .NET Framework infrastructure and is not intended to be used directly from your code.


GetChars

public long GetChars(int i,
                     long dataIndex,
                     char[] buffer,
                     int bufferIndex,
                     int length)

Reads a stream of characters from the specified column offset into the buffer as an array starting at the given buffer offset.

The actual number of characters read can be less than the requested length, if the end of the field is reached. If you pass a buffer that is a null reference (Nothing in Visual Basic), GetChars returns the length of the field in characters.

No conversions are performed, therefore the data retrieved must already be a character array.

Parameters:
i - The zero-based column ordinal.
dataIndex - The index within the row from which to begin the read operation.
buffer - The buffer into which to copy data.
bufferIndex - The index for buffer to begin the read operation.
length - The maximum number of characters to read.
Returns:
The actual number of characters read.

GetData

public System.Data.IDataReader GetData(int i)

This member supports the .NET Framework infrastructure and is not intended to be used directly from your code.


GetDataTypeName

public string GetDataTypeName(int i)

Gets the name of the source data type.

Parameters:
i - The zero-based column ordinal.
Returns:
The name of the back-end data type.

GetDateTime

public System.DateTime GetDateTime(int i)

Gets the value of the specified column as a System.DateTime object.

Parameters:
i - The zero-based column ordinal.
Returns:
The value of the specified column.

GetDecimal

public decimal GetDecimal(int i)

Gets the value of the specified column as a System.Decimal object.

Parameters:
i - The zero-based column ordinal.
Returns:
The value of the specified column.

GetDouble

public double GetDouble(int i)

Gets the value of the specified column as a double-precision floating point number.

Parameters:
i - The zero-based column ordinal.
Returns:
The value of the specified column.

GetEnumerator

private System.Collections.IEnumerator GetEnumerator()

This member supports the .NET Framework infrastructure and is not intended to be used directly from your code.


GetFieldType

public System.Type GetFieldType(int i)

Gets the System.Type information corresponding to the type of System.Object that would be returned from MySqlSharp.Provider.MySqlDataReader.GetValue(System.Int32).

Parameters:
i - The index of the field to find.
Returns:
The System.Type information corresponding to the type of System.Object that would be returned from MySqlSharp.Provider.MySqlDataReader.GetValue(System.Int32).
Throws:
System.IndexOutOfRangeException - The index passed was outside the range of 0 through MySqlSharp.Provider.MySqlDataReader.FieldCount.

GetFloat

public float GetFloat(int i)

Gets the value of the specified column as a single-precision floating point number.

Parameters:
i - The zero-based column ordinal.
Returns:
The value of the specified column.

GetGuid

public System.Guid GetGuid(int i)

This member supports the .NET Framework infrastructure and is not intended to be used directly from your code.


GetInt16

public short GetInt16(int i)

Gets the value of the specified column as a 16-bit signed integer.

Parameters:
i - The zero-based column ordinal.
Returns:
The value of the specified column.

GetInt32

public int GetInt32(int i)

Gets the value of the specified column as a 32-bit signed integer.

Parameters:
i - The zero-based column ordinal.
Returns:
The value of the specified column.

GetInt64

public long GetInt64(int i)

Gets the value of the specified column as a 64-bit signed integer.

Parameters:
i - The zero-based column ordinal.
Returns:
The value of the specified column.

GetName

public string GetName(int i)

Gets the name of the specified column.

Parameters:
i - The zero-based column ordinal.
Returns:
The name of the specified column.

GetOrdinal

public int GetOrdinal(string name)

Gets the column ordinal, given the name of the column.

GetOrdinal performs a case-sensitive lookup first. If it fails, a second case-insensitive search is made.

Because ordinal-based lookups are more efficient than named lookups, it is inefficient to call GetOrdinal within a loop. Save time by calling GetOrdinal once and assigning the results to an integer variable for use within the loop.

Parameters:
name - The name of the column.
Returns:
The zero-based column ordinal.
Throws:
System.IndexOutOfRangeException - The name specified is not a valid column name.

GetSchemaTable

public System.Data.DataTable GetSchemaTable()

This member supports the .NET Framework infrastructure and is not intended to be used directly from your code.


GetString

public string GetString(int i)

Gets the value of the specified column as a string.

Parameters:
i - The zero-based column ordinal.
Returns:
The value of the specified column.

GetValue

public object GetValue(int i)

Gets the value of the specified column in its native format.

GetValue returns data using the .NET Framework types.

Parameters:
i - The zero-based column ordinal.
Returns:
This method returns System.DBNull for null database columns.

GetValues

public int GetValues(object[] buffer)

Gets all attribute columns in the collection for the current row.

For most applications, this method provides an efficient means for retrieving all columns, rather than retrieving each column individually.

You can pass an System.Object array that contains fewer than the number of columns contained in the resulting row. Only the amount of data the System.Object array holds is copied to the array. You can also pass an System.Object array whose length is more than the number of columns contained in the resulting row.

This method returns System.DBNull for null database columns.

Parameters:
buffer - An array of System.Object into which to copy the attribute columns.
Returns:
The number of instances of System.Object in the array.

IsDBNull

public bool IsDBNull(int i)

Gets a value indicating whether the column contains non-existent or missing values.

Call this method to check for null column values before calling the typed get methods (for example, MySqlSharp.Provider.MySqlDataReader.GetInt32(System.Int32), MySqlSharp.Provider.MySqlDataReader.GetString(System.Int32), and so on) to avoid raising an error.

Parameters:
i - The zero-based column ordinal.
Returns:
true if the specified column value is equivalent to System.DBNull; otherwise, false.

NextResult

public bool NextResult()

Advances to the end of the current result and executes the next query.

Used to process multiple results, which can be generated by executing batch mySQL statements.

By default, the data reader is positioned on the first result.

Returns:
true if there are more result sets; otherwise, false.
Throws:
MySqlSharp.Provider.MySqlException - Query failed.

Read

public bool Read()

Advances the MySqlSharp.Provider.MySqlDataReader to the next record.

The default position of the MySqlSharp.Provider.MySqlDataReader is prior to the first record. Therefore, you must call Read to begin accessing any data.

Only one MySqlSharp.Provider.MySqlDataReader per associated MySqlSharp.Provider.MySqlConnection may be open at a time, and any attempt to open another will fail until the first one is closed. Similarly, while the MySqlSharp.Provider.MySqlDataReader is in use, the associated MySqlSharp.Provider.MySqlConnection is busy serving it until you call Close.

Returns:
true if there are more rows; otherwise, false.