SIP Express Router v0.8.8 - Developer's Guide | ||
---|---|---|
<<< Previous | The Database Interface | Next >>> |
There are several functions that implement the database API logic. All function names start with db_ prefix, except bind_dbmod. bind_dbmod is implemented in db.c file, all other functions are implemented in a standalone module. Detaileddescription of functions follows.
This function is special, it's only purpose is to call find_export function in the SER core and find addresses of all other functions (starting with db_ prefix). This function MUST be called FIRST !
The function takes no parameters.
The function returns 0 if it was able to find addresses of all other functions, otherwise value < 0 is returned.
Use this function to initialize the database API and open a new database connection. This function must be called after bind_dbmod but before any other function is called.
The function takes one parameter, the parameter must contain database connection URL. The URL is of the form sql://username:password@host:port/database where:
username - Username to use when logging into database (optional).
password - Password if it was set (optional).
host - Hosname or IP address of the host where database server lives (mandatory).
port - Port number of the server if the port differs from default value (optional).
database - If the database server supports multiple databases, you must specify name of the database (optional).
The function returns pointer to db_con_t* representing the connection if it was successful, otherwise 0 is returned.
The function closes previously open connection and frees all previously allocated memory. The function db_close must be the very last function called.
The function takes one parameter, this parameter is a pointer to db_con_t structure representing database connection that should be closed.
Function doesn't return anything.
This function implements SELECT SQL directive.
The function takes 8 parameters:
_h - Database connection handle.
_k - Array of column names that will be compared and their values must match.
_v - Array of values, columns specified in _k parameter must match these values.
_c - Array of column names that you are interested in.
_n - Number of key-value pairs to match in _k and _v parameters.
_nc - Number of columns in _c parameter.
_o - Order by.
_r - Address of variable where pointer to the result will be stored.
_r will point to a dynamically allocated structure, it is neccessary to call db_free_query function once you are finished with the result.
Strings in the result are not duplicated, they will be discarded if you call db_free_query, make a copy yourself if you need to keep it after db_free_query.
You must call db_free_query BEFORE you can call db_query again !
The function returns 0 if everything is OK, otherwise value < 0 is returned.
This function frees all memory allocated previously in db_query, it is neccessary to call this function for a db_res_t structure if you don't need the structure anymore. You must call this function BEFORE you call db_query again !
The function takes 2 parameters:
_h - Database connection handle.
_r - Pointer to db_res_t structure to destroy.
The function returns 0 if everything is OK, otherwise the function returns value < 0.
This function implements INSERT SQL directive, you can insert one or more rows in a table using this function.
The function takes 4 parameters:
_h - Database connection handle.
_k - Array of keys (column names).
_v - Array of values for keys specified in _k parameter.
_n - Number of keys-value pairs int _k and _v parameters.
The function returns 0 if everything is OK, otherwise the function returns value < 0.
This function implements DELETE SQL directive, it is possible to delete one or more rows from a table.
The function takes 4 parameters:
_h - Database connection handle.
_k - Array of keys (column names) that will be matched.
_v - Array of values that the row must match to be deleted.
_n - Number of keys-value parameters in _k and _v parameters.
The function returns 0 if everything is OK, otherwise the function returns value < 0.
The function implements UPDATE SQL directive. It is possible to modify one or more rows in a table using this function.
The function takes 7 parameters:
_h - Database connection handle.
_k - Array of keys (column names) that will be matched.
_v - Array of values that the row must match to be modified.
_uk - Array of keys (column names) that will be modified.
_uv - New values for keys specified in _k parameter.
_n - Number of key-value pairs in _k and _v parameters.
_un - Number of key-value pairs in _uk and _uv parameters.
The function returns 0 if everything is OK, otherwise the function returns value < 0.
The function db_use_table takes a table name and stores it in db_con_t structure. All subsequent operations (insert, delete, update, query) are performed on that table.
The function takes 2 parameters:
_h - Database connection handle.
_t - Table name.
The function returns 0 if everything is OK, otherwise the function returns value < 0.
<<< Previous | Home | Next >>> |
The Database Interface | Up | Basic Modules |