db_ut.h File Reference

Utility functions for database drivers. More...

#include <time.h>
#include "db_key.h"
#include "db.h"

Include dependency graph for db_ut.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define _XOPEN_SOURCE   600
#define SQL_BUF_LEN   65536

Functions

int db_double2str (double _v, char *_s, int *_l)
int db_int2str (int _v, char *_s, int *_l)
int db_longlong2str (long long _v, char *_s, int *_l)
int db_print_columns (char *_b, const int _l, const db_key_t *_c, const int _n)
int db_print_set (const db_con_t *_c, char *_b, const int _l, 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 db_print_values (const db_con_t *_c, char *_b, const int _l, const db_val_t *_v, const int _n, int(*val2str)(const db_con_t *, const db_val_t *, char *, int *))
int db_print_where (const db_con_t *_c, char *_b, const int _l, 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 db_str2double (const char *_s, double *_v)
int db_str2int (const char *_s, int *_v)
int db_str2longlong (const char *_s, long long *_v)
int db_str2time (const char *_s, time_t *_v)
int db_time2str (time_t _v, char *_s, int *_l)


Detailed Description

Utility functions for database drivers.

This utility methods are used from the database SQL driver to convert values and print SQL queries from the internal API representation.

Definition in file db_ut.h.


Define Documentation

#define _XOPEN_SOURCE   600

make strptime available use 600 for 'Single UNIX Specification, Version 3' _XOPEN_SOURCE creates conflict in swab definition in Solaris

Definition at line 47 of file db_ut.h.

#define SQL_BUF_LEN   65536

maximal SQL buffer length for database drivers

Definition at line 39 of file db_ut.h.

Referenced by db_do_delete(), db_do_insert(), db_do_query(), db_do_replace(), db_do_update(), and db_insert_update().


Function Documentation

int db_double2str ( double  _v,
char *  _s,
int *  _l 
) [inline]

Converts a double value into a char pointer.

Parameters:
_v source value
_s target value
_l available length and target length
Returns:
zero on sucess, negative on conversion errors

Definition at line 151 of file db_ut.c.

References LM_ERR, and snprintf.

Referenced by bdb_val2str(), and db_val2str().

int db_int2str ( int  _v,
char *  _s,
int *  _l 
) [inline]

Converts a integer value in a char pointer.

Parameters:
_v source value
_s target value
_l available length and target length
Returns:
zero on sucess, negative on conversion errors

Definition at line 105 of file db_ut.c.

References LM_ERR, and snprintf.

Referenced by bdb_val2str(), and db_val2str().

int db_longlong2str ( long long  _v,
char *  _s,
int *  _l 
) [inline]

Converts a long long value in a char pointer.

Parameters:
_v source value
_s target value
_l available length and target length
Returns:
zero on sucess, negative on conversion errors

Definition at line 128 of file db_ut.c.

References LM_ERR, and snprintf.

Referenced by db_val2str().

int db_print_columns ( char *  _b,
const int  _l,
const db_key_t _c,
const int  _n 
) [inline]

Print columns for a SQL statement, separated by commas.

Parameters:
_b target char
_l length of the target
_c keys that should be printed
_n number of keys
Returns:
the length of the printed result on success, negative on errors

Definition at line 237 of file db_ut.c.

References len, LM_ERR, s, and snprintf.

Referenced by db_do_insert(), db_do_query(), db_do_replace(), and db_insert_update().

int db_print_set ( const db_con_t _c,
char *  _b,
const int  _l,
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 
)

Print set clause for a SQL statement.

Parameters:
_c structure representing database connection
_b target char
_l length of the target
_k keys that should be printed
_v vals that should be printed
_n number of key/value pairs
(*val2str) function pointer to a db specific conversion function
Returns:
the length of the printed result on success, negative on errors

Definition at line 341 of file db_ut.c.

References len, LM_ERR, s, and snprintf.

Referenced by db_do_update(), and db_insert_update().

int db_print_values ( const db_con_t _c,
char *  _b,
const int  _l,
const db_val_t _v,
const int  _n,
int(*)(const db_con_t *, const db_val_t *, char *, int *)  val2str 
)

Print values for a SQL statement.

Parameters:
_c structure representing database connection
_b target char
_l length of the target
_v values that should be printed
_n number of values
(*val2str) function pointer to a db specific conversion function
Returns:
the length of the printed result on success, negative on errors

Definition at line 268 of file db_ut.c.

References len, and LM_ERR.

Referenced by db_do_insert(), db_do_replace(), and db_insert_update().

int db_print_where ( const db_con_t _c,
char *  _b,
const int  _l,
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 
)

Print where clause for a SQL statement.

Parameters:
_c structure representing database connection
_b target char
_l length of the target
_k keys that should be printed
_o optional operators
_v values that should be printed
_n number of key/value pairs
(*val2str) function pointer to a db specific conversion function
Returns:
the length of the printed result on success, negative on errors

Definition at line 297 of file db_ut.c.

References len, LM_ERR, s, and snprintf.

Referenced by db_do_delete(), db_do_query(), and db_do_update().

int db_str2double ( const char *  _s,
double *  _v 
) [inline]

Converts a char into a double value.

Parameters:
_s source value
_v target value
Returns:
zero on sucess, negative on conversion errors

Definition at line 89 of file db_ut.c.

References LM_ERR.

Referenced by bdb_str2val(), and db_str2val().

int db_str2int ( const char *  _s,
int *  _v 
) [inline]

Converts a char into an integer value.

Parameters:
_s source value
_v target value
Returns:
zero on sucess, negative on conversion errors

Definition at line 45 of file db_ut.c.

References LM_ERR.

Referenced by bdb_str2val(), and db_str2val().

int db_str2longlong ( const char *  _s,
long long *  _v 
) [inline]

Converts a char into an long long value.

Parameters:
_s source value
_v target value
Returns:
zero on sucess, negative on conversion errors

Definition at line 66 of file db_ut.c.

References LM_ERR.

Referenced by db_str2val().

int db_str2time ( const char *  _s,
time_t *  _v 
) [inline]

Converts a char into a time_t value.

Parameters:
_s source value
_v target value
Returns:
zero on sucess, negative on conversion errors

Definition at line 174 of file db_ut.c.

References LM_ERR, and NULL.

Referenced by bdb_str2val(), and db_str2val().

int db_time2str ( time_t  _v,
char *  _s,
int *  _l 
) [inline]

Convert a time_t value to string.

Parameters:
_v source value
_s target value
_l available length and target length
Returns:
zero on sucess, negative on conversion errors
Todo:
This functions add quotes to the time value. This should be done in the val2str function, as some databases like db_berkeley don't need or like this at all.

Definition at line 203 of file db_ut.c.

References LM_ERR, and NULL.

Referenced by db_val2str(), and get_all_db_ucontacts().


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