db_postgres/dbase.c File Reference

DB_POSTGRES :: Core

Module: DB_POSTGRES :: the PostgreSQL driver for Kamailio. More...

#include <string.h>
#include <stdio.h>
#include "../../dprint.h"
#include "../../mem/mem.h"
#include "../../db/db.h"
#include "../../db/db_ut.h"
#include "../../db/db_query.h"
#include "dbase.h"
#include "pg_con.h"
#include "val.h"
#include "res.h"

Include dependency graph for db_postgres/dbase.c:

Go to the source code of this file.

Defines

#define MAXCOLUMNS   512

Functions

void db_postgres_close (db_con_t *_h)
 Close database when the database is no longer needed.
int db_postgres_delete (const db_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 the specified table.
int db_postgres_fetch_result (const db_con_t *_con, db_res_t **_res, const int nrows)
 Gets a partial result set, fetch rows from a result.
static void db_postgres_free_query (const db_con_t *_con)
 Free database and any old query results.
int db_postgres_free_result (db_con_t *_con, db_res_t *_r)
 Free the query and the result memory in the core.
db_con_tdb_postgres_init (const str *_url)
 Initialize database for future queries.
int db_postgres_insert (const db_con_t *_h, const db_key_t *_k, const db_val_t *_v, const int _n)
 Insert a row into specified table.
int db_postgres_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)
 Query table for specified rows.
int db_postgres_raw_query (const db_con_t *_h, const str *_s, db_res_t **_r)
int db_postgres_store_result (const db_con_t *_con, db_res_t **_r)
 Retrieve result set.
static int db_postgres_submit_query (const db_con_t *_con, const str *_s)
 Submit_query, run a query.
int db_postgres_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 db_postgres_use_table (db_con_t *_con, const str *_t)


Detailed Description

DB_POSTGRES :: Core

Module: DB_POSTGRES :: the PostgreSQL driver for Kamailio.

Definition in file db_postgres/dbase.c.


Define Documentation

#define MAXCOLUMNS   512

maximum number of columns

Definition at line 68 of file db_postgres/dbase.c.


Function Documentation

void db_postgres_close ( db_con_t _h  ) 

Close database when the database is no longer needed.

Parameters:
_h closed connection, as returned from db_postgres_init
Note:
free all memory and resources

Definition at line 102 of file db_postgres/dbase.c.

References db_do_close(), and db_postgres_free_connection().

Referenced by db_postgres_bind_api().

int db_postgres_delete ( const db_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 the specified table.

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
Returns:
0 on success, negative on failure

Definition at line 491 of file db_postgres/dbase.c.

References db_do_delete(), db_free_result(), db_postgres_store_result(), db_postgres_submit_query(), db_postgres_val2str(), LM_WARN, and NULL.

Referenced by db_postgres_bind_api().

int db_postgres_fetch_result ( const db_con_t _con,
db_res_t **  _res,
const int  nrows 
)

Gets a partial result set, 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.

Parameters:
_con database connection
_res result set
nrows number of fetches rows
Returns:
0 on success, negative on failure

Definition at line 175 of file db_postgres/dbase.c.

References CON_CONNECTION, CON_RESULT, db_free_result(), db_free_rows(), db_new_result(), db_postgres_convert_rows(), db_postgres_get_columns(), LM_DBG, LM_ERR, NULL, RES_LAST_ROW, RES_NUM_ROWS, RES_ROW_N, and RES_ROWS.

Referenced by db_postgres_bind_api().

static void db_postgres_free_query ( const db_con_t _con  )  [static]

Free database and any old query results.

Parameters:
_con database connection

Definition at line 298 of file db_postgres/dbase.c.

References CON_RESULT, and LM_DBG.

Referenced by db_postgres_free_result(), db_postgres_store_result(), and db_postgres_submit_query().

int db_postgres_free_result ( db_con_t _con,
db_res_t _r 
)

Free the query and the result memory in the core.

Parameters:
_con database connection
_r result set
Returns:
0 on success, -1 on failure

Definition at line 315 of file db_postgres/dbase.c.

References db_free_result(), db_postgres_free_query(), and LM_ERR.

Referenced by db_postgres_bind_api().

db_con_t* db_postgres_init ( const str _url  ) 

Initialize database for future queries.

Parameters:
_url URL of the database that should be opened
Returns:
database connection on success, NULL on error
Note:
this function must be called prior to any database functions

Definition at line 91 of file db_postgres/dbase.c.

References db_do_init(), and db_postgres_new_connection().

Referenced by db_postgres_bind_api().

int db_postgres_insert ( const db_con_t _h,
const db_key_t _k,
const db_val_t _v,
const int  _n 
)

Insert a row into specified table.

Parameters:
_h structure representing database connection
_k key names
_v values of the keys
_n number of key=value pairs
Returns:
0 on success, negative on failure

Definition at line 465 of file db_postgres/dbase.c.

References db_do_insert(), db_free_result(), db_postgres_store_result(), db_postgres_submit_query(), db_postgres_val2str(), LM_WARN, and NULL.

Referenced by db_postgres_bind_api().

int db_postgres_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 
)

