This topic describes the general C API functions.
Overview
The following table lists all C API functions available to OceanBase Connector/C.
For more information about the APIs, see C API functions in the OceanBase Connector/C.
| Name | Description |
|---|---|
| my_init() | Initializes global variables in OceanBase Database. |
| mysql_affected_rows() | Returns the number of rows modified, deleted, or inserted by the last UPDATE, DELETE, or INSERT statement. |
| mysql_autocommit() | Sets the autocommit mode. |
| mysql_change_user() | Modifies the user and database on an open connection. |
| mysql_character_set_name() | Returns the name of the default character set for the current connection. |
| mysql_client_find_plugin() | Returns a pointer to a plug-in. |
| mysql_client_register_plugin() | Registers a plug-in. |
| mysql_close() | Closes the connection with the server. |
| mysql_commit() | Commits a transaction. |
| mysql_connect() | Connects to the server. This function is deprecated. |
| mysql_create_db() | Creates a database. This function is deprecated. |
| mysql_data_seek() | Searches for an arbitrary row in a result set. |
| mysql_debug() | Uses a given string to perform a DBUG_PUSH operation. |
| mysql_drop_db() | Drops a database. This function is deprecated. |
| mysql_dump_debug_info() | Instructs the server to write debugging information to the error log. |
| mysql_eof() | Checks whether the last row in a result set is already read. This function is deprecated. |
| mysql_errno() | Returns the error code generated for the last called API function. |
| mysql_error() | Returns the error message generated for the last called API function. |
| mysql_escape_string() | Escapes special characters in a string so that it can be used in an SQL statement. |
| mysql_fetch_field() | Returns the next field. |
| mysql_fetch_field_direct() | Returns the field with the specified field number. |
| mysql_fetch_fields() | Returns an array of all field structures. |
| mysql_fetch_lengths() | Returns the lengths of the columns of the current row in a result set. |
| mysql_fetch_row() | Retrieves the next row of a result set. |
| mysql_field_count() | Returns the number of columns for the most recent query. |
| mysql_field_seek() | Searches for columns of a row in a result set. |
| mysql_field_tell() | Returns the position of the field used for the last call to the mysql_fetch_field() function. |
| mysql_free_result() | Frees the memory allocated to a result set. |
| mysql_get_character_set_info() | Returns the information about the default character set. |
| mysql_get_client_info() | Returns a string that represents the OceanBase client library version. |
| mysql_get_client_version() | Returns an integer that represents the OceanBase client library version. |
| mysql_get_host_info() | Returns the connection information, including the server hostname. |
| mysql_get_proto_info() | Returns the protocol version used for the current connection. |
| mysql_get_server_info() | Returns a string that represents the server version. |
| mysql_get_server_version() | Returns an integer that represents the server version. |
| mysql_get_ssl_cipher() | Returns the current SSL password. |
| mysql_hex_string() | Creates a hexadecimal string. |
| mysql_info() | Returns the information about the most recently executed statement. |
| mysql_init() | Obtains or initializes a connection structure. |
| mysql_insert_id() | Returns the ID generated by the previous statement for an AUTO_INCREMENT column. |
| mysql_kill() | Kills a thread. This function is deprecated. |
| mysql_library_end() | Finalizes the C API library. |
| mysql_library_init() | Initializes the C API library. |
| mysql_list_dbs() | Returns database names that match a regular expression. |
| mysql_list_fields() | Returns field names that match a regular expression. |
| mysql_list_processes() | Returns the thread list of the server. |
| mysql_list_tables() | Returns table names that match a regular expression. |
| mysql_load_plugin() | Loads a plug-in. |
| mysql_load_plugin_v() | Loads a plug-in. |
| mysql_more_results() | Checks whether more results exist. |
| mysql_next_result() | Returns the next statement result. |
| mysql_num_fields() | Returns the number of columns in a result set. |
| mysql_num_rows() | Returns the number of rows in a result set. |
| mysql_options() | Sets connection options. |
| mysql_options4() | Sets connection options. |
| mysql_ping() | Checks whether the connection to the server is working. |
| mysql_plugin_options() | Sets plug-in options. |
| mysql_query() | Executes an SQL statement. |
| mysql_real_connect() | Connects to the server. |
| mysql_real_escape_string() | Encodes special characters in a string of a statement. |
| mysql_real_query() | Execute the statement. |
| mysql_refresh() | Flushes or resets tables or caches. |
| mysql_reload() | Reloads the grant tables. This function is deprecated. |
| mysql_rollback() | Rolls back a transaction. |
| mysql_row_seek() | Searches for an arbitrary row in a query result set. |
| mysql_row_tell() | Returns the current position of the row cursor for a result set. |
| mysql_select_db() | Selects a database. |
| mysql_server_end() | Finalizes the C API library. |
| mysql_server_init() | Initializes the C API library. |
| mysql_set_character_set() | Sets the default character set for the current connection. |
| mysql_set_local_infile_default() | Sets the LOAD DATA LOCAL callback functions to the default values. |
| mysql_set_local_infile_handler() | Installs callbacks to be used during the execution of LOAD DATA LOCAL statements. |
| mysql_set_server_option() | Enables or disables an option for the current connection. |
| mysql_shutdown() | Shuts down the server. |
| mysql_sqlstate() | Returns the SQLSTATE value of the most recently called function. |
| mysql_ssl_set() | Establishes an SSL connection to the server. |
| mysql_stat() | Returns the status of the server. |
| mysql_stmt_affected_rows() | Returns the number of rows modified, deleted, or inserted by the last UPDATE, DELETE, or INSERT statement. |
| mysql_stmt_attr_get() | Obtains an attribute value of a prepared statement. |
| mysql_stmt_attr_set() | Sets an attribute value for a prepared statement. |
| mysql_stmt_bind_param() | Associates the input data with the parameter markers of a prepared statement. |
| mysql_stmt_bind_result() | Associates data buffers with output columns in the result set. |
| mysql_stmt_close() | Closes a prepared statement. |
| mysql_stmt_data_seek() | Searches for an arbitrary row in the result set of a prepared statement. |
| mysql_stmt_errno() | Returns the error code for the most recently called statement. |
| mysql_stmt_error() | Returns the error message generated for the last called statement API function. |
| mysql_stmt_execute() | Executes a prepared statement. |
| mysql_stmt_fetch() | Returns the next row in a result set and returns the values of all associated columns. |
| mysql_stmt_fetch_column() | Fetches one column from the current result set row. |
| mysql_stmt_field_count() | Returns the number of columns in the result set of the most recently executed prepared statement. |
| mysql_stmt_free_result() | Free resources allocated to the statement handler. |
| mysql_stmt_init() | Allocates and initializes memory to the STMT structure. |
| mysql_stmt_insert_id() | Returns the ID generated by the previous prepared statement for an AUTO_INCREMENT column. |
| mysql_stmt_next_result() | Returns the next result in the result set of a prepared statement. |
| mysql_stmt_num_rows() | Returns the number of rows in the result set of a statement. |
| mysql_stmt_param_count() | Returns the number of parameters in a prepared statement. |
| mysql_stmt_param_metadata() | Returns parameter metadata as a result set. |
| mysql_stmt_prepare() | Prepares a statement. |
| mysql_stmt_reset() | Resets a statement buffer on the server. |
| mysql_stmt_result_metadata() | Returns the metadata of a prepared statement as a result set. |
| mysql_stmt_row_seek() | Searches for an arbitrary row in the result set of a prepared statement. |
| mysql_stmt_row_tell() | Returns the current position of the row cursor for the result set of a prepared statement. |
| mysql_stmt_send_long_data() | Sends data to the server in pieces. |
| mysql_stmt_sqlstate() | Returns the SQLSTATE value for the most recently called statement API function. |
| mysql_stmt_store_result() | Retrieves and stores a result set. |
| mysql_store_result() | Retrieves and stores a result set. |
| mysql_thread_end() | Finalizes the thread handler. |
| mysql_thread_id() | Returns the current thread ID. |
| mysql_thread_init() | Initializes the thread handler. |
| mysql_thread_safe() | Indicates whether the client library is compiled as thread-safe. |
| mysql_use_result() | Retrieves a result set row by row. |
| mysql_warning_count() | Returns the number of alerts generated during the execution of the previous statement. |
Example
Use basic APIs to connect to OceanBase Database, create a table, and modify the data in the table.
mysql_library_init(0, NULL, NULL);
MYSQL *mysql = mysql_init(NULL);
/* Use the CLIENT_MULTI_STATEMENTS option to connect to the server. */
if (mysql_real_connect (mysql, host_name, user_name, password,
db_name, port_num, socket_name, CLIENT_MULTI_STATEMENTS) == NULL)
{
printf("mysql_real_connect() failed\n");
mysql_close(mysql);
mysql_library_end();
exit(1);
}
/* Execute multiple statements. */
status = mysql_query(mysql,
"DROP TABLE IF EXISTS tbl1;\
CREATE TABLE tbl1(id INT);\
INSERT INTO tbl1 VALUES(110);\
UPDATE tbl1 SET id=120 WHERE id=110;\
SELECT * FROM tbl1;\
DROP TABLE tbl1");
if (status)
{
printf("Could not execute statement(s)");
mysql_close(mysql);
mysql_library_end();
exit(0);
}
/* Process the result of each statement. */
do {
/* Check whether the current statement returns data. */
result = mysql_store_result(mysql);
if (result)
{
/* If yes, process the rows and release the result set. */
process_result_set(mysql, result);
mysql_free_result(result);
}
else /* No result set generated or an error occurred. */
{
if (mysql_field_count(mysql) == 0)
{
printf("%lld rows affected\n",
mysql_affected_rows(mysql));
}
else /* An error occurred. */
{
printf("Could not retrieve result set\n");
break;
}
}
/* Check whether more results are generated. The value -1 indicates no. The value 0 indicates yes, which means the loop continues. A value greater than 0 indicates that an error occurred. */
if ((status = mysql_next_result(mysql)) > 0)
printf("Could not execute statement\n");
} while (status == 0);
mysql_close(mysql);
mysql_library_end();