Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
#include <mysql.h>
size_t mariadb_convert_string(const char *from __attribute__((unused)),
size_t *from_len __attribute__((unused)),
MARIADB_CHARSET_INFO *from_cs __attribute__((unused)),
char *to __attribute__((unused)),
size_t *to_len __attribute__((unused)),
MARIADB_CHARSET_INFO *to_cs __attribute__((unused)), int *errorcode)#include <mysql.h>
MYSQL *mariadb_connect(MYSQL * mysql, const char *conn_str);if (!mariadb_connect(mysql, "host=localhost;database=test;ssl_enforce=1"))
{
printf("Error: %s\n", mysql_error(mysql));
return 1;
}#include <mysql.h>
my_bool mariadb_connection(MYSQL * mysql);#include <mysql.h>
int mariadb_field_attr(MARIADB_CONST_STRING *attr,
const MYSQL_FIELD *field,
enum mariadb_field_attr_t type)#include <mysql.h>
int display_extended_field_attribute(MYSQL *mysql)
{
MYSQL_RES *result;
MYSQL_FIELD *fields;
if (mysql_query(mysql, "CREATE TEMPORARY TABLE t1 (a POINT)"))
return 1;
if (mysql_query(mysql, "SELECT a FROM t1"))
return 1;
if (!(result= mysql_store_result(mysql)))
return 1;
if ((fields= mysql_fetch_fields(result)))
{
MARIADB_CONST_STRING field_attr;
if (!mariadb_field_attr(&field_attr, &fields[0],
MARIADB_FIELD_ATTR_DATA_TYPE_NAME))
{
printf("Extended field attribute: %s\n", field_attr.str);
}
}
mysql_free_result(result);
return 0;
}#include <mysql.h>
my_bool mariadb_get_info(MYSQL *mysql, enum mariadb_value value, void *arg)#include <mysql.h>
struct st_mysql_client_plugin *
mysql_client_find_plugin(MYSQL *mysql, const char *name, int type);#include <mysql.h>
my_bool mysql_eof(MYSQL_RES *result);#include <mysql.h>
unsigned int mysql_get_timeout_value(const MYSQL *mysql);#include <mysql.h>
unsigned int mysql_get_timeout_value_ms(const MYSQL *mysql);#include <mysql.h>
struct st_mysql_client_plugin *
mysql_load_plugin(struct st_mysql *mysql, const char *name, int type,
int argc, ...);#include <mysql.h>
unsigned long mysql_net_field_length(unsigned char **packet)#include <mysql.h>
unsigned long mysql_net_read_packet(MYSQL *mysql)#include <mysql.h>
int mysql_options4(MYSQL *mysql,
enum mysql_option option,
const void *arg1,
const void *arg2);#include <mysql.h>
void STDCALL mysql_set_local_infile_handler(MYSQL *conn,
int (*local_infile_init)(void **, const char *, void *),
int (*local_infile_read)(void *, char *, uint),
void (*local_infile_end)(void *),
int (*local_infile_error)(void *, char *, uint),
void *userdata);#include <mysql.h>
void mysql_set_local_infile_default(MYSQL *conn);mariadb_get_infov retrieves generic or connection-specific information from a MariaDB Connector/C handle, accepting a value-type enum and a pointer to store the result.
my_bool mariadb_get_infov(MYSQL * mysql,
enum mariadb_value value,
void * arg,
...);/* get server port for current connection */
unsigned int port;
mariadb_get_infov(mysql, MARIADB_CONNECTION_PORT, void *)&port);/* get user name for current connection */
const char *user;
mariadb_get_infov(mysql, MARIADB_CONNECTION_USER, (void *)&user);mysql_autocommit enables or disables autocommit mode for the current database connection, returning zero on success or nonzero on failure.
my_bool mysql_autocommit(MYSQL * mysql, my_bool auto_mode);# Turn off autocommit
SET AUTOCOMMIT=0;
# Retrieve autocommit
SELECT @@autocommit;
+--------------+
| @@autocommit |
+--------------+
| 0 |
+--------------+static int test_autocommit(MYSQL *mysql)
{
int rc;
unsigned int server_status;
/* Turn autocommit off */
rc= mysql_autocommit(mysql, 0);
if (rc)
return rc; /* Error */
/* If autocommit = 0 succeeded, the last OK packet updated the server status */
rc= mariadb_get_infov(mysql, MARIADB_CONNECTION_SERVER_STATUS, &server_status);
if (rc)
return rc; /* Error */
if (server_status & SERVER_STATUS_AUTOCOMMIT)
{
printf("Error: autocommit is on\n");
return 1;
}
printf("OK: autocommit is off\n");
return 0;
}mysql_change_user changes the authenticated user and default database on an existing connection, resetting session state including transactions, temporary tables, and locks.
mysql_debug enables debug output for a MariaDB Connector/C client using the DBUG library, accepting a colon-separated control string to configure trace and logging options.
mysql_get_optionv retrieves the current value of a connection option previously set with mysql_optionsv, supporting boolean, integer, string, and miscellaneous option types.
int mysql_get_optionv(MYSQL * mysql,
enum mysql_option,
void * arg,
...);uint8_t reconnect;
rc = mysql_get_optionv(mysql, MYSQL_OPT_RECONNECT, &reconnect);uint32_t timeout;
rc = mysql_get_optionv(mysql, MYSQL_OPT_CONNECT_TIMEOUT, &timeout);char **commands;
int elements;
rc = mysql_get_optionv(mysql, MYSQL_INIT_COMMAND, &commands, &elements);char *plugin_dir;
rc = mysql_get_optionv(mysql, MYSQL_PLUGIN_DIR, &plugin_dir);/* get number of connection attributes */
int i, elements= 0;
char **key, **value;
mysql_get_optionv(mysql, MYSQL_CONNECT_ATTRS, NULL, NULL, (void *)&elements);
key= (char **)malloc(sizeof(char *) * elements);
val= (char **)malloc(sizeof(char *) * elements);
mysql_get_optionv(mysql, MYSQL_OPT_CONNECT_ATTRS, &key, &val, &elements);
for (i=0; i < elements; i++)
printf("key: %s value: %s", key[i], val[i]);const char *ssh_user;
mysql_get_optionv(mysql, MARIADB_OPT_USERDATA, "ssh_user", (void *)ssh_user);mysql_real_connect opens a connection to a MariaDB server and returns a MYSQL handle on success, or NULL if the connection could not be established.
mysql_real_escape_string encodes a string for safe use in a SQL statement, taking the connection's current character set into account when escaping special characters.
mysql_select_db changes the default database on an active connection; the current default can also be queried with the SELECT DATABASE() SQL function.
int mysql_select_db(MYSQL * mysql,
const char * db);# switch to default database test
USE test;
# check default database
SELECT DATABASE();
+------------+
| database() |
+------------+
| test |
+------------+static int set_default_db(MYSQL *mysql)
{
int rc;
char *default_db;
/* change default database to test */
rc= mysql_select_db(mysql, "test");
if (rc)
return rc; /* Error */
/* get the default database */
rc= mariadb_get_infov(mysql, MARIADB_CONNECTION_SCHEMA, &default_db);
if (rc)
return rc; /* Error */
if (strcmp("test", default_db) != NULL)
{
printf("Wrong default database\n");
return 1;
}
printf("Default database: %s", default_db);
return 0;
}mysql_session_track_get_first retrieves the first session state change notification from the server, covering schema changes, system variables, and state flags. Added in Connector/C 3.0.
mysql_session_track_get_next retrieves subsequent session state change notifications after mysql_session_track_get_first, called repeatedly until a nonzero value signals end of data.
mysql_set_character_set sets the default character set for a MariaDB Connector/C connection, ensuring mysql_real_escape_string uses the correct encoding.
mysql_ssl_set configures TLS parameters including key, certificate, CA, and cipher list for a MariaDB connection, and must be called before mysql_real_connect.
int mysql_set_character_set(MYSQL * mysql,
const char * csname);