db_res.h File Reference

Data structure that represents a result from a query. More...

#include "db_key.h"
#include "db_val.h"

Include dependency graph for db_res.h:

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

Go to the source code of this file.

Data Structures

struct  db_res

Defines

#define RES_COL_N(re)   ((re)->col.n)
#define RES_LAST_ROW(re)   ((re)->last_row)
#define RES_NAMES(re)   ((re)->col.names)
#define RES_NUM_ROWS(re)   ((re)->res_rows)
#define RES_ROW_N(re)   ((re)->n)
#define RES_ROWS(re)   ((re)->rows)
#define RES_TYPES(re)   ((re)->col.types)

Typedefs

typedef struct db_res db_res_t

Functions

int db_allocate_columns (db_res_t *_r, const unsigned int cols)
int db_allocate_rows (db_res_t *_res)
int db_free_columns (db_res_t *_r)
int db_free_result (db_res_t *_r)
int db_free_rows (db_res_t *_r)
db_res_tdb_new_result (void)


Detailed Description

Data structure that represents a result from a query.

Data structure that represents a result from a database query, it also provides some convenience macros and some memory management functions for result structures.

Definition in file db_res.h.


Define Documentation

#define RES_COL_N ( re   )     ((re)->col.n)

#define RES_LAST_ROW ( re   )     ((re)->last_row)

Return the last row of the result

Definition at line 78 of file db_res.h.

Referenced by db_mysql_fetch_result(), db_postgres_convert_rows(), db_postgres_fetch_result(), and db_unixodbc_fetch_result().

#define RES_NAMES ( re   )     ((re)->col.names)

#define RES_NUM_ROWS ( re   )     ((re)->res_rows)

Return the number of total result rows

Definition at line 80 of file db_res.h.

Referenced by bdb_get_columns(), db_mysql_fetch_result(), and db_postgres_fetch_result().

#define RES_ROW_N ( re   )     ((re)->n)

#define RES_ROWS ( re   )     ((re)->rows)

#define RES_TYPES ( re   )     ((re)->col.types)


Typedef Documentation

typedef struct db_res db_res_t

This type represents a result returned by db_query function (see below). The result can consist of zero or more rows (see db_row_t description).

Note: A variable of type db_res_t returned by db_query function uses dynamicaly allocated memory, don't forget to call db_free_result if you don't need the variable anymore. You will encounter memory leaks if you fail to do this!

In addition to zero or more rows, each db_res_t object contains also an array of db_key_t objects. The objects represent keys (names of columns). *


Function Documentation

int db_allocate_columns ( db_res_t _r,
const unsigned int  cols 
) [inline]

Allocate storage for column names and type in existing result structure. If no more memory is available for the allocation of the types then the already allocated memory for the names is freed.

Parameters:
_r filled result set
cols number of columns
Returns:
zero on success, negative on errors

Definition at line 144 of file db_res.c.

References LM_DBG, LM_ERR, pkg_free, pkg_malloc, RES_NAMES, and RES_TYPES.

Referenced by bdb_get_columns(), db_mysql_get_columns(), db_postgres_get_columns(), db_unixodbc_get_columns(), dbt_get_columns(), and get_columns().

int db_allocate_rows ( db_res_t _res  )  [inline]

Allocate memory for rows.

Parameters:
_res result set
Returns:
zero on success, negative on errors

Definition at line 174 of file db_res.c.

References len, LM_DBG, LM_ERR, pkg_malloc, RES_ROW_N, and RES_ROWS.

Referenced by db_mysql_convert_rows(), db_postgres_convert_rows(), db_unixodbc_convert_rows(), and dbt_convert_rows().

int db_free_columns ( db_res_t _r  )  [inline]

Release memory used by columns. This methods assumes that the string values holding the column names are in memory allocated from the database driver, and thus must be not freed here.

Parameters:
_r the result that should be released
Returns:
zero on success, negative on errors

Definition at line 71 of file db_res.c.

References LM_DBG, LM_ERR, NULL, pkg_free, RES_COL_N, RES_NAMES, and RES_TYPES.

Referenced by bdb_get_columns(), db_free_result(), db_mysql_convert_result(), db_mysql_get_columns(), db_oracle_store_result(), db_postgres_convert_result(), db_postgres_get_columns(), db_unixodbc_convert_result(), db_unixodbc_fetch_result(), db_unixodbc_get_columns(), dbt_convert_result(), dbt_get_columns(), and get_columns().

int db_free_result ( db_res_t _r  )  [inline]

int db_free_rows ( db_res_t _r  )  [inline]

Release memory used by rows in a result structure.

Parameters:
_r the result that should be released
Returns:
zero on success, negative on errors

Definition at line 44 of file db_res.c.

References db_free_row(), LM_DBG, LM_ERR, NULL, pkg_free, RES_ROW_N, and RES_ROWS.

Referenced by _bdb_delete_cursor(), db_free_result(), db_mysql_convert_rows(), db_mysql_fetch_result(), db_postgres_convert_rows(), db_postgres_fetch_result(), db_unixodbc_convert_rows(), db_unixodbc_fetch_result(), dbt_convert_rows(), and get_rows().

db_res_t* db_new_result ( void   )  [inline]

Create a new result structure and initialize it.

Returns:
a pointer to the new result on success, NULL on errors

Definition at line 107 of file db_res.c.

References LM_DBG, LM_ERR, NULL, and pkg_malloc.

Referenced by _bdb_delete_cursor(), bdb_query(), db_mysql_fetch_result(), db_mysql_store_result(), db_oracle_store_result(), db_postgres_fetch_result(), db_postgres_store_result(), db_unixodbc_fetch_result(), db_unixodbc_store_result(), and dbt_get_result().


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