diff options
author | Rodrigo Ramírez Norambuena <decipher.hk@gmail.com> | 2015-05-06 22:18:28 -0400 |
---|---|---|
committer | Rodrigo Ramírez Norambuena <decipher.hk@gmail.com> | 2015-05-20 12:08:18 -0400 |
commit | 9c3c7797e5f1fead0d489b7cdaa41b6be5349898 (patch) | |
tree | a3e69d53aed6ce55250f1632523ced9d3c1489cc /cel | |
parent | 2bbfcfc647dc69089236cde0003ba88c3161d1ec (diff) |
cel, cdr: Assigned separator for column name and values.
Use a separator string between column names and values for SQL sentences
instead of evaluating the separator to use each time.
This change adds a space after the comma in constructing SQL sentences.
Before the SQL was created like "INSERT INTO cdr(calldate,clid,dst"
without spaces between column name and values.
The files applied this change are cdr/cdr_adaptive_odbc.c, cdr/cdr_pgsql.c,
cel/cel_odbc.c
ASTERISK-25109 #close
Reported By: Rodrigo Ramírez Norambuena <decipher.hk@gmail.com>
Change-Id: Ia5a1a161f5e26e1643703b30f8cc9cf0860cc7ea
Diffstat (limited to 'cel')
-rw-r--r-- | cel/cel_odbc.c | 48 |
1 files changed, 24 insertions, 24 deletions
diff --git a/cel/cel_odbc.c b/cel/cel_odbc.c index 480344499..2d8408baa 100644 --- a/cel/cel_odbc.c +++ b/cel/cel_odbc.c @@ -402,7 +402,7 @@ static void odbc_log(struct ast_event *event) } AST_LIST_TRAVERSE(&odbc_tables, tableptr, list) { - int first = 1; + char *separator = ""; ast_str_set(&sql, 0, "INSERT INTO %s (", tableptr->table); ast_str_set(&sql2, 0, " VALUES ("); @@ -536,11 +536,11 @@ static void odbc_log(struct ast_event *event) } } - ast_str_append(&sql, 0, "%s%s", first ? "" : ",", entry->name); + ast_str_append(&sql, 0, "%s%s", separator, entry->name); LENGTHEN_BUF2(strlen(colptr)); /* Encode value, with escaping */ - ast_str_append(&sql2, 0, "%s'", first ? "" : ","); + ast_str_append(&sql2, 0, "%s'", separator); for (tmp = colptr; *tmp; tmp++) { if (*tmp == '\'') { ast_str_append(&sql2, 0, "''"); @@ -580,9 +580,9 @@ static void odbc_log(struct ast_event *event) } } - ast_str_append(&sql, 0, "%s%s", first ? "" : ",", entry->name); + ast_str_append(&sql, 0, "%s%s", separator, entry->name); LENGTHEN_BUF2(17); - ast_str_append(&sql2, 0, "%s{d '%04d-%02d-%02d'}", first ? "" : ",", year, month, day); + ast_str_append(&sql2, 0, "%s{d '%04d-%02d-%02d'}", separator, year, month, day); } break; case SQL_TYPE_TIME: @@ -605,9 +605,9 @@ static void odbc_log(struct ast_event *event) } } - ast_str_append(&sql, 0, "%s%s", first ? "" : ",", entry->name); + ast_str_append(&sql, 0, "%s%s", separator, entry->name); LENGTHEN_BUF2(15); - ast_str_append(&sql2, 0, "%s{t '%02d:%02d:%02d'}", first ? "" : ",", hour, minute, second); + ast_str_append(&sql2, 0, "%s{t '%02d:%02d:%02d'}", separator, hour, minute, second); } break; case SQL_TYPE_TIMESTAMP: @@ -646,9 +646,9 @@ static void odbc_log(struct ast_event *event) } } - ast_str_append(&sql, 0, "%s%s", first ? "" : ",", entry->name); + ast_str_append(&sql, 0, "%s%s", separator, entry->name); LENGTHEN_BUF2(27); - ast_str_append(&sql2, 0, "%s{ts '%04d-%02d-%02d %02d:%02d:%02d.%d'}", first ? "" : ",", year, month, day, hour, minute, second, fraction); + ast_str_append(&sql2, 0, "%s{ts '%04d-%02d-%02d %02d:%02d:%02d.%d'}", separator, year, month, day, hour, minute, second, fraction); } break; case SQL_INTEGER: @@ -659,9 +659,9 @@ static void odbc_log(struct ast_event *event) continue; } - ast_str_append(&sql, 0, "%s%s", first ? "" : ",", entry->name); + ast_str_append(&sql, 0, "%s%s", separator, entry->name); LENGTHEN_BUF2(12); - ast_str_append(&sql2, 0, "%s%d", first ? "" : ",", integer); + ast_str_append(&sql2, 0, "%s%d", separator, integer); } break; case SQL_BIGINT: @@ -673,9 +673,9 @@ static void odbc_log(struct ast_event *event) continue; } - ast_str_append(&sql, 0, "%s%s", first ? "" : ",", entry->name); + ast_str_append(&sql, 0, "%s%s", separator, entry->name); LENGTHEN_BUF2(24); - ast_str_append(&sql2, 0, "%s%lld", first ? "" : ",", integer); + ast_str_append(&sql2, 0, "%s%lld", separator, integer); } break; case SQL_SMALLINT: @@ -686,9 +686,9 @@ static void odbc_log(struct ast_event *event) continue; } - ast_str_append(&sql, 0, "%s%s", first ? "" : ",", entry->name); + ast_str_append(&sql, 0, "%s%s", separator, entry->name); LENGTHEN_BUF2(7); - ast_str_append(&sql2, 0, "%s%d", first ? "" : ",", integer); + ast_str_append(&sql2, 0, "%s%d", separator, integer); } break; case SQL_TINYINT: @@ -699,9 +699,9 @@ static void odbc_log(struct ast_event *event) continue; } - ast_str_append(&sql, 0, "%s%s", first ? "" : ",", entry->name); + ast_str_append(&sql, 0, "%s%s", separator, entry->name); LENGTHEN_BUF2(4); - ast_str_append(&sql2, 0, "%s%d", first ? "" : ",", integer); + ast_str_append(&sql2, 0, "%s%d", separator, integer); } break; case SQL_BIT: @@ -714,9 +714,9 @@ static void odbc_log(struct ast_event *event) if (integer != 0) integer = 1; - ast_str_append(&sql, 0, "%s%s", first ? "" : ",", entry->name); + ast_str_append(&sql, 0, "%s%s", separator, entry->name); LENGTHEN_BUF2(2); - ast_str_append(&sql2, 0, "%s%d", first ? "" : ",", integer); + ast_str_append(&sql2, 0, "%s%d", separator, integer); } break; case SQL_NUMERIC: @@ -728,9 +728,9 @@ static void odbc_log(struct ast_event *event) continue; } - ast_str_append(&sql, 0, "%s%s", first ? "" : ",", entry->name); + ast_str_append(&sql, 0, "%s%s", separator, entry->name); LENGTHEN_BUF2(entry->decimals + 2); - ast_str_append(&sql2, 0, "%s%*.*lf", first ? "" : ",", entry->decimals, entry->radix, number); + ast_str_append(&sql2, 0, "%s%*.*lf", separator, entry->decimals, entry->radix, number); } break; case SQL_FLOAT: @@ -743,16 +743,16 @@ static void odbc_log(struct ast_event *event) continue; } - ast_str_append(&sql, 0, "%s%s", first ? "" : ",", entry->name); + ast_str_append(&sql, 0, "%s%s", separator, entry->name); LENGTHEN_BUF2(entry->decimals); - ast_str_append(&sql2, 0, "%s%lf", first ? "" : ",", number); + ast_str_append(&sql2, 0, "%s%lf", separator, number); } break; default: ast_log(LOG_WARNING, "Column type %d (field '%s:%s:%s') is unsupported at this time.\n", entry->type, tableptr->connection, tableptr->table, entry->name); continue; } - first = 0; + separator = ", "; } } |