mirror of
https://github.com/asterisk/asterisk.git
synced 2025-11-16 14:58:25 +00:00
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
This commit is contained in:
@@ -857,6 +857,21 @@ static int acf_odbc_read(struct ast_channel *chan, const char *cmd, char *s, cha
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (colcount <= 0) {
|
||||||
|
ast_verb(4, "Returned %d columns [%s]\n", colcount, ast_str_buffer(sql));
|
||||||
|
buf[0] = '\0';
|
||||||
|
SQLCloseCursor(stmt);
|
||||||
|
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
|
||||||
|
release_obj_or_dsn (&obj, &dsn);
|
||||||
|
if (!bogus_chan) {
|
||||||
|
pbx_builtin_setvar_helper(chan, "ODBCROWS", "0");
|
||||||
|
pbx_builtin_setvar_helper(chan, "ODBCSTATUS", "NODATA");
|
||||||
|
ast_autoservice_stop(chan);
|
||||||
|
}
|
||||||
|
odbc_datastore_free(resultset);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
res = SQLFetch(stmt);
|
res = SQLFetch(stmt);
|
||||||
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
|
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
|
||||||
int res1 = -1;
|
int res1 = -1;
|
||||||
@@ -1520,6 +1535,15 @@ static char *cli_odbc_read(struct ast_cli_entry *e, int cmd, struct ast_cli_args
|
|||||||
return CLI_SUCCESS;
|
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));
|
||||||
|
AST_RWLIST_UNLOCK(&queries);
|
||||||
|
return CLI_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
res = SQLFetch(stmt);
|
res = SQLFetch(stmt);
|
||||||
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
|
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
|
||||||
SQLCloseCursor(stmt);
|
SQLCloseCursor(stmt);
|
||||||
|
|||||||
Reference in New Issue
Block a user