src/modules/sqlops/sql_api.h
dd6cc225
 /**
  * Copyright (C) 2008 Elena-Ramona Modroiu (asipto.com)
  *
  * This file is part of kamailio, a free SIP server.
  *
6c780225
  * Kamailio is free software; you can redistribute it and/or modify
dd6cc225
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version
  *
6c780225
  * Kamailio is distributed in the hope that it will be useful,
dd6cc225
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
9e1ff448
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
dd6cc225
  */
2caae8fd
 
 /*! \file
  * \ingroup sqlops
33cdf4f3
  * \brief Kamailio SQL-operations :: API
2caae8fd
  *
  * - Module: \ref sqlops
  */
 
dd6cc225
 #ifndef _SQL_API_H_
 #define _SQL_API_H_
 
cf83221d
 #include "../../core/sr_module.h"
c00d1faa
 #include "../../lib/srdb1/db.h"
cf83221d
 #include "../../core/pvar.h"
dd6cc225
 
 typedef struct _sql_col
 {
 	str name;
     unsigned int colid;
 } sql_col_t;
 
 typedef struct _sql_val
 {
 	int flags;
 	int_str value;
 } sql_val_t;
 
 typedef struct _sql_result
 {
 	unsigned int resid;
 	str name;
 	int nrows;
 	int ncols;
 	sql_col_t *cols;
 	sql_val_t **vals;
 	struct _sql_result *next;
 } sql_result_t;
 
 typedef struct _sql_con
 {
 	str name;
 	unsigned int conid;
 	str db_url;
c00d1faa
 	db1_con_t  *dbh;
dd6cc225
 	db_func_t dbf;
 	struct _sql_con *next;
 } sql_con_t;
 
 int sql_parse_param(char *val);
 void sql_destroy(void);
2df43b99
 int sql_connect(int mode);
 int sql_reconnect(sql_con_t *sc);
576ed7b9
 
 int sql_do_query(sql_con_t *con, str *query, sql_result_t *res);
6f886339
 int sql_do_query_async(sql_con_t *con, str *query);
7fceaf17
 int sql_do_xquery(sip_msg_t *msg, sql_con_t *con, pv_elem_t *query,
f2e79b33
 		pv_elem_t *res);
7fceaf17
 int sql_do_pvquery(sip_msg_t *msg, sql_con_t *con, pv_elem_t *query,
ab4e481b
 		pvname_list_t *res);
7fceaf17
 int pv_get_sqlrows(sip_msg_t *msg,  pv_param_t *param,
d947e752
 		pv_value_t *res);
 int pv_parse_con_name(pv_spec_p sp, str *in);
 
dd6cc225
 sql_con_t* sql_get_connection(str *name);
 sql_result_t* sql_get_result(str *name);
 
 void sql_reset_result(sql_result_t *res);
 
576ed7b9
 typedef int (*sqlops_do_query_f)(str *scon, str *squery, str *sres);
 int sqlops_do_query(str *scon, str *squery, str *sres);
 
99b933c1
 typedef int (*sqlops_get_value_f)(str *sres, int i, int j, sql_val_t **val);
 int sqlops_get_value(str *sres, int i, int j, sql_val_t **val);
576ed7b9
 
 typedef int (*sqlops_is_null_f)(str *sres, int i, int j);
 int sqlops_is_null(str *res, int i, int j);
 
 typedef int (*sqlops_get_column_f)(str *sres, int i, str *col);
 int sqlops_get_column(str *sres, int i, str *name);
 
 typedef int (*sqlops_num_columns_f)(str *sres);
 int sqlops_num_columns(str *sres);
 
 typedef int (*sqlops_num_rows_f)(str *sres);
 int sqlops_num_rows(str *sres);
 
 typedef void (*sqlops_reset_result_f)(str *sres);
 void sqlops_reset_result(str *sres);
 
7fceaf17
 typedef int (*sqlops_do_xquery_f)(sip_msg_t *msg, str *scon, str *squery, str *sxavp);
 int sqlops_do_xquery(sip_msg_t *msg, str *scon, str *squery, str *sxavp);
 
576ed7b9
 typedef struct sqlops_api {
 	sqlops_do_query_f query;
 	sqlops_get_value_f value;
 	sqlops_is_null_f is_null;
 	sqlops_get_column_f column;
 	sqlops_reset_result_f reset;
 	sqlops_num_rows_f nrows;
 	sqlops_num_columns_f ncols;
7fceaf17
 	sqlops_do_xquery_f xquery;
576ed7b9
 } sqlops_api_t;
 
 typedef int (*bind_sqlops_f)(sqlops_api_t* api);
 
 /**
  * @brief Load the SQLOps API
  */
 static inline int sqlops_load_api(sqlops_api_t *sqb)
 {
 	bind_sqlops_f bindsqlops;
 
 	bindsqlops = (bind_sqlops_f)find_export("bind_sqlops", 0, 0);
 	if ( bindsqlops == 0) {
 		LM_ERR("cannot find bind_sqlops\n");
 		return -1;
 	}
 	if (bindsqlops(sqb)==-1)
 	{
 		LM_ERR("cannot bind sqlops api\n");
 		return -1;
 	}
 	return 0;
 }
 
 
dd6cc225
 #endif