Skip to content

Commit

Permalink
Merge pull request #1467 from que273/master
Browse files Browse the repository at this point in the history
 sqlops: sqlops_do_query - Make result parameter optional in C API
  • Loading branch information
henningw committed Mar 3, 2018
2 parents 8c1f1c1 + 53e1326 commit 0648043
Showing 1 changed file with 56 additions and 4 deletions.
60 changes: 56 additions & 4 deletions src/modules/sqlops/sql_api.c
Expand Up @@ -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;
Expand All @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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)
{
Expand Down

0 comments on commit 0648043

Please sign in to comment.