summaryrefslogtreecommitdiff
path: root/cdr/cdr_adaptive_odbc.c
diff options
context:
space:
mode:
authorRodrigo Ramírez Norambuena <decipher.hk@gmail.com>2015-05-06 22:18:28 -0400
committerRodrigo Ramírez Norambuena <decipher.hk@gmail.com>2015-05-20 12:08:18 -0400
commit9c3c7797e5f1fead0d489b7cdaa41b6be5349898 (patch)
treea3e69d53aed6ce55250f1632523ced9d3c1489cc /cdr/cdr_adaptive_odbc.c
parent2bbfcfc647dc69089236cde0003ba88c3161d1ec (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 'cdr/cdr_adaptive_odbc.c')
-rw-r--r--cdr/cdr_adaptive_odbc.c33
1 files changed, 17 insertions, 16 deletions
diff --git a/cdr/cdr_adaptive_odbc.c b/cdr/cdr_adaptive_odbc.c
index e6b60dc10..f276959a0 100644
--- a/cdr/cdr_adaptive_odbc.c
+++ b/cdr/cdr_adaptive_odbc.c
@@ -395,6 +395,8 @@ static int odbc_log(struct ast_cdr *cdr)
char colbuf[1024], *colptr;
SQLHSTMT stmt = NULL;
SQLLEN rows = 0;
+ char *separator;
+ int quoted = 0;
if (!sql || !sql2) {
if (sql)
@@ -412,8 +414,7 @@ static int odbc_log(struct ast_cdr *cdr)
}
AST_LIST_TRAVERSE(&odbc_tables, tableptr, list) {
- int first = 1;
- int quoted = 0;
+ separator = "";
if (tableptr->quoted_identifiers != '\0'){
quoted = 1;
@@ -517,7 +518,7 @@ static int odbc_log(struct ast_cdr *cdr)
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, "''");
@@ -550,7 +551,7 @@ static int odbc_log(struct ast_cdr *cdr)
}
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:
@@ -566,7 +567,7 @@ static int odbc_log(struct ast_cdr *cdr)
}
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:
@@ -594,7 +595,7 @@ static int odbc_log(struct ast_cdr *cdr)
}
LENGTHEN_BUF2(26);
- ast_str_append(&sql2, 0, "%s{ ts '%04d-%02d-%02d %02d:%02d:%02d' }", first ? "" : ",", year, month, day, hour, minute, second);
+ ast_str_append(&sql2, 0, "%s{ ts '%04d-%02d-%02d %02d:%02d:%02d' }", separator, year, month, day, hour, minute, second);
}
break;
case SQL_INTEGER:
@@ -608,7 +609,7 @@ static int odbc_log(struct ast_cdr *cdr)
}
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:
@@ -622,7 +623,7 @@ static int odbc_log(struct ast_cdr *cdr)
}
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:
@@ -636,7 +637,7 @@ static int odbc_log(struct ast_cdr *cdr)
}
LENGTHEN_BUF2(6);
- ast_str_append(&sql2, 0, "%s%d", first ? "" : ",", integer);
+ ast_str_append(&sql2, 0, "%s%d", separator, integer);
}
break;
case SQL_TINYINT:
@@ -650,7 +651,7 @@ static int odbc_log(struct ast_cdr *cdr)
}
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:
@@ -666,7 +667,7 @@ static int odbc_log(struct ast_cdr *cdr)
integer = 1;
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:
@@ -698,7 +699,7 @@ static int odbc_log(struct ast_cdr *cdr)
}
LENGTHEN_BUF2(entry->decimals);
- 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:
@@ -731,7 +732,7 @@ static int odbc_log(struct ast_cdr *cdr)
}
LENGTHEN_BUF2(entry->decimals);
- ast_str_append(&sql2, 0, "%s%lf", first ? "" : ",", number);
+ ast_str_append(&sql2, 0, "%s%lf", separator, number);
}
break;
default:
@@ -739,11 +740,11 @@ static int odbc_log(struct ast_cdr *cdr)
continue;
}
if (quoted) {
- ast_str_append(&sql, 0, "%s%s", first ? "" : ",", entry->name);
+ ast_str_append(&sql, 0, "%s%s", separator, entry->name);
} else {
- ast_str_append(&sql, 0, "%s%c%s%c", first ? "" : ",", tableptr->quoted_identifiers, entry->name, tableptr->quoted_identifiers);
+ ast_str_append(&sql, 0, "%s%c%s%c", separator, tableptr->quoted_identifiers, entry->name, tableptr->quoted_identifiers);
}
- first = 0;
+ separator = ", ";
} else if (entry->filtervalue
&& ((!entry->negatefiltervalue && entry->filtervalue[0] != '\0')
|| (entry->negatefiltervalue && entry->filtervalue[0] == '\0'))) {