MySqlSharp.Provider.ClientAPI
Class MySql

This class contains static functions bindings to the mySql C client API.

Functions that return a value generally return a pointer or an integer. Unless specified otherwise, functions returning a pointer return a non-null value to indicate success or a null value to indicate an error, and functions returning an integer return zero to indicate success or non-zero to indicate an error. Note that "non-zero" means just that. Unless the function description says otherwise, do not test against a value other than zero.

When a function returns an error, the Errors subsection of the function description lists the possible types of errors. You can find out which of these occurred by calling MySqlSharp.Provider.ClientAPI.MySql.ErrNo(System.IntPtr). A string representation of the error may be obtained by calling MySqlSharp.Provider.ClientAPI.MySql.Error(System.IntPtr).

Field Summary
uint Port
         The default mySql server port number.

Method Summary
ulong AffectedRows(System.IntPtr mysql)
         Returns the number of rows changed by the last UPDATE, deleted by the last DELETE or inserted by the last INSERT statement. May be called immediately after MySqlSharp.Provider.ClientAPI.MySql.Query(System.IntPtr,System.String) for UPDATE, DELETE, or INSERT statements. For SELECT statements, AffectedRows works like MySqlSharp.Provider.ClientAPI.MySql.NumRows(System.IntPtr).
byte ChangeUser(System.IntPtr mysql, string user, string password, string db)
         Changes the user and causes the database specified by db to become the default (current) database on the connection specified by mysql. In subsequent queries, this database is the default for table references that do not include an explicit database specifier.
string CharacterSetName(System.IntPtr mysql)
         Returns the default character set for the current connection.
void Close(System.IntPtr mysql)
         Closes a previously opened connection. Close also deallocates the connection handle pointed to by mysql if the handle was allocated automatically by MySqlSharp.Provider.ClientAPI.MySql.Init(System.IntPtr) or MySqlSharp.Provider.ClientAPI.MySql.Connect(System.IntPtr,System.String,System.String,System.String).
System.IntPtr Connect(System.IntPtr mysql, string host, string user, string passwd)
         This function is deprecated. It is preferable to use MySqlSharp.Provider.ClientAPI.MySql.RealConnect(System.IntPtr,System.String,System.String,System.String,System.String,System.UInt32,System.String,System.UInt32) instead.
void DataSeek(System.IntPtr result, ulong offset)
         Seeks to an arbitrary row in a query result set. This requires that the result set structure contains the entire result of the query, so DataSeek may be used in conjunction only with MySqlSharp.Provider.ClientAPI.MySql.StoreResult(System.IntPtr), not with MySqlSharp.Provider.ClientAPI.MySql.UseResult(System.IntPtr).
int ErrNo(System.IntPtr mysql)
         For the connection specified by mysql, ErrNo returns the error code for the most recently invoked API function that can succeed or fail. A return value of zero means that no error occurred.
string Error(System.IntPtr mysql)
         For the connection specified by mysql, Error returns the error message for the most recently invoked API function that can succeed or fail. An empty string ("") is returned if no error occurred.
MySqlSharp.Provider.ClientAPI.Field FetchField(System.IntPtr result)
         Returns the definition of one column of a result set as a MYSQL_FIELD structure. Call this function repeatedly to retrieve information about all columns in the result set. FetchField returns null when no more fields are left.
MySqlSharp.Provider.ClientAPI.Field FetchFieldDirect(System.IntPtr result, uint fieldnr)
         Given a field number fieldnr for a column within a result set, returns that column's field definition as a MYSQL_FIELD structure. You may use this function to retrieve the definition for an arbitrary column. The value of fieldnr should be in the range from 0 to MySqlSharp.Provider.ClientAPI.MySql.NumFields(System.IntPtr)-1.
MySqlSharp.Provider.ClientAPI.Field[] FetchFields(System.IntPtr result)
         Returns an array of all MYSQL_FIELD structures for a result set. Each structure provides the field definition for one column of the result set.
ulong[] FetchLengths(System.IntPtr result)
         Returns the lengths of the columns of the current row within a result set. If the result set contains binary data, you must use this function to determine the size of the data.
System.IntPtr[] FetchRow(System.IntPtr result)
         Retrieves the next row of a result set. When used after MySqlSharp.Provider.ClientAPI.MySql.StoreResult(System.IntPtr), FetchRow returns null when there are no more rows to retrieve. When used after MySqlSharp.Provider.ClientAPI.MySql.UseResult(System.IntPtr), FetchRow returns null when there are no more rows to retrieve or if an error occurred.
int FieldCount(System.IntPtr mysql)
         Returns the number of columns for the most recent query on the connection.
