Index: funcs/func_odbc.c =================================================================== --- funcs/func_odbc.c (revision 41071) +++ funcs/func_odbc.c (working copy) @@ -61,6 +61,8 @@ char sql_read[2048]; char sql_write[2048]; unsigned int flags; + unsigned int setvars; + char colprefix[20]; struct ast_custom_function *acf; }; @@ -203,6 +205,13 @@ SQLHSTMT stmt; SQLSMALLINT colcount=0; SQLINTEGER indicator; + + char fieldname[140]; + SQLCHAR colname[128]; + SQLSMALLINT coltype; + SQLSMALLINT colnamelen; + SQLUINTEGER precision; + SQLSMALLINT scale; AST_LIST_LOCK(&queries); AST_LIST_TRAVERSE(&queries, query, list) { @@ -295,6 +304,17 @@ return -1; } + /* Option: Return Values As Vars with optional prefix */ + if (query->setvars) { + SQLDescribeCol(stmt, x + 1, colname, sizeof(colname), &colnamelen, &coltype, &precision, &scale, NULL); + if (query->colprefix) { + sprintf(fieldname, "%s%s", query->colprefix, colname); + pbx_builtin_setvar_helper(chan, fieldname, coldata); + } else { + pbx_builtin_setvar_helper(chan, colname, coldata); + } + } + /* Copy data, encoding '\' and ',' for the argument parser */ for (i = 0; i < sizeof(coldata); i++) { if (escapecommas && (coldata[i] == '\\' || coldata[i] == ',')) { @@ -373,6 +393,18 @@ ast_copy_string((*query)->sql_write, tmp, sizeof((*query)->sql_write)); } + /* Optional Setting Of Result Fields As Vars */ + if ((tmp = ast_variable_retrieve(cfg, catg, "setvars"))) { + if (ast_false(tmp)) + (*query)->setvars=0; + else + (*query)->setvars=1; + } + + if ((tmp = ast_variable_retrieve(cfg, catg, "colprefix"))) { + ast_copy_string((*query)->colprefix, tmp, sizeof((*query)->colprefix)); + } + /* Allow escaping of embedded commas in fields to be turned off */ ast_set_flag((*query), OPT_ESCAPECOMMAS); if ((tmp = ast_variable_retrieve(cfg, catg, "escapecommas"))) {