Implementation of core functions for the MySQL driver. More...
#include <stdio.h>#include <string.h>#include <mysql/mysql.h>#include <mysql/errmsg.h>#include <mysql/mysql_version.h>#include "../../mem/mem.h"#include "../../dprint.h"#include "../../lib/srdb1/db_query.h"#include "../../lib/srdb1/db_ut.h"#include "mysql_mod.h"#include "km_val.h"#include "km_my_con.h"#include "km_res.h"#include "km_row.h"#include "km_db_mysql.h"#include "km_dbase.h"
Go to the source code of this file.
This file contains the implementation of core functions for the MySQL database driver, for example to submit a query or fetch a result.
Module: DB_MYSQL :: the MySQL driver for Kamailio
Definition in file db_mysql/km_dbase.c.
| int db_mysql_affected_rows | ( | const db1_con_t * | _h | ) |
Returns number of affected rows for last query.
| _h | database handle |
Definition at line 489 of file db_mysql/km_dbase.c.
| int db_mysql_alloc_buffer | ( | void | ) |
Definition at line 589 of file db_mysql/km_dbase.c.
References db_api_init().

| void db_mysql_close | ( | db1_con_t * | _h | ) |
Close a database connection.
No function should be called after this
| _h | handle to the closed connection |
Definition at line 146 of file db_mysql/km_dbase.c.
References db_do_close(), and db_mysql_free_connection().

| int db_mysql_delete | ( | const db1_con_t * | _h, | |
| const db_key_t * | _k, | |||
| const db_op_t * | _o, | |||
| const db_val_t * | _v, | |||
| const int | _n | |||
| ) |
Delete a row from table.
| _h | structure representing database connection | |
| _k | key names | |
| _o | operators | |
| _v | values of the keys that must match | |
| _n | number of key=value pairs |
Definition at line 423 of file db_mysql/km_dbase.c.
References db_do_delete(), db_mysql_submit_query(), and db_mysql_val2str().

fetch rows from a result
Gets a partial result set, fetch a number of rows from a database result. This function initialize the given result structure on the first run, and fetches the nrows number of rows. On subsequenting runs, it uses the existing result and fetches more rows, until it reaches the end of the result set. Because of this the result needs to be null in the first invocation of the function. If the number of wanted rows is zero, the function returns anything with a result of zero.
| _h | structure representing the database connection | |
| _r | pointer to a structure representing the result | |
| nrows | number of fetched rows |
Definition at line 280 of file db_mysql/km_dbase.c.
References counter_inc(), db_free_result(), db_free_rows(), db_mysql_convert_row(), db_mysql_get_columns(), db_new_result(), RES_LAST_ROW, RES_NUM_ROWS, RES_ROW_N, and RES_ROWS.

Free all memory allocated by get_result.
| _h | handle to the database | |
| _r | result set that should be freed |
Definition at line 227 of file db_mysql/km_dbase.c.
References db_free_result().

Initialize database connection.
No function should be called before this
| _url | URL used for initialization |
Definition at line 134 of file db_mysql/km_dbase.c.
References db_do_init(), and db_mysql_new_connection().

| int db_mysql_insert | ( | const db1_con_t * | _h, | |
| const db_key_t * | _k, | |||
| const db_val_t * | _v, | |||
| const int | _n | |||
| ) |
Insert a row into table.
| _h | structure representing database connection | |
| _k | key names | |
| _v | values of the keys | |
| _n | number of key=value pairs |
Definition at line 407 of file db_mysql/km_dbase.c.
References db_do_insert(), db_mysql_submit_query(), and db_mysql_val2str().

| int db_mysql_insert_delayed | ( | const db1_con_t * | _h, | |
| const db_key_t * | _k, | |||
| const db_val_t * | _v, | |||
| const int | _n | |||
| ) |
Insert a row into table.
| _h | structure representing database connection | |
| _k | key names | |
| _v | values of the keys | |
| _n | number of key=value pairs |
Definition at line 565 of file db_mysql/km_dbase.c.
References db_do_insert_delayed(), db_mysql_submit_query(), and db_mysql_val2str().