Query table for specified rows.

Parameters:
_h structure representing database connection
_k key names
_op operators
_v values of the keys that must match
_c column names to return
_n nmber of key=values pairs to compare
_nc number of columns to return
_o order by the specified column
_r result set
Returns:
0 on success, negative on failure

Definition at line 343 of file db_postgres/dbase.c.

References db_do_query(), db_postgres_store_result(), db_postgres_submit_query(), and db_postgres_val2str().

Referenced by db_postgres_bind_api().

int db_postgres_raw_query ( const db_con_t _h,
const str _s,
db_res_t **  _r 
)

Execute a raw SQL query

Parameters:
_h database connection
_s raw query string
_r result set
Returns:
0 on success, negative on failure

Definition at line 359 of file db_postgres/dbase.c.

References db_do_raw_query(), db_postgres_store_result(), and db_postgres_submit_query().

Referenced by db_postgres_bind_api().

int db_postgres_store_result ( const db_con_t _con,
db_res_t **  _r 
)

Retrieve result set.

Parameters:
_con structure representing the database connection
_r pointer to a structure represending the result set
Returns:
0 If the status of the last command produced a result set and, If the result set contains data or the convert_result() routine completed successfully. Negative if the status of the last command was not handled or if the convert_result() returned an error.
Note:
A new result structure is allocated on every call to this routine. If this routine returns 0, it is the callers responsbility to free the result structure. If this routine returns < 0, then the result structure is freed before returning to the caller.

Definition at line 379 of file db_postgres/dbase.c.

References CON_CONNECTION, CON_RESULT, db_free_result(), db_new_result(), db_postgres_convert_result(), db_postgres_free_query(), LM_DBG, LM_ERR, NULL, and pkg_free.

Referenced by db_postgres_delete(), db_postgres_insert(), db_postgres_query(), db_postgres_raw_query(), and db_postgres_update().

static int db_postgres_submit_query ( const db_con_t _con,
const str _s 
) [static]

Submit_query, run a query.

Parameters:
_con database connection
_s query string
Returns:
0 on success, negative on failure

Definition at line 114 of file db_postgres/dbase.c.

References CON_CONNECTION, db_postgres_free_query(), _str::len, LM_DBG, LM_ERR, and _str::s.

Referenced by db_postgres_delete(), db_postgres_insert(), db_postgres_query(), db_postgres_raw_query(), and db_postgres_update().

int db_postgres_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 
)

Update some rows in the specified table

Parameters:
_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
Returns:
0 on success, negative on failure

Definition at line 520 of file db_postgres/dbase.c.

References db_do_update(), db_free_result(), db_postgres_store_result(), db_postgres_submit_query(), db_postgres_val2str(), LM_WARN, and NULL.

Referenced by db_postgres_bind_api().

int db_postgres_use_table ( db_con_t _con,
const str _t 
)

Store name of table that will be used by subsequent database functions

Parameters:
_con database connection
_t table name
Returns:
0 on success, negative on error

Definition at line 544 of file db_postgres/dbase.c.

References db_use_table().

Referenced by db_postgres_bind_api().


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