uint FieldSeek(System.IntPtr result, uint offset)
         Sets the field cursor to the given offset. The next call to MySqlSharp.Provider.ClientAPI.MySql.FetchField(System.IntPtr) will retrieve the field definition of the column associated with that offset.
uint FieldTell(System.IntPtr result)
         Returns the position of the field cursor used for the last MySqlSharp.Provider.ClientAPI.MySql.FetchField(System.IntPtr). This value can be used as an argument to MySqlSharp.Provider.ClientAPI.MySql.FieldSeek(System.IntPtr,System.UInt32).
void FreeResult(System.IntPtr result)
         Frees the memory allocated for a result set by MySqlSharp.Provider.ClientAPI.MySql.StoreResult(System.IntPtr) and MySqlSharp.Provider.ClientAPI.MySql.UseResult(System.IntPtr). When you are done with a result set, you must free the memory it uses by calling FreeResult.
string GetClientInfo()
         Returns a string that represents the client library version.
string GetHostInfo(System.IntPtr mysql)
         Returns a string describing the type of connection in use, including the server host name.
uint GetProtoInfo(System.IntPtr mysql)
         Returns the protocol version used by current connection.
string GetServerInfo(System.IntPtr mysql)
         Returns a string that represents the server version number.
string Info(System.IntPtr mysql)
         Retrieves a string providing information about the most recently executed query, but only for the statements listed below. For other statements, Info returns NULL. The format of the string varies depending on the type of query, as described below. The numbers are illustrative only; the string will contain values appropriate for the query.
System.IntPtr Init(System.IntPtr mysql)
         Allocates or initializes a MYSQL object suitable for MySqlSharp.Provider.ClientAPI.MySql.RealConnect(System.IntPtr,System.String,System.String,System.String,System.String,System.UInt32,System.String,System.UInt32). If mysql is a null pointer, the function allocates, initializes, and returns a new object. Otherwise the object is initialized and the address of the object is returned. If Init allocates a new object, it will be freed when MySqlSharp.Provider.ClientAPI.MySql.Close(System.IntPtr) is called to close the connection.
ulong InsertId(System.IntPtr mysql)
         Returns the ID generated for an AUTO_INCREMENT column by the previous query. Use this function after you have performed an INSERT query into a table that contains an AUTO_INCREMENT field.
int NumFields(System.IntPtr result)
         Returns the number of columns in a result set.
ulong NumRows(System.IntPtr result)
         Returns the number of rows in the result set.
int Options(System.IntPtr mysql)
         Checks whether or not the connection to the server is working. If it has gone down, an automatic reconnection is attempted.
