#include <stdlib.h>
#include <stdarg.h>
#include <time.h>
#include <errno.h>
#include <string.h>
#include <sys/time.h>
#include <mysql/errmsg.h>
#include <mysql/mysql.h>
Go to the source code of this file.
Data Structures | |
struct | mysac_list_head |
union | MYSAC_ROW |
struct | MYSAC_ROWS |
struct | MYSAC_RES |
struct | mysac_bind |
struct | mysac |
Defines | |
#define | mysac_container_of(ptr, type, member) |
#define | mysac_list_entry(ptr, type, member) mysac_container_of(ptr, type, member) |
#define | mysac_list_first_entry(ptr, type, member) mysac_list_entry((ptr)->next, type, member) |
Typedefs | |
typedef struct mysac_bind | MYSAC_BIND |
typedef struct mysac | MYSAC |
Functions | |
MYSAC * | mysac_new (int buffsize) |
void | mysac_init (MYSAC *mysac, char *buffer, unsigned int buffsize) |
void | mysac_setup (MYSAC *mysac, const char *my_addr, const char *user, const char *passwd, const char *db, unsigned long client_flag) |
int | mysac_connect (MYSAC *mysac) |
void | mysac_close (MYSAC *mysac) |
int | mysac_get_fd (MYSAC *mysac) |
int | mysac_io (MYSAC *mysac) |
int | mysac_set_database (MYSAC *mysac, const char *database) |
int | mysac_send_database (MYSAC *mysac) |
MYSAC_RES * | mysac_init_res (char *buffer, int len) |
MYSAC_RES * | mysac_new_res (int chunk_size, int extend) |
void | mysac_free_res (MYSAC_RES *r) |
int | mysac_set_query (MYSAC *mysac, MYSAC_RES *res, const char *fmt,...) |
int | mysac_v_set_query (MYSAC *mysac, MYSAC_RES *res, const char *fmt, va_list ap) |
int | mysac_s_set_query (MYSAC *mysac, MYSAC_RES *res, const char *query) |
int | mysac_b_set_query (MYSAC *mysac, MYSAC_RES *res, const char *query, int len) |
MYSAC_RES * | mysac_get_res (MYSAC *mysac) |
int | mysac_send_query (MYSAC *mysac) |
int | mysac_set_stmt_prepare (MYSAC *mysac, unsigned long *stmt_id, const char *fmt,...) |
int | mysac_v_set_stmt_prepare (MYSAC *mysac, unsigned long *stmt_id, const char *fmt, va_list ap) |
int | mysac_s_set_stmt_prepare (MYSAC *mysac, unsigned long *stmt_id, const char *request) |
int | mysac_b_set_stmt_prepare (MYSAC *mysac, unsigned long *stmt_id, const char *request, int len) |
int | mysac_send_stmt_prepare (MYSAC *mysac) |
int | mysac_set_stmt_execute (MYSAC *mysac, MYSAC_RES *res, unsigned long stmt_id, MYSAC_BIND *values, int nb) |
int | mysac_send_stmt_execute (MYSAC *mysac) |
int | mysac_affected_rows (MYSAC *mysac) |
unsigned int | mysac_field_count (MYSAC_RES *res) |
unsigned long | mysac_num_rows (MYSAC_RES *res) |
MYSAC_ROW * | mysac_fetch_row (MYSAC_RES *res) |
void | mysac_first_row (MYSAC_RES *res) |
MYSAC_ROW * | mysac_cur_row (MYSAC_RES *res) |
unsigned long | mysac_insert_id (MYSAC *m) |
int | mysac_change_user (MYSAC *mysac, const char *user, const char *passwd, const char *db) |
unsigned int | mysac_errno (MYSAC *mysac) |
const char * | mysac_error (MYSAC *mysac) |
const char * | mysac_advance_error (MYSAC *mysac) |
#define mysac_container_of | ( | ptr, | |||
type, | |||||
member | ) |
Value:
({ \ const typeof( ((type *)0)->member ) *__mptr = (ptr); \ (type *)( (char *)__mptr - mysac_offset_of(type,member) );})
def imported from: linux-2.6.24/include/linux/kernel.h
ptr | the pointer to the member. | |
type | the type of the container struct this is embedded in. | |
member | the name of the member within the struct. |
#define mysac_list_entry | ( | ptr, | |||
type, | |||||
member | ) | mysac_container_of(ptr, type, member) |
list_entry - get the struct for this entry
def imported from: linux-2.6.24/include/linux/list.h
ptr,: | the &struct list_head pointer. | |
type,: | the type of the struct this is embedded in. | |
member,: | the name of the list_struct within the struct. |
#define mysac_list_first_entry | ( | ptr, | |||
type, | |||||
member | ) | mysac_list_entry((ptr)->next, type, member) |
list_first_entry - get the first element from a list
def imported from: linux-2.6.24/include/linux/list.h
ptr | the list head to take the element from. | |
type | the type of the struct this is embedded in. | |
member | the name of the list_struct within the struct. |
typedef struct mysac_bind MYSAC_BIND |
This contain list of values for statement binding
const char* mysac_advance_error | ( | MYSAC * | mysac | ) |
For the connection specified by mysql, mysql_error() returns a null- terminated string containing the error message for the most recently invoked API function that failed. If a function didn't fail, the return value of mysql_error() may be the previous error or an empty string to indicate no error.
mysac | Should be the address of an existing MYSQL structure. |
int mysac_affected_rows | ( | MYSAC * | mysac | ) |
After executing a statement with mysql_query() returns the number of rows changed (for UPDATE), deleted (for DELETE), orinserted (for INSERT). For SELECT statements, mysql_affected_rows() works like mysql_num_rows().
mysac | Should be the address of an existing MYSQL structure. |
int mysac_b_set_stmt_prepare | ( | MYSAC * | mysac, | |
unsigned long * | stmt_id, | |||
const char * | request, | |||
int | len | |||
) |
Prepare statement
mysac | Should be the address of an existing MYSAC structur. | |
stmt_id | is the receiver of the statement id | |
request | is a string containing the query | |
len | is the len of the query |
int mysac_change_user | ( | MYSAC * | mysac, | |
const char * | user, | |||
const char * | passwd, | |||
const char * | 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.
mysql_change_user() fails if the connected user cannot be authenticated or doesn't have permission to use the database. In this case, the user and database are not changed
This command resets the state as if one had done a new connect. It always performs a ROLLBACK of any active transactions, closes and drops all temporary tables, and unlocks all locked tables. Session system variables are reset to the values of the corresponding global system variables. Prepared statements are released and HANDLER variables are closed. Locks acquired with GET_LOCK() are released. These effects occur even if the user didn't change.
mysac | Should be the address of an existing MYSQL structure. | |
user | The user parameter contains the user's MySQL login ID. If user is NULL or the empty string "", the current user is assumed. | |
passwd | The passwd parameter contains the password for user. If passwd is NULL, only entries in the user table for the user that have a blank (empty) password field are checked for a match. | |
db | The db parameter may be set to NULL if you don't want to have a default database. |
void mysac_close | ( | MYSAC * | mysac | ) |
Closes a previously opened connection. mysql_close() also deallocates the connection handle pointed to by mysql if the handle was allocated automatically by mysql_init() or mysql_connect().
mysac | Should be the address of an existing MYSQL structure. |
int mysac_connect | ( | MYSAC * | mysac | ) |
Run network connexion and mysql authentication
mysac | Should be the address of an existing MYSQL structure. |
unsigned int mysac_errno | ( | MYSAC * | mysac | ) |
Returns the default character set name for the current connection.
mysac | Should be the address of an existing MYSQL structure. |
mysac | Should be the address of an existing MYSQL structure. |
const char* mysac_error | ( | MYSAC * | mysac | ) |
For the connection specified by mysql, mysql_error() returns a null- terminated string containing the error message for the most recently invoked API function that failed. If a function didn't fail, the return value of mysql_error() may be the previous error or an empty string to indicate no error.
mysac | Should be the address of an existing MYSQL structure. |
Retrieves the next row of a result set. mysql_fetch_row() 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 mysql_num_fields(result).
The lengths of the field values in the row may be obtained by calling mysql_fetch_lengths(). 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.
res | Should be the address of an existing MYSAC_RES structure. |
unsigned int mysac_field_count | ( | MYSAC_RES * | res | ) |
Returns the number of columns for the most recent query on the connection.
res | Should be the address of an existing MYSAC_RES structure. |
void mysac_first_row | ( | MYSAC_RES * | res | ) |
Set pointer on the first row, you can exec mysac_fetch_row, return it the first row;
int mysac_get_fd | ( | MYSAC * | mysac | ) |
This function return the mysql filedescriptor used for connection to the mysql server
mysac | Should be the address of an existing MYSAC structure. |
This function return the mysql response pointer
mysac | Should be the address of an existing MYSAC structure. |
void mysac_init | ( | MYSAC * | mysac, | |
char * | buffer, | |||
unsigned int | buffsize | |||
) |
Initializes a MYSQL object. 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 mysql_init() allocates a new object, it is freed when mysql_close() is called to close the connection.
mysac | Should be the address of an existing MYSAC structure. | |
buffer | is ptr on the pre-allocated buffer | |
buffsize | is the size of the buffer |
MYSAC_RES* mysac_init_res | ( | char * | buffer, | |
int | len | |||
) |
Initialize MYSAC_RES structur This function can not allocate memory, just use your buffer.
buffer | this buffer must contain all the sql response. this size is: sizeof(MYSAC_RES) + ( sizeof(MYSQL_FIELD) * nb_field ) + ( different fields names ) |
len | is the len of the buffer |
unsigned long mysac_insert_id | ( | MYSAC * | m | ) |
Returns the value generated for an AUTO_INCREMENT column by the previous INSERT or UPDATE statement. Use this function after you have performed an INSERT statement into a table that contains an AUTO_INCREMENT field
http://dev.mysql.com/doc/refman/5.0/en/mysql-insert-id.html
m | Should be the address of an existing MYSQL structure. |
int mysac_io | ( | MYSAC * | mysac | ) |
this function call the io function associated with the current command. (mysac_send_database, mysac_send_query and mysac_connect)
mysac | Should be the address of an existing MYSAC structure. |
MYSAC* mysac_new | ( | int | buffsize | ) |
Allocates and initializes a MYSQL object. 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 mysql_init() allocates a new object, it is freed when mysql_close() is called to close the connection.
buffsize | is the size of the buffer |
MYSAC_RES* mysac_new_res | ( | int | chunk_size, | |
int | extend | |||
) |
Create new MYSAC_RES structur This function allocate memory
WARNING: If extend is set, you must use the function mysac_get_res for retrieving the resource pointer after each call att mysac_send_query.
chunk_size | is the size allocated for the bloc | |
extend | if is true, the block is extended if the initial memory does not enough. the extension size is the size of chunk_size |
unsigned long mysac_num_rows | ( | MYSAC_RES * | res | ) |
Returns the number of rows in the result set.
mysql_num_rows() is intended for use with statements that return a result set, such as SELECT. For statements such as INSERT, UPDATE, or DELETE, the number of affected rows can be obtained with mysql_affected_rows().
res | Should be the address of an existing MYSAC_RES structure. |
int mysac_s_set_stmt_prepare | ( | MYSAC * | mysac, | |
unsigned long * | stmt_id, | |||
const char * | request | |||
) |
Prepare statement
mysac | Should be the address of an existing MYSAC structur. | |
stmt_id | is the receiver of the statement id | |
query | is a string (terminated by ) containing the query |
int mysac_send_database | ( | MYSAC * | mysac | ) |
This send use database command
mysac | Should be the address of an existing MYSQL structure. |
int mysac_send_query | ( | MYSAC * | mysac | ) |
Send sql query command
mysac | Should be the address of an existing MYSAC structur. |
int mysac_send_stmt_execute | ( | MYSAC * | mysac | ) |
send stmt execute command
mysac | Should be the address of an existing MYSQL structure. |
int mysac_send_stmt_prepare | ( | MYSAC * | mysac | ) |
Send sql query command
mysac | Should be the address of an existing MYSAC structur. | |
stmt_id | is pointer for storing the statement id |
int mysac_set_database | ( | MYSAC * | mysac, | |
const char * | database | |||
) |
Build use database message
mysac | Should be the address of an existing MYSQL structure. | |
database | is the database name |
int mysac_set_stmt_execute | ( | MYSAC * | mysac, | |
MYSAC_RES * | res, | |||
unsigned long | stmt_id, | |||
MYSAC_BIND * | values, | |||
int | nb | |||
) |
int mysac_set_stmt_prepare | ( | MYSAC * | mysac, | |
unsigned long * | stmt_id, | |||
const char * | fmt, | |||
... | ||||
) |
Prepare statement
mysac | Should be the address of an existing MYSAC structur. | |
stmt_id | is the receiver of the statement id | |
fmt | is the output format with the printf style |
void mysac_setup | ( | MYSAC * | mysac, | |
const char * | my_addr, | |||
const char * | user, | |||
const char * | passwd, | |||
const char * | db, | |||
unsigned long | client_flag | |||
) |
mysac_connect() attempts to establish a connection to a MySQL database engine running on host. mysql_real_connect() must complete successfully before you can execute any other API functions that require a valid MYSQL connection handle structure.
mysac | The first parameter should be the address of an existing MYSQL structure. Before calling mysql_real_connect() you must call mysql_init() to initialize the MYSQL structure. You can change a lot of connect options with the mysql_options() call. | |
my_addr | like "<ipv4>:<port>" "<ipv6>:<port>", "socket_unix_file" or NULL. If NULL, bind is set to socket 0 | |
user | The user parameter contains the user's MySQL login ID. If user is NULL or the empty string "", the current user is assumed. | |
passwd | The passwd parameter contains the password for user. If passwd is NULL, only entries in the user table for the user that have a blank (empty) password field are checked for a match. | |
db | is the database name. If db is not NULL, the connection sets the default database to this value. | |
client_flag | The value of client_flag is usually 0, but can be set to a combination of the following flags to enable certain features: |
int mysac_v_set_stmt_prepare | ( | MYSAC * | mysac, | |
unsigned long * | stmt_id, | |||
const char * | fmt, | |||
va_list | ap | |||
) |
Prepare statement
mysac | Should be the address of an existing MYSAC structur. | |
stmt_id | is the receiver of the statement id | |
fmt | is the output format with the printf style | |
ap | is the argument list on format vprintf |