<p>Dennis has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/14700">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">cdr_mysql: Clear column list before scanning table<br><br>When Asterisk re-connects to MySQL, table column names are<br>appended to the existing column list. This results in execution<br>errors due to duplicate column names listed in the INSERT query.<br><br>This change also fixes two warnings:<br><br>When MYSQL_VERSION_ID < 50013, "my_bool_true" becomes<br>unused and compiler will complain about it.<br><br>"entry" in my_unload_module is always unused.<br><br>ASTERISK-29007 #close<br><br>Change-Id: I899aa94ff34f48d8c7d73bc7f707dcd6f6a4ee36<br>---<br>M addons/cdr_mysql.c<br>1 file changed, 14 insertions(+), 7 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/00/14700/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/addons/cdr_mysql.c b/addons/cdr_mysql.c</span><br><span>index c05b86a..723f74d 100644</span><br><span>--- a/addons/cdr_mysql.c</span><br><span>+++ b/addons/cdr_mysql.c</span><br><span>@@ -108,6 +108,14 @@</span><br><span> </span><br><span> static MYSQL mysql = { { NULL }, };</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+static void my_clear_columns(void)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ struct column *entry;</span><br><span style="color: hsl(120, 100%, 40%);">+ while ((entry = AST_RWLIST_REMOVE_HEAD(&columns, list))) {</span><br><span style="color: hsl(120, 100%, 40%);">+                ast_free(entry);</span><br><span style="color: hsl(120, 100%, 40%);">+      }</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> static char *handle_cli_cdr_mysql_status(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)</span><br><span> {</span><br><span>    switch (cmd) {</span><br><span>@@ -173,12 +181,13 @@</span><br><span> {</span><br><span>  struct ast_str *sql1 = ast_str_thread_get(&sql1_buf, 1024), *sql2 = ast_str_thread_get(&sql2_buf, 1024);</span><br><span>     int retries = 5;</span><br><span style="color: hsl(120, 100%, 40%);">+#if MYSQL_VERSION_ID >= 50013</span><br><span> #ifdef HAVE_MYSQLCLIENT_BOOL</span><br><span>   bool my_bool_true = 1;</span><br><span> #elif HAVE_MYSQLCLIENT_MY_BOOL</span><br><span>     my_bool my_bool_true = 1;</span><br><span style="color: hsl(0, 100%, 40%);">-#endif</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(120, 100%, 40%);">+#endif /* HAVE_MYSQLCLIENT_MY_BOOL */</span><br><span style="color: hsl(120, 100%, 40%);">+#endif /* MYSQL_VERSION_ID */</span><br><span>        if (!sql1 || !sql2) {</span><br><span>                ast_log(LOG_ERROR, "Memory error\n");</span><br><span>              return -1;</span><br><span>@@ -382,8 +391,6 @@</span><br><span> </span><br><span> static int my_unload_module(int reload)</span><br><span> {</span><br><span style="color: hsl(0, 100%, 40%);">-    struct column *entry;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span>        if (!reload) {</span><br><span>               if (ast_cdr_unregister(name)) {</span><br><span>                      /* If we can't unregister the backend, we can't unload the module */</span><br><span>@@ -404,9 +411,7 @@</span><br><span>   if (!reload) {</span><br><span>               AST_RWLIST_WRLOCK(&columns);</span><br><span>     }</span><br><span style="color: hsl(0, 100%, 40%);">-       while ((entry = AST_RWLIST_REMOVE_HEAD(&columns, list))) {</span><br><span style="color: hsl(0, 100%, 40%);">-          ast_free(entry);</span><br><span style="color: hsl(0, 100%, 40%);">-        }</span><br><span style="color: hsl(120, 100%, 40%);">+     my_clear_columns();</span><br><span>  if (!reload) {</span><br><span>               AST_RWLIST_UNLOCK(&columns);</span><br><span>     }</span><br><span>@@ -531,6 +536,8 @@</span><br><span>              return AST_MODULE_LOAD_DECLINE;</span><br><span>      }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ my_clear_columns();</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>        while ((row = mysql_fetch_row(result))) {</span><br><span>            struct column *entry;</span><br><span>                char *cdrvar = "", *staticvalue = "";</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/14700">change 14700</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/14700"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 18 </div>
<div style="display:none"> Gerrit-Change-Id: I899aa94ff34f48d8c7d73bc7f707dcd6f6a4ee36 </div>
<div style="display:none"> Gerrit-Change-Number: 14700 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Dennis <dennis.buteyn@xorcom.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>