[sr-dev] git:master:06480434: Merge pull request #1467 from que273/master

GitHub noreply at github.com
Sat Mar 3 19:03:33 CET 2018


Module: kamailio
Branch: master
Commit: 064804347421088e01c9f702933aa76ed59c7c13
URL: https://github.com/kamailio/kamailio/commit/064804347421088e01c9f702933aa76ed59c7c13

Author: henningw <henningw at users.noreply.github.com>
Committer: GitHub <noreply at github.com>
Date: 2018-03-03T19:03:27+01:00

Merge pull request #1467 from que273/master

 sqlops: sqlops_do_query - Make result parameter optional in C API

---

Modified: src/modules/sqlops/sql_api.c

---

Diff:  https://github.com/kamailio/kamailio/commit/064804347421088e01c9f702933aa76ed59c7c13.diff
Patch: https://github.com/kamailio/kamailio/commit/064804347421088e01c9f702933aa76ed59c7c13.patch

---

diff --git a/src/modules/sqlops/sql_api.c b/src/modules/sqlops/sql_api.c
index 16492300bc..21fbfa950f 100644
--- a/src/modules/sqlops/sql_api.c
+++ b/src/modules/sqlops/sql_api.c
@@ -697,17 +697,27 @@ int sqlops_do_query(str *scon, str *squery, str *sres)
 	sql_con_t *con = NULL;
 	sql_result_t *res = NULL;
 
+	if (scon == NULL || scon->s == NULL)
+	{
+		LM_ERR("invalid connection name\n");
+		goto error;
+	}
+
 	con = sql_get_connection(scon);
 	if(con==NULL)
 	{
 		LM_ERR("invalid connection [%.*s]\n", scon->len, scon->s);
 		goto error;
 	}
-	res = sql_get_result(sres);
-	if(res==NULL)
+	/* Result parameter is optional */
+	if (sres && sres->s)
 	{
-		LM_ERR("invalid result [%.*s]\n", sres->len, sres->s);
-		goto error;
+		res = sql_get_result(sres);
+		if(res==NULL)
+		{
+			LM_ERR("invalid result [%.*s]\n", sres->len, sres->s);
+			goto error;
+		}
 	}
 	if(sql_do_query(con, squery, res)<0)
 		goto error;
@@ -724,6 +734,12 @@ int sqlops_get_value(str *sres, int i, int j, sql_val_t **val)
 {
 	sql_result_t *res = NULL;
 
+	if (sres == NULL || sres->s == NULL)
+	{
+		LM_ERR("invalid result name\n");
+		goto error;
+	}
+
 	res = sql_get_result(sres);
 	if(res==NULL)
 	{
@@ -754,6 +770,12 @@ int sqlops_is_null(str *sres, int i, int j)
 {
 	sql_result_t *res = NULL;
 
+	if (sres == NULL || sres->s == NULL)
+	{
+		LM_ERR("invalid result name\n");
+		goto error;
+	}
+
 	res = sql_get_result(sres);
 	if(res==NULL)
 	{
@@ -784,6 +806,12 @@ int sqlops_get_column(str *sres, int i, str *col)
 {
 	sql_result_t *res = NULL;
 
+	if (sres == NULL || sres->s == NULL)
+	{
+		LM_ERR("invalid result name\n");
+		goto error;
+	}
+
 	res = sql_get_result(sres);
 	if(res==NULL)
 	{
@@ -808,6 +836,12 @@ int sqlops_num_columns(str *sres)
 {
 	sql_result_t *res = NULL;
 
+	if (sres == NULL || sres->s == NULL)
+	{
+		LM_ERR("invalid result name\n");
+		goto error;
+	}
+
 	res = sql_get_result(sres);
 	if(res==NULL)
 	{
@@ -826,6 +860,12 @@ int sqlops_num_rows(str *sres)
 {
 	sql_result_t *res = NULL;
 
+	if (sres == NULL || sres->s == NULL)
+	{
+		LM_ERR("invalid result name\n");
+		goto error;
+	}
+
 	res = sql_get_result(sres);
 	if(res==NULL)
 	{
@@ -844,6 +884,12 @@ void sqlops_reset_result(str *sres)
 {
 	sql_result_t *res = NULL;
 
+	if (sres == NULL || sres->s == NULL)
+	{
+		LM_ERR("invalid result name\n");
+		return;
+	}
+
 	res = sql_get_result(sres);
 	if(res==NULL)
 	{
@@ -862,6 +908,12 @@ int sqlops_do_xquery(sip_msg_t *msg, str *scon, str *squery, str *xavp)
 {
 	sql_con_t *con = NULL;
 
+	if (scon == NULL || scon->s == NULL)
+	{
+		LM_ERR("invalid connection name\n");
+		goto error;
+	}
+
 	con = sql_get_connection(scon);
 	if(con==NULL)
 	{




More information about the sr-dev mailing list