--- funcs/func_odbc.c 2007-12-22 16:34:59.000000000 +0200 +++ ../clean/asterisk-1.4.15/funcs/func_odbc.c 2007-11-30 09:18:36.000000000 +0200 @@ -62,7 +62,6 @@ char dsn[30]; char sql_read[2048]; char sql_write[2048]; - char sql_insert[2048]; unsigned int flags; struct ast_custom_function *acf; }; @@ -99,7 +98,7 @@ { struct odbc_obj *obj; struct acf_odbc_query *query; - char *t, buf[2048]="", ibuf[2048]="", varname[15]; + char *t, buf[2048]="", varname[15]; int i, bogus_chan = 0; AST_DECLARE_APP_ARGS(values, AST_APP_ARG(field)[100]; @@ -169,10 +168,7 @@ /* Additionally set the value as a whole (but push an empty string if value is NULL) */ pbx_builtin_pushvar_helper(chan, "VALUE", value ? value : ""); - if (!ast_strlen_zero(query->sql_write)) - pbx_substitute_variables_helper(chan, query->sql_write, buf, sizeof(buf) - 1); - if (!ast_strlen_zero(query->sql_insert)) - pbx_substitute_variables_helper(chan, query->sql_insert, ibuf, sizeof(ibuf) - 1); + pbx_substitute_variables_helper(chan, query->sql_write, buf, sizeof(buf) - 1); /* Restore prior values */ for (i = 0; i < args.argc; i++) { @@ -188,20 +184,13 @@ AST_LIST_UNLOCK(&queries); - if (!ast_strlen_zero(query->sql_write)) { - stmt = ast_odbc_prepare_and_execute(obj, generic_prepare, buf); - if (stmt) { - /* Rows affected */ - SQLRowCount(stmt, &rows); - } - } - if ((rows == 0) && (!ast_strlen_zero(query->sql_insert))) { - stmt = ast_odbc_prepare_and_execute(obj, generic_prepare, ibuf); - if (stmt) { - /* Rows affected */ - SQLRowCount(stmt, &rows); - } + stmt = ast_odbc_prepare_and_execute(obj, generic_prepare, buf); + + if (stmt) { + /* Rows affected */ + SQLRowCount(stmt, &rows); } + /* Output the affected rows, for all cases. In the event of failure, we * flag this as -1 rows. Note that this is different from 0 affected rows * which would be the case if we succeeded in our query, but the values did @@ -441,10 +430,6 @@ ast_copy_string((*query)->sql_write, tmp, sizeof((*query)->sql_write)); } - if ((tmp = ast_variable_retrieve(cfg, catg, "insert"))) { - ast_copy_string((*query)->sql_insert, tmp, sizeof((*query)->sql_insert)); - } - /* 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"))) { @@ -483,18 +468,7 @@ } (*query)->acf->synopsis = "Runs the referenced query with the specified arguments"; - if (!ast_strlen_zero((*query)->sql_read) && !ast_strlen_zero((*query)->sql_write) && !ast_strlen_zero((*query)->sql_insert)) { - asprintf((char **)&((*query)->acf->desc), - "Runs the following query, as defined in func_odbc.conf, performing\n" - "substitution of the arguments into the query as specified by ${ARG1},\n" - "${ARG2}, ... ${ARGn}. When setting the function, the values are provided\n" - "either in whole as ${VALUE} or parsed as ${VAL1}, ${VAL2}, ... ${VALn}.\n" - "The insert command will be executed when a update fails.\n" - "\nRead:\n%s\n\nWrite:\n%s\n\nInsert:\n%s\n", - (*query)->sql_read, - (*query)->sql_write, - (*query)->sql_insert); - } else if (!ast_strlen_zero((*query)->sql_read) && !ast_strlen_zero((*query)->sql_write)) { + if (!ast_strlen_zero((*query)->sql_read) && !ast_strlen_zero((*query)->sql_write)) { asprintf((char **)&((*query)->acf->desc), "Runs the following query, as defined in func_odbc.conf, performing\n" "substitution of the arguments into the query as specified by ${ARG1},\n" @@ -503,47 +477,20 @@ "\nRead:\n%s\n\nWrite:\n%s\n", (*query)->sql_read, (*query)->sql_write); - } else if (!ast_strlen_zero((*query)->sql_read) && !ast_strlen_zero((*query)->sql_insert)) { - asprintf((char **)&((*query)->acf->desc), - "Runs the following query, as defined in func_odbc.conf, performing\n" - "substitution of the arguments into the query as specified by ${ARG1},\n" - "${ARG2}, ... ${ARGn}. When setting the function, the values are provided\n" - "either in whole as ${VALUE} or parsed as ${VAL1}, ${VAL2}, ... ${VALn}.\n" - "\nRead:\n%s\n\nInsert:\n%s\n", - (*query)->sql_read, - (*query)->sql_insert); } else if (!ast_strlen_zero((*query)->sql_read)) { asprintf((char **)&((*query)->acf->desc), "Runs the following query, as defined in func_odbc.conf, performing\n" "substitution of the arguments into the query as specified by ${ARG1},\n" - "${ARG2}, ... ${ARGn}. This function may only be read, not set.\n\nRead:\n%s\n", + "${ARG2}, ... ${ARGn}. This function may only be read, not set.\n\nSQL:\n%s\n", (*query)->sql_read); - } else if (!ast_strlen_zero((*query)->sql_write) && !ast_strlen_zero((*query)->sql_insert)) { - asprintf((char **)&((*query)->acf->desc), - "Runs the following query, as defined in func_odbc.conf, performing\n" - "substitution of the arguments into the query as specified by ${ARG1},\n" - "${ARG2}, ... ${ARGn}. The values are provided either in whole as\n" - "${VALUE} or parsed as ${VAL1}, ${VAL2}, ... ${VALn}.\n" - "This function may only be set.\nWrite:\n%s\n\nInsert:\n%s\n", - (*query)->sql_write, - (*query)->sql_insert); } else if (!ast_strlen_zero((*query)->sql_write)) { asprintf((char **)&((*query)->acf->desc), "Runs the following query, as defined in func_odbc.conf, performing\n" "substitution of the arguments into the query as specified by ${ARG1},\n" "${ARG2}, ... ${ARGn}. The values are provided either in whole as\n" "${VALUE} or parsed as ${VAL1}, ${VAL2}, ... ${VALn}.\n" - "The insert command will be executed when a update fails.\n" - "This function may only be set.\nWrite:\n%s\n", + "This function may only be set.\nSQL:\n%s\n", (*query)->sql_write); - } else if (!ast_strlen_zero((*query)->sql_insert)) { - asprintf((char **)&((*query)->acf->desc), - "Runs the following query, as defined in func_odbc.conf, performing\n" - "substitution of the arguments into the query as specified by ${ARG1},\n" - "${ARG2}, ... ${ARGn}. The values are provided either in whole as\n" - "${VALUE} or parsed as ${VAL1}, ${VAL2}, ... ${VALn}.\n" - "This function may only be set.\nInsert:\n%s\n", - (*query)->sql_insert); } /* Could be out of memory, or could be we have neither sql_read nor sql_write */ @@ -562,7 +509,7 @@ (*query)->acf->read = acf_odbc_read; } - if ((ast_strlen_zero((*query)->sql_write)) && (ast_strlen_zero((*query)->sql_insert))) { + if (ast_strlen_zero((*query)->sql_write)) { (*query)->acf->write = NULL; } else { (*query)->acf->write = acf_odbc_write;