[sr-dev] git:master: sqlops: new cfg function - sql_query_asycn(con, sql)

Daniel-Constantin Mierla miconda at gmail.com
Mon Apr 14 22:38:21 CEST 2014


Module: sip-router
Branch: master
Commit: 6f8863392ac230d85289d5edcab1d0d83fc85b00
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=6f8863392ac230d85289d5edcab1d0d83fc85b00

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date:   Mon Apr 14 22:18:52 2014 +0200

sqlops: new cfg function - sql_query_asycn(con, sql)

- execute sql statement via async raw query, if implemented by db driver
  module (e.g., db_mysql)
- the query is executed in another process and result is not available
  back to config, thus it should be used only for sql statements that
  don't return values (e.g., insert, delete, update...)

---

 modules/sqlops/sql_api.c |   23 +++++++++++++++++++++++
 modules/sqlops/sql_api.h |    1 +
 modules/sqlops/sqlops.c  |   15 +++++++++++++++
 3 files changed, 39 insertions(+), 0 deletions(-)

diff --git a/modules/sqlops/sql_api.c b/modules/sqlops/sql_api.c
index 2518db1..0202bc5 100644
--- a/modules/sqlops/sql_api.c
+++ b/modules/sqlops/sql_api.c
@@ -415,6 +415,29 @@ error:
 	return -1;
 }
 
+int sql_do_query_async(sql_con_t *con, str *query)
+{
+	db1_res_t* db_res = NULL;
+	int i, j;
+	str sv;
+
+	if(query==NULL)
+	{
+		LM_ERR("bad parameters\n");
+		return -1;
+	}
+	if(con->dbf.raw_query_async==NULL) {
+		LM_ERR("the db driver module doesn't support async query\n");
+		return -1;
+	}
+	if(con->dbf.raw_query_async(con->dbh, query)!=0)
+	{
+		LM_ERR("cannot do the query\n");
+		return -1;
+	}
+	return 1;
+}
+
 #ifdef WITH_XAVP
 int sql_exec_xquery(struct sip_msg *msg, sql_con_t *con, str *query,
 		str *xavp)
diff --git a/modules/sqlops/sql_api.h b/modules/sqlops/sql_api.h
index aaffca6..374d9cc 100644
--- a/modules/sqlops/sql_api.h
+++ b/modules/sqlops/sql_api.h
@@ -73,6 +73,7 @@ void sql_destroy(void);
 int sql_connect(void);
 
 int sql_do_query(sql_con_t *con, str *query, sql_result_t *res);
+int sql_do_query_async(sql_con_t *con, str *query);
 #ifdef WITH_XAVP
 int sql_do_xquery(sip_msg_t *msg, sql_con_t *con, pv_elem_t *query,
 		pv_elem_t *res);
diff --git a/modules/sqlops/sqlops.c b/modules/sqlops/sqlops.c
index 695c6c5..2602bd9 100644
--- a/modules/sqlops/sqlops.c
+++ b/modules/sqlops/sqlops.c
@@ -62,6 +62,7 @@ static int bind_sqlops(sqlops_api_t* api);
 /** module functions */
 static int sql_query(struct sip_msg*, char*, char*, char*);
 static int sql_query2(struct sip_msg*, char*, char*);
+static int sql_query_async(struct sip_msg*, char*, char*);
 #ifdef WITH_XAVP
 static int sql_xquery(struct sip_msg *msg, char *dbl, char *query, char *res);
 #endif
@@ -93,6 +94,8 @@ static cmd_export_t cmds[]={
 		ANY_ROUTE},
 	{"sql_query",  (cmd_function)sql_query2, 2, fixup_sql_query, 0, 
 		ANY_ROUTE},
+	{"sql_query_async",  (cmd_function)sql_query_async, 2, fixup_sql_query, 0, 
+		ANY_ROUTE},
 #ifdef WITH_XAVP
 	{"sql_xquery",  (cmd_function)sql_xquery, 3, fixup_sql_xquery, 0, 
 		ANY_ROUTE},
@@ -214,6 +217,18 @@ static int sql_query2(struct sip_msg *msg, char *dbl, char *query)
 	return sql_query(msg, dbl, query, NULL);
 }
 
+static int sql_query_async(struct sip_msg *msg, char *dbl, char *query)
+{
+	str sq;
+	if(pv_printf_s(msg, (pv_elem_t*)query, &sq)!=0)
+	{
+		LM_ERR("cannot print the sql query\n");
+		return -1;
+	}
+	return sql_do_query_async((sql_con_t*)dbl, &sq);
+}
+
+
 #ifdef WITH_XAVP
 /**
  *




More information about the sr-dev mailing list