diff options
Diffstat (limited to 'res/res_config_sqlite.c')
-rw-r--r-- | res/res_config_sqlite.c | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/res/res_config_sqlite.c b/res/res_config_sqlite.c index 756de0cd5..114aa803b 100644 --- a/res/res_config_sqlite.c +++ b/res/res_config_sqlite.c @@ -789,6 +789,7 @@ static int cdr_handler(struct ast_cdr *cdr) struct sqlite_cache_tables *tbl = find_table(cdr_table); struct sqlite_cache_columns *col; struct ast_str *sql1 = ast_str_create(160), *sql2 = ast_str_create(16); + int first = 1; if (!tbl) { ast_log(LOG_WARNING, "No such table: %s\n", cdr_table); @@ -805,33 +806,31 @@ static int cdr_handler(struct ast_cdr *cdr) continue; } if (sscanf(tmp, "%d", &scannum) == 1) { - ast_str_append(&sql1, 0, "%s,", col->name); - ast_str_append(&sql2, 0, "%d,", scannum); + ast_str_append(&sql1, 0, "%s%s", first ? "" : ",", col->name); + ast_str_append(&sql2, 0, "%s%d", first ? "" : ",", scannum); } } else { ast_cdr_getvar(cdr, col->name, &tmp, workspace, sizeof(workspace), 0, 0); if (!tmp) { continue; } - ast_str_append(&sql1, 0, "%s,", col->name); + ast_str_append(&sql1, 0, "%s%s", first ? "" : ",", col->name); tmp = sqlite_mprintf("%Q", tmp); - ast_str_append(&sql2, 0, "%s,", tmp); + ast_str_append(&sql2, 0, "%s%s", first ? "" : ",", tmp); sqlite_freemem(tmp); } } release_table(tbl); - sql1->str[--sql1->used] = '\0'; - sql2->str[--sql2->used] = '\0'; - ast_str_append(&sql1, 0, "%s)", sql2->str); + ast_str_append(&sql1, 0, "%s)", ast_str_buffer(sql2)); ast_free(sql2); - ast_debug(1, "SQL query: %s\n", sql1->str); + ast_debug(1, "SQL query: %s\n", ast_str_buffer(sql1)); ast_mutex_lock(&mutex); RES_CONFIG_SQLITE_BEGIN - error = sqlite_exec(db, sql1->str, NULL, NULL, &errormsg); + error = sqlite_exec(db, ast_str_buffer(sql1), NULL, NULL, &errormsg); RES_CONFIG_SQLITE_END(error) ast_mutex_unlock(&mutex); @@ -1413,13 +1412,13 @@ static int realtime_update2_handler(const char *database, const char *table, first = 0; } - ast_str_append(&sql, 0, " %s", where->str); - ast_debug(1, "SQL query: %s\n", sql->str); + ast_str_append(&sql, 0, " %s", ast_str_buffer(where)); + ast_debug(1, "SQL query: %s\n", ast_str_buffer(sql)); ast_mutex_lock(&mutex); RES_CONFIG_SQLITE_BEGIN - error = sqlite_exec(db, sql->str, NULL, NULL, &errormsg); + error = sqlite_exec(db, ast_str_buffer(sql), NULL, NULL, &errormsg); RES_CONFIG_SQLITE_END(error) if (!error) { |