int Query(System.IntPtr conn, string query)
         Executes the SQL query pointed to by the null-terminated string query. The query must consist of a single SQL statement. You should not add a terminating semicolon (`;') or \g to the statement.
System.IntPtr RealConnect(System.IntPtr db, string host, string user, string passwd, string dbname, uint port, string socketName, uint flags)
         Attempts to establish a connection to a MySQL database engine running on host.
string RealEscapeString(System.IntPtr db, string str)
         This function is used to create a legal SQL string that you can use in a SQL statement.
string RealEscapeString(System.IntPtr db, byte[] bytes)
         This function is used to create a legal SQL string that you can use in a SQL statement.
int RealQuery(System.IntPtr db, string query, uint length)
         Executes the SQL query pointed to by query, which should be a string length bytes long. The query must consist of a single SQL statement. You should not add a terminating semicolon (`;') or \g to the statement.
System.IntPtr RowSeek(System.IntPtr result, System.IntPtr offset)
         Sets the row cursor to an arbitrary row in a query result set. This requires that the result set structure contains the entire result of the query, so RowSeek may be used in conjunction only with MySqlSharp.Provider.ClientAPI.MySql.StoreResult(System.IntPtr), not with MySqlSharp.Provider.ClientAPI.MySql.UseResult(System.IntPtr).
System.IntPtr RowTell(System.IntPtr result)
         Returns the current position of the row cursor for the last MySqlSharp.Provider.ClientAPI.MySql.FetchRow(System.IntPtr). This value can be used as an argument to MySqlSharp.Provider.ClientAPI.MySql.RowSeek(System.IntPtr,System.IntPtr).
int SelectDb(System.IntPtr mysql, string db)
         Causes the database specified by db to become the default (current) database on the connection specified by mysql. In subsequent queries, this database is the default for table references that do not include an explicit database specifier.
int Shutdown(System.IntPtr mysql)
         Asks the database server to shut down. The connected user must have shutdown privileges.
string Stat(System.IntPtr mysql)
         Returns a character string containing information similar to that provided by the mysqladmin status command. This includes uptime in seconds and the number of running threads, questions, reloads, and open tables.
System.IntPtr StoreResult(System.IntPtr mysql)
         You must call StoreResult or MySqlSharp.Provider.ClientAPI.MySql.UseResult(System.IntPtr) for every query that successfully retrieves data (SELECT, SHOW, DESCRIBE, EXPLAIN).
System.IntPtr UseResult(System.IntPtr mysql)
         You must call UseResult or MySqlSharp.Provider.ClientAPI.MySql.StoreResult(System.IntPtr) for every query that successfully retrieves data (SELECT, SHOW, DESCRIBE, EXPLAIN).

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


Field Detail

Port

public uint Port

The default mySql server port number.

Method Detail

AffectedRows

public ulong AffectedRows(System.IntPtr mysql)

Returns the number of rows changed by the last UPDATE, deleted by the last DELETE or inserted by the last INSERT statement. May be called immediately after MySqlSharp.Provider.ClientAPI.MySql.Query(System.IntPtr,System.String) for UPDATE, DELETE, or INSERT statements. For SELECT statements, AffectedRows works like MySqlSharp.Provider.ClientAPI.MySql.NumRows(System.IntPtr).

Parameters:
mysql - A pointer to the MYSQL structure used as a connection handle
Returns:
An integer greater than zero indicates the number of rows affected or retrieved. Zero indicates that no records where updated for an UPDATE statement, no rows matched the WHERE clause in the query or that no query has yet been executed. -1 indicates that the query returned an error or that, for a SELECT query, AffectedRows was called prior to calling MySqlSharp.Provider.ClientAPI.MySql.StoreResult(System.IntPtr).

ChangeUser

public byte ChangeUser(System.IntPtr mysql,
                       string user,
                       string password,
                       string db)

Changes the user and causes the database specified by db to become the default (current) database on the connection specified by mysql. In subsequent queries, this database is the default for table references that do not include an explicit database specifier.

This function was introduced in MySQL Version 3.23.3.

ChangeUser fails unless the connected user can be authenticated or if he doesn't have permission to use the database. In this case the user and database are not changed.

The db parameter may be set to null if you don't want to have a default database.

Errors:

  • CR_COMMANDS_OUT_OF_SYNC - Commands were executed in an improper order.
  • CR_SERVER_GONE_ERROR - The MySQL server has gone away.
  • CR_SERVER_LOST - The connection to the server was lost during the query.
  • CR_UNKNOWN_ERROR - An unknown error occurred.
  • ER_UNKNOWN_COM_ERROR - The MySQL server doesn't implement this command (probably an old server)
  • ER_ACCESS_DENIED_ERROR - The user or password was wrong.
  • ER_BAD_DB_ERROR - The database didn't exist.
  • ER_DBACCESS_DENIED_ERROR - The user did not have access rights to the database.
  • ER_WRONG_DB_NAME - The database name was too long.
  • Parameters:
    mysql - A pointer to the MYSQL structure used as a connection handle
    db - The new database name
    password - The new user's password
    user - The new user's login
    Returns:
    Zero for success. Non-zero if an error occurred.

    CharacterSetName

    public string CharacterSetName(System.IntPtr mysql)

    Returns the default character set for the current connection.

    Parameters:
    mysql - A pointer to the MYSQL structure used as a connection handle
    Returns:
    The default character set.

    Close

    public void Close(System.IntPtr mysql)

    Closes a previously opened connection. Close also deallocates the connection handle pointed to by mysql if the handle was allocated automatically by MySqlSharp.Provider.ClientAPI.MySql.Init(System.IntPtr) or MySqlSharp.Provider.ClientAPI.MySql.Connect(System.IntPtr,System.String,System.String,System.String).

    Parameters:
    mysql - A pointer to the MYSQL structure used as a connection handle

    Connect

    public System.IntPtr Connect(System.IntPtr mysql,
                                 string host,
                                 string user,
                                 string passwd)

    This function is deprecated. It is preferable to use MySqlSharp.Provider.ClientAPI.MySql.RealConnect(System.IntPtr,System.String,System.String,System.String,System.String,System.UInt32,System.String,System.UInt32) instead.

    Connect attempts to establish a connection to a MySQL database engine running on host. Connect must complete successfully before you can execute any of the other API functions, with the exception of MySqlSharp.Provider.ClientAPI.MySql.GetClientInfo.

    The meanings of the parameters are the same as for the corresponding parameters for MySqlSharp.Provider.ClientAPI.MySql.RealConnect(System.IntPtr,System.String,System.String,System.String,System.String,System.UInt32,System.String,System.UInt32) with the difference that the connection parameter may be null. In this case the API allocates memory for the connection structure automatically and frees it when you call MySqlSharp.Provider.ClientAPI.MySql.Close(System.IntPtr). The disadvantage of this approach is that you can't retrieve an error message if the connection fails. (To get error information from MySqlSharp.Provider.ClientAPI.MySql.ErrNo(System.IntPtr) or MySqlSharp.Provider.ClientAPI.MySql.Error(System.IntPtr), you must provide a valid MYSQL pointer.)

    Errors: same as for MySqlSharp.Provider.ClientAPI.MySql.RealConnect(System.IntPtr,System.String,System.String,System.String,System.String,System.UInt32,System.String,System.UInt32)

    Parameters:
    mysql - A pointer to the MYSQL structure used as a connection handle, can be null
    host - The name of the mySQL server host
    passwd - The user password
    user - The user login for mySQL access
    Returns:
    Same as for MySqlSharp.Provider.ClientAPI.MySql.RealConnect(System.IntPtr,System.String,System.String,System.String,System.String,System.UInt32,System.String,System.UInt32)

    DataSeek

    public void DataSeek(System.IntPtr result,
                         ulong offset)

    Seeks to an arbitrary row in a query result set. This requires that the result set structure contains the entire result of the query, so DataSeek may be used in conjunction only with MySqlSharp.Provider.ClientAPI.MySql.StoreResult(System.IntPtr), not with MySqlSharp.Provider.ClientAPI.MySql.UseResult(System.IntPtr).

    Parameters:
    result - A pointer to a mySql RESULT structure.
    offset - The offset should be a value in the range from 0 to MySqlSharp.Provider.ClientAPI.MySql.NumRows(System.IntPtr)(result)-1.

    ErrNo

    public int ErrNo(System.IntPtr mysql)

    For the connection specified by mysql, ErrNo returns the error code for the most recently invoked API function that can succeed or fail. A return value of zero means that no error occurred.

    Client error message numbers are listed in the MySQL `errmsg.h' header file. Server error message numbers are listed in `mysqld_error.h'. In the MySQL source distribution you can find a complete list of error messages and error numbers in the file `Docs/mysqld_error.txt'.

    Parameters:
    mysql - A pointer to the MYSQL structure used as a connection handle
    Returns:
    An error code value. 0 if no error occurred.

    Error

    public string Error(System.IntPtr mysql)

    For the connection specified by mysql, Error returns the error message for the most recently invoked API function that can succeed or fail. An empty string ("") is returned if no error occurred.

    Parameters:
    mysql - A pointer to the MYSQL structure used as a connection handle
    Returns:
    A character string that describes the error. An empty string if no error occurred.

    FetchField

    public MySqlSharp.Provider.ClientAPI.Field FetchField(System.IntPtr result)

    Returns the definition of one column of a result set as a MYSQL_FIELD structure. Call this function repeatedly to retrieve information about all columns in the result set. FetchField returns null when no more fields are left.

    FetchField is reset to return information about the first field each time you execute a new SELECT query. The field returned by FetchField is also affected by calls to MySqlSharp.Provider.ClientAPI.MySql.FieldSeek(System.IntPtr,System.UInt32).

    If you've called Query to perform a SELECT on a table but have not called MySqlSharp.Provider.ClientAPI.MySql.StoreResult(System.IntPtr), MySQL returns the default blob length (8K bytes) if you call FetchField to ask for the length of a BLOB field. (The 8K size is chosen because MySQL doesn't know the maximum length for the BLOB. This should be made configurable sometime.) Once you've retrieved the result set, field->max_length contains the length of the largest value for this column in the specific query.

    Returns:
    The MYSQL_FIELD structure for the current column. null if no columns are left.

    FetchFieldDirect

    public MySqlSharp.Provider.ClientAPI.Field FetchFieldDirect(System.IntPtr result,
                                                                uint fieldnr)

    Given a field number fieldnr for a column within a result set, returns that column's field definition as a MYSQL_FIELD structure. You may use this function to retrieve the definition for an arbitrary column. The value of fieldnr should be in the range from 0 to MySqlSharp.Provider.ClientAPI.MySql.NumFields(System.IntPtr)-1.


    FetchFields

    public MySqlSharp.Provider.ClientAPI.Field[] FetchFields(System.IntPtr result)

    Returns an array of all MYSQL_FIELD structures for a result set. Each structure provides the field definition for one column of the result set.

    Returns:
    An array of MySqlSharp.Provider.ClientAPI.Field for all columns of a result set.

    FetchLengths

    public ulong[] FetchLengths(System.IntPtr result)

    Returns the lengths of the columns of the current row within a result set. If the result set contains binary data, you must use this function to determine the size of the data.

    The length for empty columns and for columns containing NULL values is zero. To see how to distinguish these two cases, see the description for MySqlSharp.Provider.ClientAPI.MySql.FetchRow(System.IntPtr).

    Returns:
    An array of unsigned long integers representing the size of each column (not including any terminating null characters). null if an error occurred.

    FetchRow

    public System.IntPtr[] FetchRow(System.IntPtr result)

    Retrieves the next row of a result set. When used after MySqlSharp.Provider.ClientAPI.MySql.StoreResult(System.IntPtr), FetchRow returns null when there are no more rows to retrieve. When used after MySqlSharp.Provider.ClientAPI.MySql.UseResult(System.IntPtr), FetchRow returns null when there are no more rows to retrieve or if an error occurred.

    The number of values in the row is given by MySqlSharp.Provider.ClientAPI.MySql.NumFields(System.IntPtr). NULL values in the row are indicated by null pointers.

    The lengths of the field values in the row may be obtained by calling MySqlSharp.Provider.ClientAPI.MySql.FetchLengths(System.IntPtr). Empty fields and fields containing NULL both have length 0; you can distinguish these by checking the pointer for the field value. If the pointer is null, the field is NULL; otherwise the field is empty.

    Returns:
    A MYSQL_ROW structure for the next row. null if there are no more rows to retrieve or if an error occurred.

    FieldCount

    public int FieldCount(System.IntPtr mysql)

    Returns the number of columns for the most recent query on the connection.

    If you are using a version of MySQL earlier than Version 3.22.24, you should use unsigned int MySqlSharp.Provider.ClientAPI.MySql.NumFields(System.IntPtr) instead.

    The normal use of this function is when MySqlSharp.Provider.ClientAPI.MySql.StoreResult(System.IntPtr) returned null (and thus you have no result set pointer). In this case, you can call FieldCount to determine whether or not MySqlSharp.Provider.ClientAPI.MySql.StoreResult(System.IntPtr) should have produced a non-empty result. This allows the client program to take proper action without knowing whether or not the query was a SELECT (or SELECT-like) statement.


    FieldSeek

    public uint FieldSeek(System.IntPtr result,
                          uint offset)

    Sets the field cursor to the given offset. The next call to MySqlSharp.Provider.ClientAPI.MySql.FetchField(System.IntPtr) will retrieve the field definition of the column associated with that offset.

    To seek to the beginning of a row, pass an offset value of zero.

    Returns:
    The previous value of the field cursor.

    FieldTell

    public uint FieldTell(System.IntPtr result)

    Returns the position of the field cursor used for the last MySqlSharp.Provider.ClientAPI.MySql.FetchField(System.IntPtr). This value can be used as an argument to MySqlSharp.Provider.ClientAPI.MySql.FieldSeek(System.IntPtr,System.UInt32).

    Returns:
    The current offset of the field cursor.

    FreeResult

    public void FreeResult(System.IntPtr result)

    Frees the memory allocated for a result set by MySqlSharp.Provider.ClientAPI.MySql.StoreResult(System.IntPtr) and MySqlSharp.Provider.ClientAPI.MySql.UseResult(System.IntPtr). When you are done with a result set, you must free the memory it uses by calling FreeResult.


    GetClientInfo

    public string GetClientInfo()

    Returns a string that represents the client library version.

    Returns:
    A character string that represents the MySQL client library version.

    GetHostInfo

    public string GetHostInfo(System.IntPtr mysql)

    Returns a string describing the type of connection in use, including the server host name.

    Returns:
    A character string representing the server host name and the connection type.

    GetProtoInfo

    public uint GetProtoInfo(System.IntPtr mysql)

    Returns the protocol version used by current connection.

    Returns:
    An unsigned integer representing the protocol version used by the current connection.

    GetServerInfo

    public string GetServerInfo(System.IntPtr mysql)

    Returns a string that represents the server version number.

    Returns:
    A character string that represents the server version number.

    Info

    public string Info(System.IntPtr mysql)

    Retrieves a string providing information about the most recently executed query, but only for the statements listed below. For other statements, Info returns NULL. The format of the string varies depending on the type of query, as described below. The numbers are illustrative only; the string will contain values appropriate for the query.

    Note that Info returns a non-NULL value for the INSERT ... VALUES statement only if multiple value lists are specified in the statement.


    Init

    public System.IntPtr Init(System.IntPtr mysql)

    Allocates or initializes a MYSQL object suitable for MySqlSharp.Provider.ClientAPI.MySql.RealConnect(System.IntPtr,System.String,System.String,System.String,System.String,System.UInt32,System.String,System.UInt32). If mysql is a null pointer, the function allocates, initializes, and returns a new object. Otherwise the object is initialized and the address of the object is returned. If Init allocates a new object, it will be freed when MySqlSharp.Provider.ClientAPI.MySql.Close(System.IntPtr) is called to close the connection.

    Returns:
    An initialized MYSQL* handle. null if there was insufficient memory to allocate a new object.

    InsertId

    public ulong InsertId(System.IntPtr mysql)

    Returns the ID generated for an AUTO_INCREMENT column by the previous query. Use this function after you have performed an INSERT query into a table that contains an AUTO_INCREMENT field.

    Note that InsertId returns 0 if the previous query does not generate an AUTO_INCREMENT value. If you need to save the value for later, be sure to call InsertId immediately after the query that generates the value.

    InsertId is updated after INSERT and UPDATE statements that generate an AUTO_INCREMENT value or that set a column value to LAST_INSERT_ID(expr).

    Also note that the value of the SQL LAST_INSERT_ID() function always contains the most recently generated AUTO_INCREMENT value, and is not reset between queries because the value of that function is maintained in the server.

    Returns:
    The value of the AUTO_INCREMENT field that was updated by the previous query. Returns zero if there was no previous query on the connection or if the query did not update an AUTO_INCREMENT value.

    NumFields

    public int NumFields(System.IntPtr result)

    Returns the number of columns in a result set.

    Note that you can get the number of columns either from a pointer to a result set or to a connection handle. You would use the connection handle if MySqlSharp.Provider.ClientAPI.MySql.StoreResult(System.IntPtr) or MySqlSharp.Provider.ClientAPI.MySql.UseResult(System.IntPtr) returned null (and thus you have no result set pointer). In this case, you can call MySqlSharp.Provider.ClientAPI.MySql.FieldCount(System.IntPtr) to determine whether or not MySqlSharp.Provider.ClientAPI.MySql.StoreResult(System.IntPtr) should have produced a non-empty result. This allows the client program to take proper action without knowing whether or not the query was a SELECT (or SELECT-like) statement.

    Returns:
    An unsigned integer representing the number of fields in a result set.

    NumRows

    public ulong NumRows(System.IntPtr result)

    Returns the number of rows in the result set.

    The use of NumRows depends on whether you use MySqlSharp.Provider.ClientAPI.MySql.StoreResult(System.IntPtr) or MySqlSharp.Provider.ClientAPI.MySql.UseResult(System.IntPtr) to return the result set. If you use MySqlSharp.Provider.ClientAPI.MySql.StoreResult(System.IntPtr), NumRows) may be called immediately. If you use MySqlSharp.Provider.ClientAPI.MySql.UseResult(System.IntPtr), NumRows will not return the correct value until all the rows in the result set have been retrieved.

    Returns:
    The number of rows in the result set.

    Options

    public int Options(System.IntPtr mysql)

    Checks whether or not the connection to the server is working. If it has gone down, an automatic reconnection is attempted.

    This function can be used by clients that remain idle for a long while, to check whether or not the server has closed the connection and reconnect if necessary.

    Returns:
    Zero if the server is alive. Non-zero if an error occurred.

    Query

    public int Query(System.IntPtr conn,
                     string query)

    Executes the SQL query pointed to by the null-terminated string query. The query must consist of a single SQL statement. You should not add a terminating semicolon (`;') or \g to the statement.

    Query cannot be used for queries that contain binary data; you should use MySqlSharp.Provider.ClientAPI.MySql.RealQuery(System.IntPtr,System.String,System.UInt32) instead. (Binary data may contain the `\0' character, which Query interprets as the end of the query string.)

    If you want to know if the query should return a result set or not, you can use MySqlSharp.Provider.ClientAPI.MySql.FieldCount(System.IntPtr) to check for this.

    Returns:
    Zero if the query was successful. Non-zero if an error occurred.

    RealConnect

    public System.IntPtr RealConnect(System.IntPtr db,
                                     string host,
                                     string user,
                                     string passwd,
                                     string dbname,
                                     uint port,
                                     string socketName,
                                     uint flags)

    Attempts to establish a connection to a MySQL database engine running on host.

    RealConnect must complete successfully before you can execute any of the other API functions, with the exception of MySqlSharp.Provider.ClientAPI.MySql.GetClientInfo.

    Parameters:
    db - db should be the address of an existing MYSQL structure. Before calling RealConnect you must call MySqlSharp.Provider.ClientAPI.MySql.Init(System.IntPtr) to initialize the MYSQL structure. You can change a lot of connect options with the MySqlSharp.Provider.ClientAPI.MySql.Options(System.IntPtr) call.
    host - The value of host may be either a hostname or an IP address. If host is null or the string "localhost", a connection to the local host is assumed. Named pipes are used instead of TCP/IP to connect to the server.
    user - Contains the user's MySQL login ID. If it is null, the current user is assumed.
    passwd - Contains the password for user. If it is null, only entries in the user table for the user that have a blank (empty) password field will be checked for a match. This allows the database administrator to set up the MySQL privilege system in such a way that users get different privileges depending on whether or not they have specified a password. NOTE: Do not attempt to encrypt the password before calling RealConnect; password encryption is handled automatically by the client API.
    dbname - This is the database name. If it is not null, the connection will set the default database to this value.
    port - If port this is not 0, the value will be used as the port number for the TCP/IP connection. Note that the host parameter determines the type of the connection.
    socketName - If it is not null, this string specifies the named pipe that should be used. Note that the host parameter determines the type of the connection.
    flags - Options flags
    Returns:
    A MYSQL* connection handle if the connection was successful, null if the connection was unsuccessful. For a successful connection, the return value is the same as the value of the db, unless you pass null for that parameter.

    RealEscapeString

    public string RealEscapeString(System.IntPtr db,
                                   string str)

    This function is used to create a legal SQL string that you can use in a SQL statement.


    RealEscapeString

    public string RealEscapeString(System.IntPtr db,
                                   byte[] bytes)

    This function is used to create a legal SQL string that you can use in a SQL statement.


    RealQuery

    public int RealQuery(System.IntPtr db,
                         string query,
                         uint length)

    Executes the SQL query pointed to by query, which should be a string length bytes long. The query must consist of a single SQL statement. You should not add a terminating semicolon (`;') or \g to the statement.

    You must use RealQuery rather than MySqlSharp.Provider.ClientAPI.MySql.Query(System.IntPtr,System.String) for queries that contain binary data, because binary data may contain the `\0' character. In addition, RealQuery is faster than MySqlSharp.Provider.ClientAPI.MySql.Query(System.IntPtr,System.String) because it does not call strlen() on the query string.

    If you want to know if the query should return a result set or not, you can use MySqlSharp.Provider.ClientAPI.MySql.FieldCount(System.IntPtr) to check for this.

    Returns:
    Zero if the query was successful. Non-zero if an error occurred.

    RowSeek

    public System.IntPtr RowSeek(System.IntPtr result,
                                 System.IntPtr offset)

    Sets the row cursor to an arbitrary row in a query result set. This requires that the result set structure contains the entire result of the query, so RowSeek may be used in conjunction only with MySqlSharp.Provider.ClientAPI.MySql.StoreResult(System.IntPtr), not with MySqlSharp.Provider.ClientAPI.MySql.UseResult(System.IntPtr).

    The offset should be a value returned from a call to MySqlSharp.Provider.ClientAPI.MySql.RowTell(System.IntPtr) or to RowSeek. This value is not simply a row number; if you want to seek to a row within a result set using a row number, use MySqlSharp.Provider.ClientAPI.MySql.DataSeek(System.IntPtr,System.UInt64) instead.

    Returns:
    The previous value of the row cursor. This value may be passed to a subsequent call to RowSeek

    RowTell

    public System.IntPtr RowTell(System.IntPtr result)

    Returns the current position of the row cursor for the last MySqlSharp.Provider.ClientAPI.MySql.FetchRow(System.IntPtr). This value can be used as an argument to MySqlSharp.Provider.ClientAPI.MySql.RowSeek(System.IntPtr,System.IntPtr).

    You should use RowTell only after MySqlSharp.Provider.ClientAPI.MySql.StoreResult(System.IntPtr), not after MySqlSharp.Provider.ClientAPI.MySql.UseResult(System.IntPtr).


    SelectDb

    public int SelectDb(System.IntPtr mysql,
                        string db)

    Causes the database specified by db to become the default (current) database on the connection specified by mysql. In subsequent queries, this database is the default for table references that do not include an explicit database specifier.

    SelectDb fails unless the connected user can be authenticated as having permission to use the database.

    Returns:
    Zero for success. Non-zero if an error occurred.

    Shutdown

    public int Shutdown(System.IntPtr mysql)

    Asks the database server to shut down. The connected user must have shutdown privileges.

    Returns:
    Zero for success. Non-zero if an error occurred.

    Stat

    public string Stat(System.IntPtr mysql)

    Returns a character string containing information similar to that provided by the mysqladmin status command. This includes uptime in seconds and the number of running threads, questions, reloads, and open tables.

    Returns:
    A character string describing the server status. null if an error occurred.

    StoreResult

    public System.IntPtr StoreResult(System.IntPtr mysql)

    You must call StoreResult or MySqlSharp.Provider.ClientAPI.MySql.UseResult(System.IntPtr) for every query that successfully retrieves data (SELECT, SHOW, DESCRIBE, EXPLAIN).

    You don't have to call StoreResult or MySqlSharp.Provider.ClientAPI.MySql.UseResult(System.IntPtr) for other queries, but it will not do any harm or cause any notable performance if you call StoreResult in all cases. You can detect if the query didn't have a result set by checking if StoreResult returns 0 (more about this later one).

    If you want to know if the query should return a result set or not, you can use MySqlSharp.Provider.ClientAPI.MySql.FieldCount(System.IntPtr) to check for this.

    Store reads the entire result of a query to the client, allocates a MYSQL_RES structure, and places the result into this structure.

    StoreResult returns a null pointer if the query didn't return a result set (if the query was, for example, an INSERT statement).

    StoreResult also returns a null pointer if reading of the result set failed. You can check if you got an error by checking if MySqlSharp.Provider.ClientAPI.MySql.Error(System.IntPtr) doesn't return a null pointer, if MySqlSharp.Provider.ClientAPI.MySql.ErrNo(System.IntPtr) returns != 0, or if MySqlSharp.Provider.ClientAPI.MySql.FieldCount(System.IntPtr) returns != 0.

    An empty result set is returned if there are no rows returned. (An empty result set differs from a null pointer as a return value.)

    Once you have called StoreResult and got a result back that isn't a null pointer, you may call MySqlSharp.Provider.ClientAPI.MySql.NumRows(System.IntPtr) to find out how many rows are in the result set.

    You can call MySqlSharp.Provider.ClientAPI.MySql.FetchRow(System.IntPtr) to fetch rows from the result set, or MySqlSharp.Provider.ClientAPI.MySql.RowSeek(System.IntPtr,System.IntPtr) and MySqlSharp.Provider.ClientAPI.MySql.RowTell(System.IntPtr) to obtain or set the current row position within the result set.

    You must call MySqlSharp.Provider.ClientAPI.MySql.FreeResult(System.IntPtr) once you are done with the result set.

    Returns:
    A MYSQL_RES result structure with the results. NULL if an error occurred.

    UseResult

    public System.IntPtr UseResult(System.IntPtr mysql)

    You must call UseResult or MySqlSharp.Provider.ClientAPI.MySql.StoreResult(System.IntPtr) for every query that successfully retrieves data (SELECT, SHOW, DESCRIBE, EXPLAIN).

    UseResult initiates a result set retrieval but does not actually read the result set into the client like MySqlSharp.Provider.ClientAPI.MySql.StoreResult(System.IntPtr) does. Instead, each row must be retrieved individually by making calls to MySqlSharp.Provider.ClientAPI.MySql.FetchRow(System.IntPtr). This reads the result of a query directly from the server without storing it in a temporary table or local buffer, which is somewhat faster and uses much less memory than MySqlSharp.Provider.ClientAPI.MySql.StoreResult(System.IntPtr). The client will only allocate memory for the current row and a communication buffer that may grow up to max_allowed_packet bytes.

    On the other hand, you shouldn't use UseResult if you are doing a lot of processing for each row on the client side, or if the output is sent to a screen on which the user may type a ^S (stop scroll). This will tie up the server and prevent other threads from updating any tables from which the data is being fetched.

    When using UseResult, you must execute MySqlSharp.Provider.ClientAPI.MySql.FetchRow(System.IntPtr) until a null value is returned, otherwise the unfetched rows will be returned as part of the result set for your next query. The C API will give the error Commands out of sync; You can't run this command now if you forget to do this!

    You may not use MySqlSharp.Provider.ClientAPI.MySql.DataSeek(System.IntPtr,System.UInt64), MySqlSharp.Provider.ClientAPI.MySql.RowSeek(System.IntPtr,System.IntPtr), MySqlSharp.Provider.ClientAPI.MySql.RowTell(System.IntPtr), MySqlSharp.Provider.ClientAPI.MySql.NumRows(System.IntPtr), or MySqlSharp.Provider.ClientAPI.MySql.AffectedRows(System.IntPtr) with a result returned from UseResult, nor may you issue other queries until the UseResult has finished. (However, after you have fetched all the rows, MySqlSharp.Provider.ClientAPI.MySql.NumRows(System.IntPtr) will accurately return the number of rows fetched.)

    You must call MySqlSharp.Provider.ClientAPI.MySql.FreeResult(System.IntPtr) once you are done with the result set.

    Returns:
    A MYSQL_RES result structure. NULL if an error occurred.