| int db_mysql_insert_update | ( | const db1_con_t * | _h, | |
| const db_key_t * | _k, | |||
| const db_val_t * | _v, | |||
| const int | _n | |||
| ) |
Insert a row into table, update on duplicate key.
| _h | structure representing database connection | |
| _k | key names | |
| _v | values of the keys | |
| _n | number of key=value pairs |
Definition at line 506 of file db_mysql/km_dbase.c.
References CON_TABLE, db_mysql_submit_query(), db_mysql_val2str(), db_print_columns(), db_print_set(), db_print_values(), _str::len, and _str::s.

| int db_mysql_last_inserted_id | ( | const db1_con_t * | _h | ) |
| _h | database handle |
Definition at line 474 of file db_mysql/km_dbase.c.
| int db_mysql_query | ( | const db1_con_t * | _h, | |
| const db_key_t * | _k, | |||
| const db_op_t * | _op, | |||
| const db_val_t * | _v, | |||
| const db_key_t * | _c, | |||
| const int | _n, | |||
| const int | _nc, | |||
| const db_key_t | _o, | |||
| db1_res_t ** | _r | |||
| ) |
Do a query.
| _h | structure representing database connection | |
| _k | key names | |
| _op | operators | |
| _v | values of the keys that must match | |
| _c | column names to return | |
| _n | number of key=values pairs to compare | |
| _nc | number of columns to return | |
| _o | order by the specified column | |
| _r | pointer to a structure representing the result |
Definition at line 257 of file db_mysql/km_dbase.c.
References db_do_query(), db_mysql_store_result(), db_mysql_submit_query(), and db_mysql_val2str().

Raw SQL query.
| _h | handle for the database | |
| _s | raw query string | |
| _r | result set for storage |
Definition at line 392 of file db_mysql/km_dbase.c.
References db_do_raw_query(), db_mysql_store_result(), and db_mysql_submit_query().

| int db_mysql_replace | ( | const db1_con_t * | _h, | |
| const db_key_t * | _k, | |||
| const db_val_t * | _v, | |||
| const int | _n, | |||
| const int | _un, | |||
| const int | _m | |||
| ) |
| _h | database handle | |
| _k | key names | |
| _v | values of the keys that must match | |
| _n | number of key=value pairs |
Definition at line 460 of file db_mysql/km_dbase.c.
References db_do_replace(), db_mysql_submit_query(), and db_mysql_val2str().

| _h | handle to the database | |
| _r | result set that should be retrieved |
Definition at line 158 of file db_mysql/km_dbase.c.
References counter_inc(), db_free_result(), db_mysql_convert_result(), and db_new_result().
Referenced by db_mysql_query(), and db_mysql_raw_query().


Send a SQL query to the database server. This methods tries to reconnect to the server if the connection is gone and the auto_reconnect parameter is enabled. It also issues a mysql_ping before the query to connect again after a long waiting period because for some older mysql versions the auto reconnect don't work sufficient. If auto_reconnect is enabled and the server supports it, then the mysql_ping is probably not necessary, but its safer to do it in this cases too.
| _h | handle for the db | |
| _s | executed query |
Definition at line 71 of file db_mysql/km_dbase.c.
References counter_inc(), _str::len, my_ping_interval, and _str::s.
Referenced by db_mysql_delete(), db_mysql_insert(), db_mysql_insert_delayed(), db_mysql_insert_update(), db_mysql_query(), db_mysql_raw_query(), db_mysql_replace(), and db_mysql_update().


| int db_mysql_update | ( | const db1_con_t * | _h, | |
| const db_key_t * | _k, | |||
| const db_op_t * | _o, | |||
| const db_val_t * | _v, | |||
| const db_key_t * | _uk, | |||
| const db_val_t * | _uv, | |||
| const int | _n, | |||
| const int | _un | |||
| ) |
Update a row in table.
| _h | structure representing database connection | |
| _k | key names | |
| _o | operators | |
| _v | values of the keys that must match | |
| _uk | updated columns | |
| _uv | updated values of the columns | |
| _n | number of key=value pairs | |
| _un | number of columns to update |
Definition at line 443 of file db_mysql/km_dbase.c.
References db_do_update(), db_mysql_submit_query(), and db_mysql_val2str().

Store name of table that will be used by subsequent database functions.
| _h | database handle | |
| _t | table name |
Definition at line 578 of file db_mysql/km_dbase.c.
References db_use_table().

1.7.1