[Asterisk-code-review] cdr/cdr adaptive odbc.c: Add support set character for quote... (asterisk[master])
Rodrigo Ramirez Norambuena
asteriskteam at digium.com
Thu Apr 23 19:02:09 CDT 2015
Rodrigo Ramirez Norambuena has uploaded a new change for review.
https://gerrit.asterisk.org/246
Change subject: cdr/cdr_adaptive_odbc.c: Add support set character for quoted identifiers.
......................................................................
cdr/cdr_adaptive_odbc.c: Add support set character for quoted identifiers.
Added the ability to set the character to quote indentifiers. This allows add
the character and init and end of table and columns names. This setting is
configurable for cdr_adaptive_odbc via the quoted_identifiers in file
cdr_adaptive_odbc.conf.
ASTERISK-25006
Change-Id: I0b9a56b79ca13a727a803d88ed3b8643e37632b8
---
M CHANGES
M cdr/cdr_adaptive_odbc.c
M configs/samples/cdr_adaptive_odbc.conf.sample
3 files changed, 46 insertions(+), 5 deletions(-)
git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/46/246/1
diff --git a/CHANGES b/CHANGES
index 94ed559..e3e20ec 100644
--- a/CHANGES
+++ b/CHANGES
@@ -136,6 +136,17 @@
* Added a new option, 'usegmtime', which causes timestamps in CEL events
to be logged in GMT.
+CDR Backends
+------------------
+
+cdr_adaptive_odbc
+------------------
+ * Added the ability to set the character to quote indentifiers. This allows add
+ the character and init and end of table and columns names. This setting is
+ configurable for cdr_adaptive_odbc via the quoted_identifiers in file
+ cdr_adaptive_odbc.conf.
+
+
------------------------------------------------------------------------------
--- Functionality changes from Asterisk 13.3.0 to Asterisk 13.4.0 ------------
------------------------------------------------------------------------------
diff --git a/cdr/cdr_adaptive_odbc.c b/cdr/cdr_adaptive_odbc.c
index 83877cb..aa18779 100644
--- a/cdr/cdr_adaptive_odbc.c
+++ b/cdr/cdr_adaptive_odbc.c
@@ -82,6 +82,7 @@
char *connection;
char *table;
char *schema;
+ char *quoted_identifiers;
unsigned int usegmtime:1;
AST_LIST_HEAD_NOLOCK(odbc_columns, columns) columns;
AST_RWLIST_ENTRY(tables) list;
@@ -101,7 +102,8 @@
char connection[40];
char table[40];
char schema[40];
- int lenconnection, lentable, lenschema, usegmtime = 0;
+ char quoted_identifiers[3];
+ int lenconnection, lentable, lenschema, lenquoted_identifiers, usegmtime = 0;
SQLLEN sqlptr;
int res = 0;
SQLHSTMT stmt = NULL;
@@ -149,6 +151,12 @@
ast_copy_string(schema, tmp, sizeof(schema));
lenschema = strlen(schema);
+ if (ast_strlen_zero(tmp = ast_variable_retrieve(cfg, catg, "quoted_identifiers"))) {
+ tmp = "";
+ }
+ ast_copy_string(quoted_identifiers, tmp, sizeof(quoted_identifiers));
+ lenquoted_identifiers = strlen(quoted_identifiers);
+
res = SQLAllocHandle(SQL_HANDLE_STMT, obj->con, &stmt);
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
ast_log(LOG_WARNING, "SQL Alloc Handle failed on connection '%s'!\n", connection);
@@ -164,7 +172,7 @@
continue;
}
- tableptr = ast_calloc(sizeof(char), sizeof(*tableptr) + lenconnection + 1 + lentable + 1 + lenschema + 1);
+ tableptr = ast_calloc(sizeof(char), sizeof(*tableptr) + lenconnection + 1 + lentable + 1 + lenschema + 1 + lenquoted_identifiers + 1);
if (!tableptr) {
ast_log(LOG_ERROR, "Out of memory creating entry for table '%s' on connection '%s'%s%s%s\n", table, connection,
lenschema ? " (schema '" : "", lenschema ? schema : "", lenschema ? "')" : "");
@@ -178,9 +186,11 @@
tableptr->connection = (char *)tableptr + sizeof(*tableptr);
tableptr->table = (char *)tableptr + sizeof(*tableptr) + lenconnection + 1;
tableptr->schema = (char *)tableptr + sizeof(*tableptr) + lenconnection + 1 + lentable + 1;
+ tableptr->quoted_identifiers = (char *)tableptr + sizeof(*tableptr) + lenconnection + 1 + lentable + 1 + lenschema + 1;
ast_copy_string(tableptr->connection, connection, lenconnection + 1);
ast_copy_string(tableptr->table, table, lentable + 1);
ast_copy_string(tableptr->schema, schema, lenschema + 1);
+ ast_copy_string(tableptr->quoted_identifiers, quoted_identifiers, lenquoted_identifiers + 1);
ast_verb(3, "Found adaptive CDR table %s@%s.\n", tableptr->table, tableptr->connection);
@@ -379,6 +389,8 @@
struct odbc_obj *obj;
struct ast_str *sql = ast_str_create(maxsize), *sql2 = ast_str_create(maxsize2);
char *tmp;
+ char table[40];
+ char schema[40];
char colbuf[1024], *colptr;
SQLHSTMT stmt = NULL;
SQLLEN rows = 0;
@@ -400,10 +412,21 @@
AST_LIST_TRAVERSE(&odbc_tables, tableptr, list) {
int first = 1;
+ if (ast_strlen_zero(tableptr->quoted_identifiers)){
+ ast_copy_string(table, tableptr->table, sizeof(table));
+ ast_copy_string(schema, tableptr->schema, sizeof(schema));
+ }else{
+ struct ast_str *t = ast_str_create(maxsize), *s = ast_str_create(maxsize2);
+ ast_str_set(&t, 0, "%s%s%s", tableptr->quoted_identifiers, tableptr->table, tableptr->quoted_identifiers);
+ ast_str_set(&s, 0, "%s%s%s", tableptr->quoted_identifiers, tableptr->schema, tableptr->quoted_identifiers);
+ ast_copy_string(table, ast_str_buffer(t), sizeof(table));
+ ast_copy_string(schema, ast_str_buffer(s), sizeof(schema));
+ }
+
if (ast_strlen_zero(tableptr->schema)) {
- ast_str_set(&sql, 0, "INSERT INTO %s (", tableptr->table);
+ ast_str_set(&sql, 0, "INSERT INTO %s (", table);
} else {
- ast_str_set(&sql, 0, "INSERT INTO %s.%s (", tableptr->schema, tableptr->table);
+ ast_str_set(&sql, 0, "INSERT INTO %s.%s (", schema, table);
}
ast_str_set(&sql2, 0, " VALUES (");
@@ -708,7 +731,11 @@
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;
}
- ast_str_append(&sql, 0, "%s%s", first ? "" : ",", entry->name);
+ if (ast_strlen_zero(tableptr->quoted_identifiers)) {
+ ast_str_append(&sql, 0, "%s%s", first ? "" : ",", entry->name);
+ } else {
+ ast_str_append(&sql, 0, "%s%s%s%s", first ? "" : ",", tableptr->quoted_identifiers, entry->name, tableptr->quoted_identifiers);
+ }
first = 0;
} else if (entry->filtervalue
&& ((!entry->negatefiltervalue && entry->filtervalue[0] != '\0')
diff --git a/configs/samples/cdr_adaptive_odbc.conf.sample b/configs/samples/cdr_adaptive_odbc.conf.sample
index f3c806e..58a5966 100644
--- a/configs/samples/cdr_adaptive_odbc.conf.sample
+++ b/configs/samples/cdr_adaptive_odbc.conf.sample
@@ -57,4 +57,7 @@
; for this is to allow different sections to specify different values for
; a certain named column, presumably separated by filters.
;static "Some Special Value" => identifier_code
+;
+; Add quoted indentifiers for table and columns names.
+;quoted_identifiers=" ; Default to null
--
To view, visit https://gerrit.asterisk.org/246
To unsubscribe, visit https://gerrit.asterisk.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I0b9a56b79ca13a727a803d88ed3b8643e37632b8
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: Rodrigo Ramirez Norambuena <decipher.hk at gmail.com>
More information about the asterisk-code-review
mailing list