Go to the documentation of this file.00001
00031 #ifndef _SQL_API_H_
00032 #define _SQL_API_H_
00033
00034 #include "../../sr_module.h"
00035 #include "../../lib/srdb1/db.h"
00036 #include "../../pvar.h"
00037
00038 typedef struct _sql_col
00039 {
00040 str name;
00041 unsigned int colid;
00042 } sql_col_t;
00043
00044 typedef struct _sql_val
00045 {
00046 int flags;
00047 int_str value;
00048 } sql_val_t;
00049
00050 typedef struct _sql_result
00051 {
00052 unsigned int resid;
00053 str name;
00054 int nrows;
00055 int ncols;
00056 sql_col_t *cols;
00057 sql_val_t **vals;
00058 struct _sql_result *next;
00059 } sql_result_t;
00060
00061 typedef struct _sql_con
00062 {
00063 str name;
00064 unsigned int conid;
00065 str db_url;
00066 db1_con_t *dbh;
00067 db_func_t dbf;
00068 struct _sql_con *next;
00069 } sql_con_t;
00070
00071 int sql_parse_param(char *val);
00072 void sql_destroy(void);
00073 int sql_connect(void);
00074
00075 int sql_do_query(sql_con_t *con, str *query, sql_result_t *res);
00076 #ifdef WITH_XAVP
00077 int sql_do_xquery(sip_msg_t *msg, sql_con_t *con, pv_elem_t *query,
00078 pv_elem_t *res);
00079 #endif
00080 int sql_do_pvquery(sip_msg_t *msg, sql_con_t *con, pv_elem_t *query,
00081 pvname_list_t *res);
00082 int pv_get_sqlrows(sip_msg_t *msg, pv_param_t *param,
00083 pv_value_t *res);
00084 int pv_parse_con_name(pv_spec_p sp, str *in);
00085
00086 sql_con_t* sql_get_connection(str *name);
00087 sql_result_t* sql_get_result(str *name);
00088
00089 void sql_reset_result(sql_result_t *res);
00090
00091 typedef int (*sqlops_do_query_f)(str *scon, str *squery, str *sres);
00092 int sqlops_do_query(str *scon, str *squery, str *sres);
00093
00094 typedef int (*sqlops_get_value_f)(str *sres, int i, int j, sql_val_t **val);
00095 int sqlops_get_value(str *sres, int i, int j, sql_val_t **val);
00096
00097 typedef int (*sqlops_is_null_f)(str *sres, int i, int j);
00098 int sqlops_is_null(str *res, int i, int j);
00099
00100 typedef int (*sqlops_get_column_f)(str *sres, int i, str *col);
00101 int sqlops_get_column(str *sres, int i, str *name);
00102
00103 typedef int (*sqlops_num_columns_f)(str *sres);
00104 int sqlops_num_columns(str *sres);
00105
00106 typedef int (*sqlops_num_rows_f)(str *sres);
00107 int sqlops_num_rows(str *sres);
00108
00109 typedef void (*sqlops_reset_result_f)(str *sres);
00110 void sqlops_reset_result(str *sres);
00111
00112 typedef int (*sqlops_do_xquery_f)(sip_msg_t *msg, str *scon, str *squery, str *sxavp);
00113 int sqlops_do_xquery(sip_msg_t *msg, str *scon, str *squery, str *sxavp);
00114
00115 typedef struct sqlops_api {
00116 sqlops_do_query_f query;
00117 sqlops_get_value_f value;
00118 sqlops_is_null_f is_null;
00119 sqlops_get_column_f column;
00120 sqlops_reset_result_f reset;
00121 sqlops_num_rows_f nrows;
00122 sqlops_num_columns_f ncols;
00123 sqlops_do_xquery_f xquery;
00124 } sqlops_api_t;
00125
00126 typedef int (*bind_sqlops_f)(sqlops_api_t* api);
00127
00131 static inline int sqlops_load_api(sqlops_api_t *sqb)
00132 {
00133 bind_sqlops_f bindsqlops;
00134
00135 bindsqlops = (bind_sqlops_f)find_export("bind_sqlops", 0, 0);
00136 if ( bindsqlops == 0) {
00137 LM_ERR("cannot find bind_sqlops\n");
00138 return -1;
00139 }
00140 if (bindsqlops(sqb)==-1)
00141 {
00142 LM_ERR("cannot bind sqlops api\n");
00143 return -1;
00144 }
00145 return 0;
00146 }
00147
00148
00149 #endif