db_val.h File Reference

Data structures that represents values in the database. More...

#include "db_con.h"
#include <time.h>
#include "../str.h"

Include dependency graph for db_val.h:

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

Go to the source code of this file.

Data Structures

struct  db_val_t

Defines

#define VAL_BIGINT(dv)   ((dv)->val.ll_val)
#define VAL_BITMAP(dv)   ((dv)->val.bitmap_val)
#define VAL_BLOB(dv)   ((dv)->val.blob_val)
#define VAL_DOUBLE(dv)   ((dv)->val.double_val)
#define VAL_FREE(dv)   ((dv)->free)
#define VAL_INT(dv)   ((dv)->val.int_val)
#define VAL_NULL(dv)   ((dv)->nul)
#define VAL_STR(dv)   ((dv)->val.str_val)
#define VAL_STRING(dv)   ((dv)->val.string_val)
#define VAL_TIME(dv)   ((dv)->val.time_val)
#define VAL_TYPE(dv)   ((dv)->type)

Enumerations

enum  db_type_t {
  DB_INT, DB_BIGINT, DB_DOUBLE, DB_STRING,
  DB_STR, DB_DATETIME, DB_BLOB, DB_BITMAP
}

Functions

int db_str2val (const db_type_t _t, db_val_t *_v, const char *_s, const int _l, const unsigned int _cpy)
 Convert a str to a db value.
int db_val2str (const db_con_t *_c, const db_val_t *_v, char *_s, int *_len)
 Convert a numerical value to a string.


Detailed Description

Data structures that represents values in the database.

This file defines data structures that represents values in the database. Several datatypes are recognized and converted by the database API. Available types: DB_INT, DB_DOUBLE, DB_STRING, DB_STR, DB_DATETIME, DB_BLOB and DB_BITMAP It also provides some macros for convenient access to this values, and a function to convert a str to a value.

Definition in file db_val.h.


Define Documentation

#define VAL_BIGINT ( dv   )     ((dv)->val.ll_val)

Use this macro if you need to access the long long value in the db_val_t structure.

Definition at line 131 of file db_val.h.

Referenced by db_str2val(), and db_val2str().

#define VAL_BITMAP ( dv   )     ((dv)->val.bitmap_val)

Use this macro if you need to access the bitmap value in the db_val_t structure.

Definition at line 167 of file db_val.h.

Referenced by convert_row(), db_oracle_val2bind(), db_val2str(), dbrow2info(), flat_db_insert(), get_all_db_ucontacts(), get_columns(), and valdata().

#define VAL_BLOB ( dv   )     ((dv)->val.blob_val)

#define VAL_DOUBLE ( dv   )     ((dv)->val.double_val)

Use this macro if you need to access the double value in the db_val_t structure.

Definition at line 137 of file db_val.h.

Referenced by bdb_str2val(), bdb_val2str(), convert_row(), db_oracle_val2bind(), db_str2val(), db_val2str(), dbrow2info(), dbt_convert_row(), flat_db_insert(), get_columns(), and valdata().

#define VAL_FREE ( dv   )     ((dv)->free)

Use this macro if you need to set/ get the free flag. A non-zero flag means that the corresponding cell in the database contains data that must be freed from the DB API.

Definition at line 119 of file db_val.h.

Referenced by bdb_str2val(), convert_row(), db_free_row(), db_postgres_str2val(), db_str2val(), and dbt_convert_row().

#define VAL_INT ( dv   )     ((dv)->val.int_val)

#define VAL_NULL ( dv   )     ((dv)->nul)

#define VAL_STR ( dv   )     ((dv)->val.str_val)

#define VAL_STRING ( dv   )     ((dv)->val.string_val)

#define VAL_TIME ( dv   )     ((dv)->val.time_val)

Use this macro if you need to access the time_t value in the db_val_t structure.

Definition at line 143 of file db_val.h.

Referenced by bdb_str2val(), bdb_val2str(), convert_row(), db_oracle_val2bind(), db_str2val(), db_val2str(), dbrow2info(), flat_db_insert(), and valdata().

#define VAL_TYPE ( dv   )     ((dv)->type)


Enumeration Type Documentation

enum db_type_t

Each cell in a database table can be of a different type. To distinguish among these types, the db_type_t enumeration is used. Every value of the enumeration represents one datatype that is recognized by the database API.

Enumerator:
DB_INT  represents an 32 bit integer number
DB_BIGINT  represents an 64 bit integer number
DB_DOUBLE  represents a floating point number
DB_STRING  represents a zero terminated const char*
DB_STR  represents a string of 'str' type
DB_DATETIME  represents date and time
DB_BLOB  represents a large binary object
DB_BITMAP  an one-dimensional array of 32 flags

Definition at line 51 of file db_val.h.


Function Documentation

int db_str2val ( const db_type_t  _t,
db_val_t _v,
const char *  _s,
const int  _l,
const unsigned int  _cpy 
)

Convert a str to a db value.

Convert a str to a db value, does not copy strings if _cpy is zero

Parameters:
_t destination value type
_v destination value
_s source string
_l string length
_cpy when set to zero does not copy strings, otherwise copy strings
Returns:
0 on success, negative on error
Convert a str to a db value, copy strings if _cpy is not zero. Copying is not necessary if the result from the database client library is freed after the result inside the server is processed. If the result is freed earlier, e.g. because its saved inside some temporary storage, then it must be copied in order to be use it reliable.

Parameters:
_t destination value type
_v destination value
_s source string
_l string length
_cpy when set to zero does not copy strings, otherwise copy strings
Returns:
0 on success, negative on error

Definition at line 45 of file db_val.c.

References DB_BIGINT, DB_BITMAP, DB_BLOB, DB_DATETIME, DB_DOUBLE, DB_INT, DB_STR, db_str2double(), db_str2int(), db_str2longlong(), db_str2time(), DB_STRING, LM_DBG, LM_ERR, NULL, pkg_malloc, s, _str::s, VAL_BIGINT, VAL_BLOB, VAL_DOUBLE, VAL_FREE, VAL_INT, VAL_NULL, VAL_STR, VAL_STRING, VAL_TIME, and VAL_TYPE.

Referenced by db_mysql_convert_row(), db_postgres_str2val(), and db_unixodbc_str2val().

int db_val2str ( const db_con_t _c,
const db_val_t _v,
char *  _s,
int *  _len 
)

Convert a numerical value to a string.

Convert a numerical value to a string, used when converting result from a query. Implement common functionality needed from the databases, does parameter checking.

Parameters:
_c database connection
_v source value
_s target string
_len target string length
Returns:
0 on success, negative on error, 1 if value must be converted by other means

Definition at line 202 of file db_val.c.

References DB_BIGINT, DB_BITMAP, DB_DATETIME, DB_DOUBLE, db_double2str(), DB_INT, db_int2str(), db_longlong2str(), db_time2str(), LM_ERR, snprintf, VAL_BIGINT, VAL_BITMAP, VAL_DOUBLE, VAL_INT, VAL_NULL, VAL_TIME, and VAL_TYPE.

Referenced by db_mysql_val2str(), db_postgres_val2str(), and db_unixodbc_val2str().


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