[Asterisk-code-review] cdr/cdr adaptive odbc.c: Assigned separator for column name ... (asterisk[master])

Rodrigo Ramirez Norambuena asteriskteam at digium.com
Thu May 14 11:02:51 CDT 2015


Rodrigo Ramirez Norambuena has uploaded a new change for review.

  https://gerrit.asterisk.org/469

Change subject: cdr/cdr_adaptive_odbc.c: Assigned separator for column name and values.
......................................................................

cdr/cdr_adaptive_odbc.c: Assigned separator for column name and values.

Set a directly separator for column names and values for SQL sentences
instead of evaluate in appending if set comma or null separator in sql
buffer.

This change added one space after comma in construction SQL sentences,
before the SQL was created like "INSERT INTO cdr(calldate,clid,dst" without
spaces between column name and values.

Change-Id: Ia5a1a161f5e26e1643703b30f8cc9cf0860cc7ea
---
M cdr/cdr_adaptive_odbc.c
1 file changed, 16 insertions(+), 15 deletions(-)


  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/69/469/1

diff --git a/cdr/cdr_adaptive_odbc.c b/cdr/cdr_adaptive_odbc.c
index e6b60dc..593f01d 100644
--- a/cdr/cdr_adaptive_odbc.c
+++ b/cdr/cdr_adaptive_odbc.c
@@ -395,6 +395,7 @@
 	char colbuf[1024], *colptr;
 	SQLHSTMT stmt = NULL;
 	SQLLEN rows = 0;
+	char *SEP;
 
 	if (!sql || !sql2) {
 		if (sql)
@@ -412,7 +413,7 @@
 	}
 
 	AST_LIST_TRAVERSE(&odbc_tables, tableptr, list) {
-		int first = 1;
+		SEP = "";
 		int quoted = 0;
 
 		if (tableptr->quoted_identifiers != '\0'){
@@ -517,7 +518,7 @@
 					LENGTHEN_BUF2(strlen(colptr));
 
 					/* Encode value, with escaping */
-					ast_str_append(&sql2, 0, "%s'", first ? "" : ",");
+					ast_str_append(&sql2, 0, "%s'", SEP);
 					for (tmp = colptr; *tmp; tmp++) {
 						if (*tmp == '\'') {
 							ast_str_append(&sql2, 0, "''");
@@ -550,7 +551,7 @@
 						}
 
 						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' }", SEP, year, month, day);
 					}
 					break;
 				case SQL_TYPE_TIME:
@@ -566,7 +567,7 @@
 						}
 
 						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' }", SEP, hour, minute, second);
 					}
 					break;
 				case SQL_TYPE_TIMESTAMP:
@@ -594,7 +595,7 @@
 						}
 
 						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' }", SEP, year, month, day, hour, minute, second);
 					}
 					break;
 				case SQL_INTEGER:
@@ -608,7 +609,7 @@
 						}
 
 						LENGTHEN_BUF2(12);
-						ast_str_append(&sql2, 0, "%s%d", first ? "" : ",", integer);
+						ast_str_append(&sql2, 0, "%s%d", SEP, integer);
 					}
 					break;
 				case SQL_BIGINT:
@@ -622,7 +623,7 @@
 						}
 
 						LENGTHEN_BUF2(24);
-						ast_str_append(&sql2, 0, "%s%lld", first ? "" : ",", integer);
+						ast_str_append(&sql2, 0, "%s%lld", SEP, integer);
 					}
 					break;
 				case SQL_SMALLINT:
@@ -636,7 +637,7 @@
 						}
 
 						LENGTHEN_BUF2(6);
-						ast_str_append(&sql2, 0, "%s%d", first ? "" : ",", integer);
+						ast_str_append(&sql2, 0, "%s%d", SEP, integer);
 					}
 					break;
 				case SQL_TINYINT:
@@ -650,7 +651,7 @@
 						}
 
 						LENGTHEN_BUF2(4);
-						ast_str_append(&sql2, 0, "%s%d", first ? "" : ",", integer);
+						ast_str_append(&sql2, 0, "%s%d", SEP, integer);
 					}
 					break;
 				case SQL_BIT:
@@ -666,7 +667,7 @@
 							integer = 1;
 
 						LENGTHEN_BUF2(2);
-						ast_str_append(&sql2, 0, "%s%d", first ? "" : ",", integer);
+						ast_str_append(&sql2, 0, "%s%d", SEP, integer);
 					}
 					break;
 				case SQL_NUMERIC:
@@ -698,7 +699,7 @@
 						}
 
 						LENGTHEN_BUF2(entry->decimals);
-						ast_str_append(&sql2, 0, "%s%*.*lf", first ? "" : ",", entry->decimals, entry->radix, number);
+						ast_str_append(&sql2, 0, "%s%*.*lf", SEP, entry->decimals, entry->radix, number);
 					}
 					break;
 				case SQL_FLOAT:
@@ -731,7 +732,7 @@
 						}
 
 						LENGTHEN_BUF2(entry->decimals);
-						ast_str_append(&sql2, 0, "%s%lf", first ? "" : ",", number);
+						ast_str_append(&sql2, 0, "%s%lf", SEP, number);
 					}
 					break;
 				default:
@@ -739,11 +740,11 @@
 					continue;
 				}
 				if (quoted) {
-					ast_str_append(&sql, 0, "%s%s", first ? "" : ",", entry->name);
+					ast_str_append(&sql, 0, "%s%s", SEP, 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", SEP, tableptr->quoted_identifiers, entry->name, tableptr->quoted_identifiers);
 				}
-				first = 0;
+				SEP = ", ";
 			} else if (entry->filtervalue
 				&& ((!entry->negatefiltervalue && entry->filtervalue[0] != '\0')
 					|| (entry->negatefiltervalue && entry->filtervalue[0] == '\0'))) {

-- 
To view, visit https://gerrit.asterisk.org/469
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia5a1a161f5e26e1643703b30f8cc9cf0860cc7ea
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