[Asterisk-code-review] func odbc: NODATA if SQLNumResultCols returned 0 columns on ... (asterisk[13])
Alexei Gradinari
asteriskteam at digium.com
Thu May 31 10:29:27 CDT 2018
Alexei Gradinari has uploaded this change for review. ( https://gerrit.asterisk.org/9070
Change subject: func_odbc: NODATA if SQLNumResultCols returned 0 columns on readsql
......................................................................
func_odbc: NODATA if SQLNumResultCols returned 0 columns on readsql
The functions acf_odbc_read/cli_odbc_read ignore a number of columns
returned by the SQLNumResultCols.
If the number of columns is zero it means no data.
In this case, a SQLFetch function has to be not called,
because it will cause an error.
ASTERISK-27888 #close
Change-Id: Ie0f7bdac6c405aa5bbd38932c7b831f90729ee19
---
M funcs/func_odbc.c
1 file changed, 25 insertions(+), 0 deletions(-)
git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/70/9070/1
diff --git a/funcs/func_odbc.c b/funcs/func_odbc.c
index d19b56f..36e8a92 100644
--- a/funcs/func_odbc.c
+++ b/funcs/func_odbc.c
@@ -859,6 +859,23 @@
return -1;
}
+ if (colcount <= 0) {
+ ast_verb(4, "Returned %d columns [%s]\n", colcount, ast_str_buffer(sql));
+ buf[0] = '\0';
+ ast_copy_string(rowcount, "0", sizeof(rowcount));
+ status = "NODATA";
+ SQLCloseCursor(stmt);
+ SQLFreeHandle (SQL_HANDLE_STMT, stmt);
+ release_obj_or_dsn (&obj, &dsn);
+ if (!bogus_chan) {
+ pbx_builtin_setvar_helper(chan, "ODBCROWS", rowcount);
+ pbx_builtin_setvar_helper(chan, "ODBCSTATUS", status);
+ ast_autoservice_stop(chan);
+ }
+ odbc_datastore_free(resultset);
+ return 0;
+ }
+
res = SQLFetch(stmt);
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
int res1 = -1;
@@ -1522,6 +1539,14 @@
return CLI_SUCCESS;
}
+ if (colcount <= 0) {
+ SQLCloseCursor(stmt);
+ SQLFreeHandle (SQL_HANDLE_STMT, stmt);
+ release_obj_or_dsn (&obj, &dsn);
+ ast_cli(a->fd, "Returned %d columns. Query executed on handle %d:%s [%s]\n", colcount, dsn_num, query->readhandle[dsn_num], ast_str_buffer(sql));
+ break;
+ }
+
res = SQLFetch(stmt);
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
SQLCloseCursor(stmt);
--
To view, visit https://gerrit.asterisk.org/9070
To unsubscribe, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie0f7bdac6c405aa5bbd38932c7b831f90729ee19
Gerrit-Change-Number: 9070
Gerrit-PatchSet: 1
Gerrit-Owner: Alexei Gradinari <alex2grad at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180531/97287881/attachment.html>
More information about the asterisk-code-review
mailing list