浏览代码

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...)
Daniel-Constantin Mierla 11 年之前
父节点
当前提交
6f8863392a
共有 3 个文件被更改,包括 39 次插入0 次删除
  1. 23 0
      modules/sqlops/sql_api.c
  2. 1 0
      modules/sqlops/sql_api.h
  3. 15 0
      modules/sqlops/sqlops.c

+ 23 - 0
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)

+ 1 - 0
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);

+ 15 - 0
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
 /**
  *