Module: sip-router Branch: master Commit: 9b62514b4a90e169c9126b7bda6d87cc4c213ad2 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=9b62514b...
Author: Alex Hermann alex@speakup.nl Committer: Alex Hermann alex@speakup.nl Date: Thu Mar 10 15:21:06 2011 +0100
modules_k/sqlops: sql_query(): make result parameter optional
No need to specify a result parameter for SQL statements that do not return a resultset, so make it optional.
---
modules_k/sqlops/doc/sqlops_admin.xml | 4 +++- modules_k/sqlops/sql_api.c | 9 ++++++++- modules_k/sqlops/sqlops.c | 9 +++++++++ 3 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/modules_k/sqlops/doc/sqlops_admin.xml b/modules_k/sqlops/doc/sqlops_admin.xml index d042c61..a0a8512 100644 --- a/modules_k/sqlops/doc/sqlops_admin.xml +++ b/modules_k/sqlops/doc/sqlops_admin.xml @@ -179,7 +179,7 @@ modparam("sqlops", "sqlres", "ra") <title>Exported Functions</title> <section> <title> - <function moreinfo="none">sql_query(connection, query, result)</function> + <function moreinfo="none">sql_query(connection, query[, result])</function> </title> <para> Make a SQL query using 'connection' and store data in 'result'. @@ -201,6 +201,8 @@ modparam("sqlops", "sqlres", "ra") <emphasis>result</emphasis> - string name to identify the result. Will be used by $dbr(...) pseudo-variable to access result attributes. + If omitted, any resultset will be discarded. The result parameter should + normally only be omitted when no result is expected (INSERT, UPDATE, DELETE). </para> </listitem> </itemizedlist> diff --git a/modules_k/sqlops/sql_api.c b/modules_k/sqlops/sql_api.c index 0dc97e0..5fe3371 100644 --- a/modules_k/sqlops/sql_api.c +++ b/modules_k/sqlops/sql_api.c @@ -208,7 +208,6 @@ int sql_do_query(sql_con_t *con, str *query, sql_result_t *res) LM_ERR("bad parameters\n"); return -1; } - sql_reset_result(res); if(con->dbf.raw_query(con->dbh, query, &db_res)!=0) { LM_ERR("cannot do the query\n"); @@ -221,6 +220,14 @@ int sql_do_query(sql_con_t *con, str *query, sql_result_t *res) con->dbf.free_result(con->dbh, db_res); return 2; } + if(!res) + { + LM_DBG("no sqlresult parameter, ignoring result from query\n"); + con->dbf.free_result(con->dbh, db_res); + return 3; + } + + sql_reset_result(res); res->ncols = RES_COL_N(db_res); res->nrows = RES_ROW_N(db_res); LM_DBG("rows [%d] cols [%d]\n", res->nrows, res->ncols); diff --git a/modules_k/sqlops/sqlops.c b/modules_k/sqlops/sqlops.c index 6d04e4b..a34a7d9 100644 --- a/modules_k/sqlops/sqlops.c +++ b/modules_k/sqlops/sqlops.c @@ -60,6 +60,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*); #ifdef WITH_XAVP static int sql_xquery(struct sip_msg *msg, char *dbl, char *query, char *res); #endif @@ -86,6 +87,9 @@ static cmd_export_t cmds[]={ {"sql_query", (cmd_function)sql_query, 3, fixup_sql_query, 0, REQUEST_ROUTE | FAILURE_ROUTE | ONREPLY_ROUTE | BRANCH_ROUTE | LOCAL_ROUTE}, + {"sql_query", (cmd_function)sql_query2, 2, fixup_sql_query, 0, + REQUEST_ROUTE | FAILURE_ROUTE | + ONREPLY_ROUTE | BRANCH_ROUTE | LOCAL_ROUTE}, #ifdef WITH_XAVP {"sql_xquery", (cmd_function)sql_xquery, 3, fixup_sql_xquery, 0, REQUEST_ROUTE | FAILURE_ROUTE | @@ -192,6 +196,11 @@ static int sql_query(struct sip_msg *msg, char *dbl, char *query, char *res) return sql_do_query((sql_con_t*)dbl, &sq, (sql_result_t*)res); }
+static int sql_query2(struct sip_msg *msg, char *dbl, char *query) +{ + return sql_query(msg, dbl, query, NULL); +} + #ifdef WITH_XAVP /** *