[asterisk-addons-commits] tilghman: trunk r749 - /trunk/cdr/cdr_addon_mysql.c

SVN commits to the Asterisk addons project asterisk-addons-commits at lists.digium.com
Mon Jan 26 17:32:43 CST 2009


Author: tilghman
Date: Mon Jan 26 17:32:42 2009
New Revision: 749

URL: http://svn.digium.com/svn-view/asterisk-addons?view=rev&rev=749
Log:
When fields are missing, the resulting SQL is wrong.
(closes issue #14317)
 Reported by: cheesegrits
 Patches: 
       cdr_mysql.diff uploaded by cheesegrits (license 672)

Modified:
    trunk/cdr/cdr_addon_mysql.c

Modified: trunk/cdr/cdr_addon_mysql.c
URL: http://svn.digium.com/svn-view/asterisk-addons/trunk/cdr/cdr_addon_mysql.c?view=diff&rev=749&r1=748&r2=749
==============================================================================
--- trunk/cdr/cdr_addon_mysql.c (original)
+++ trunk/cdr/cdr_addon_mysql.c Mon Jan 26 17:32:42 2009
@@ -258,10 +258,6 @@
 			}
 
 			/* Construct SQL */
-			if (column_count++) {
-				ast_str_append(&sql1, 0, ",");
-				ast_str_append(&sql2, 0, ",");
-			}
 
 			/* Need the type and value to determine if we want the raw value or not */
 			if (entry->staticvalue) {
@@ -286,16 +282,22 @@
 			if (value) {
 				size_t valsz;
 
+				if (column_count++) {
+					ast_str_append(&sql1, 0, ",");
+					ast_str_append(&sql2, 0, ",");
+				}
+
 				ast_str_make_space(&escape, (valsz = strlen(value)) * 2 + 1);
 				mysql_real_escape_string(&mysql, ast_str_buffer(escape), value, valsz);
+
+				ast_str_append(&sql1, 0, "%s", entry->name);
 				ast_str_append(&sql2, 0, "'%s'", ast_str_buffer(escape));
-				ast_str_append(&sql1, 0, "%s", entry->name);
 			}
 		}
 		AST_RWLIST_UNLOCK(&columns);
 
 		ast_debug(1, "Inserting a CDR record.\n");
-		ast_str_append(&sql1, 0, "%s')", ast_str_buffer(sql2));
+		ast_str_append(&sql1, 0, "%s)", ast_str_buffer(sql2));
 
 		ast_debug(1, "SQL command as follows: %s\n", ast_str_buffer(sql1));
 
@@ -366,7 +368,7 @@
 	AST_LIST_LOCK(&unload_strings);
 	AST_LIST_INSERT_HEAD(&unload_strings, us, entry);
 	AST_LIST_UNLOCK(&unload_strings);
-	
+
 	tmp = ast_variable_retrieve(cfg, category, variable);
 
 	ast_str_set(field, 0, "%s", tmp ? tmp : def);




More information about the asterisk-addons-commits mailing list