db_query.c File Reference

Query helper for database drivers

This helper methods for database queries are used from the database SQL driver to do the actual work. Each function uses some functions from the actual driver with function pointers to the concrete, specific implementation. More...

#include <stdio.h>
#include "../dprint.h"
#include "db_ut.h"
#include "db_query.h"

Include dependency graph for db_query.c:

Go to the source code of this file.

Functions

int db_do_delete (const db_con_t *_h, const db_key_t *_k, const db_op_t *_o, const db_val_t *_v, const int _n, int(*val2str)(const db_con_t *, const db_val_t *, char *, int *), int(*submit_query)(const db_con_t *_h, const str *_c))
 Helper function for db delete operations.
int db_do_insert (const db_con_t *_h, const db_key_t *_k, const db_val_t *_v, const int _n, int(*val2str)(const db_con_t *, const db_val_t *, char *, int *), int(*submit_query)(const db_con_t *_h, const str *_c))
 Helper function for db insert operations.
int db_do_query (const db_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, db_res_t **_r, int(*val2str)(const db_con_t *, const db_val_t *, char *, int *_len), int(*submit_query)(const db_con_t *, const str *), int(*store_result)(const db_con_t *_h, db_res_t **_r))
int db_do_raw_query (const db_con_t *_h, const str *_s, db_res_t **_r, int(*submit_query)(const db_con_t *_h, const str *_c), int(*store_result)(const db_con_t *_h, db_res_t **_r))
 Helper function for raw db queries.
int db_do_replace (const db_con_t *_h, const db_key_t *_k, const db_val_t *_v, const int _n, int(*val2str)(const db_con_t *, const db_val_t *, char *, int *), int(*submit_query)(const db_con_t *_h, const str *_c))
 Helper function for db delete operations.
int db_do_update (const db_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, int(*val2str)(const db_con_t *, const db_val_t *, char *, int *), int(*submit_query)(const db_con_t *_h, const str *_c))
 Helper function for db update operations.

Variables

static char sql_buf [SQL_BUF_LEN]
static str sql_str


Detailed Description

Query helper for database drivers

This helper methods for database queries are used from the database SQL driver to do the actual work. Each function uses some functions from the actual driver with function pointers to the concrete, specific implementation.

Definition in file db_query.c.


Function Documentation

int db_do_delete ( const db_con_t _h,
const db_key_t _k,
const db_op_t _o,
const db_val_t _v,
const int  _n,
int(*)(const db_con_t *, const db_val_t *, char *, int *)  val2str,
int(*)(const db_con_t *_h, const str *_c)  submit_query 
)

Helper function for db delete operations.

This method evaluates the actual arguments for the database operation and setups the string that is used for the delete operation in the db module. Then its submit the query for the operation. It uses for its work the implementation in the concrete database module.

Parameters:
_h structure representing database connection
_k key names
_o operators
_v values of the keys that must match
_n number of key/value pairs that are compared, if zero then the whole table is deleted
(*val2str) function pointer to the db specific val conversion function
(*submit_query) function pointer to the db specific query submit function
Returns:
zero on success, negative on errors

Definition at line 190 of file db_query.c.

References CON_TABLE, db_print_where(), _str::len, len, LM_ERR, _str::s, s, snprintf, sql_buf, and SQL_BUF_LEN.

Referenced by db_mysql_delete(), db_oracle_delete(), db_postgres_delete(), and db_unixodbc_delete().

int db_do_insert ( const db_con_t _h,
const db_key_t _k,
const db_val_t _v,
const int  _n,
int(*)(const db_con_t *, const db_val_t *, char *, int *)  val2str,
int(*)(const db_con_t *_h, const str *_c)  submit_query 
)

Helper function for db insert operations.

This method evaluates the actual arguments for the database operation and setups the string that is used for the insert operation in the db module. Then its submit the query for the operation. It uses for its work the implementation in the concrete database module.

Parameters:
_h structure representing database connection
_k key names
_v values of the keys
_n number of key/value pairs
(*val2str) function pointer to the db specific val conversion function
(*submit_query) function pointer to the db specific query submit function
Returns:
zero on success, negative on errors

