# Developer's Guide

These are the primary functions that are used to perform the SQL queries.

## `load_ul_db_api(ul_db_api_t * api)`

Import the dbd API, set up the master database connection.

Meaning of the parameters is as follows:

- api - Pointer to distributed database API structure

## `int (* ul_db_insert_t) (str * table, str * first, str * second, db_key_t* _k, db_val_t* _v, int _n)`

Lookup the first and if needed the second key, and insert the given values into the chosen databases.

Meaning of the parameters is as follows:

- table - Pointer to the table name.

- first - Pointer to the first key.

- second - Pointer to the second key.

- _k - Pointer to the inserted db keys.

- _v - Pointer to the inserted db values.

- _n - Number of key-value pairs in _k and _v parameters.

## `int (* ul_db_update_t) (str * table, str * first, str * second, db_key_t* _k, db_op_t * _op, db_val_t* _v, db_key_t* _uk, db_val_t* _uv, int _n, int _un);`

Lookup the first and if needed the second key, and update the given values in the chosen databases.

Meaning of the parameters is as follows:

- table - Pointer to the table name.

- first - Pointer to the first key.

- second - Pointer to the second key.

- _k - Pointer to the db keys that will be matched.

- _op - Pointer to the db options for this operation.

- _v - Pointer to the db values that will be matched.

- _uk - Pointer to the updated db keys.

- _uv - Pointer to the updated db values.

- _n - Number of key-value pairs in _k and _v parameters.

- _un - Number of key-value pairs in _uk and _uv parameters.

## `int (* ul_db_insert_update_t) (str * table, str * first, str * second, db_key_t* _k, db_val_t* _v, int _n)`

Lookup the first and if needed the second key, and insert on duplicate key update the given values in the chosen databases. This is like an insert, but update if the key already exist.

Meaning of the parameters is as follows:

- table - Pointer to the table name.

- first - Pointer to the first key.

- second - Pointer to the second key.

- _k - Pointer to the inserted or updated db keys.

- _v - Pointer to the inserted or updated db values.

- _n - Number of key-value pairs in _k and _v parameters.

## `int (* ul_db_replace_t) (str * table, str * first, str * second, db_key_t* _k, db_val_t* _v, int _n)`

Lookup the first and if needed the second key, and replace the given values in the chosen databases.

Meaning of the parameters is as follows:

- table - Pointer to the table name.

- first - Pointer to the first key.

- second - Pointer to the second key.

- _k - Pointer to the replaced db keys.

- _v - Pointer to the replaced db values.

- _n - Number of key-value pairs in _k and _v parameters.

## `int (* ul_db_delete_t) (str * table, str * first, str * second, db_key_t* _k, db_op_t* _o, db_val_t* _v, int _n)`

Lookup the first and if needed the second key, and delete the given values into the chosen databases.

Meaning of the parameters is as follows:

- table - Pointer to the table name.

- first - Pointer to the first key.

- second - Pointer to the second key.

- _k - Pointer to the deleted db keys.

- _op - Pointer to the db options for this operation.

- _v - Pointer to the deleted db values.

- _n - Number of key-value pairs in _k and _v parameters.

## `int (* ul_db_query_t) (str * table, str * first, str * second, db_con_t *** _r_h, db_key_t* _k, db_op_t* _op, db_val_t* _v, db_key_t* _c, int _n, int _nc, db_key_t _o, db_res_t** _r);`

Lookup the first and if needed the second key, and performs a query in one of the chosen databases. The returned handle _r_h must be used to free the result set after the usage of the returned database entries, otherwise a memory leak will occur. You must call ul_db_free_result before you can call ul_db_query again!

Meaning of the parameters is as follows:

- table - Pointer to the table name.

- first - Pointer to the first key.

- second - Pointer to the second key.

- _r_h - Pointer to the result handle, to free the result.

- _op - Pointer to the db options for this operation.

- _k - Pointer to the queried db keys.

- _v - Pointer to the queried db values.

- _c - Pointer to the db keys that should be returned.

- _n - Number of key-value pairs in _k and _v parameters.

- _nc - Number of key-value pairs in _c parameter.

- _o - Order by options for the query.

- _nc - Pointer to the result set.

## `int (* ul_db_free_result_t)(db_con_t ** dbh, db_res_t * res);`

Frees the given result set, .

Meaning of the parameters is as follows:

- dbh - Pointer to the result handle.

- res - Pointer to the result.