Definition at line 145 of file db_query.c.

References CON_TABLE, db_print_columns(), db_print_values(), _str::len, len, LM_ERR, _str::s, s, snprintf, sql_buf, and SQL_BUF_LEN.

Referenced by db_mysql_insert(), db_oracle_insert(), db_postgres_insert(), and db_unixodbc_insert().

int db_do_query ( const db_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,
db_res_t **  _r,
int(*)(const db_con_t *, const db_val_t *, char *, int *_len)  val2str,
int(*)(const db_con_t *, const str *)  submit_query,
int(*)(const db_con_t *_h, db_res_t **_r)  store_result 
)

int db_do_raw_query ( const db_con_t _h,
const str _s,
db_res_t **  _r,
int(*)(const db_con_t *_h, const str *_c)  submit_query,
int(*)(const db_con_t *_h, db_res_t **_r)  store_result 
)

Helper function for raw db queries.

This method evaluates the actual arguments for the database raw query and setups the string that is used for the query in the db module. Then its submit the query and stores the result if necessary. It uses for its work the implementation in the concrete database module.

Parameters:
_h structure representing database connection
_s char holding the raw query
_r the result that is returned
(*submit_query) function pointer to the db specific query submit function
(*store_result) function pointer to the db specific store result function
Returns:
zero on success, negative on errors

Definition at line 120 of file db_query.c.

References LM_ERR.

Referenced by db_mysql_raw_query(), db_oracle_raw_query(), db_postgres_raw_query(), and db_unixodbc_raw_query().

int db_do_replace ( const db_con_t _h,
const db_key_t _k,
const db_val_t _v,
const int  _n,
int(*)(const db_con_t *, const db_val_t *, char *, int *)  val2str,
int(*)(const db_con_t *_h, const str *_c)  submit_query 
)

Helper function for db delete operations.

This helper method evaluates the actual arguments for the database operation and setups the string that is used for the replace operation in the db module. Then its submit the query for the operation. It uses for its work the implementation in the concrete database module.

Parameters:
_h structure representing database connection
_k key names, if not present the whole table will be returned
_v values of the keys that must match
_n number of key/value pairs that are compared, if zero then no comparison is done
(*val2str) function pointer to the db specific val conversion function
(*submit_query) function pointer to the db specific query submit function
Returns:
zero on success, negative on errors

Definition at line 279 of file db_query.c.

References CON_TABLE, db_print_columns(), db_print_values(), _str::len, len, LM_ERR, _str::s, s, snprintf, sql_buf, and SQL_BUF_LEN.

Referenced by db_mysql_replace(), and db_unixodbc_replace().

int db_do_update ( const db_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,
int(*)(const db_con_t *, const db_val_t *, char *, int *)  val2str,
int(*)(const db_con_t *_h, const str *_c)  submit_query 
)

Helper function for db update operations.

This method evaluates the actual arguments for the database operation and setups the string that is used for the update operation in the db module. Then its submit the query for the operation. It uses for its work the implementation in the concrete database module.

Parameters:
_h structure representing database connection
_k key names, if not present the whole table will be returned
_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 that are compared, if zero then no comparison is done
_un,: number of columns that should be updated
(*val2str) function pointer to the db specific val conversion function
(*submit_query) function pointer to the db specific query submit function
Returns:
zero on success, negative on errors

Definition at line 233 of file db_query.c.

References CON_TABLE, db_print_set(), db_print_where(), _str::len, len, LM_ERR, _str::s, s, snprintf, sql_buf, and SQL_BUF_LEN.

Referenced by db_mysql_update(), db_oracle_update(), db_postgres_update(), and db_unixodbc_update().


Variable Documentation

char sql_buf[SQL_BUF_LEN] [static]

str sql_str [static]

Definition at line 40 of file db_query.c.

Referenced by db_insert_update().


Generated on Tue May 22 14:00:35 2012 for Kamailio - The Open Source SIP Server by  doxygen 1.5.6