<p>Alexei Gradinari has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/10226">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_odbc: fix missing SQL error diagnostic<br><br>On SQL error there is not diagnostic information about this error.<br>There is only<br>WARNING res_odbc.c: SQL Execute error -1!<br><br>The function ast_odbc_print_errors calls a SQLGetDiagField to get the number<br>of available diagnostic records, but the SQLGetDiagField returns 0.<br>However SQLGetDiagRec could return one diagnostic records in this case.<br><br>Looking at many example of getting diagnostics error information<br>I found out that the best way it's to use only SQLGetDiagRec<br>while it returns SQL_SUCCESS.<br><br>ASTERISK-28065 #close<br><br>Change-Id: Iba5ae5470ac49ecd911dd084effbe9efac68ccc1<br>---<br>M res/res_odbc.c<br>1 file changed, 4 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/26/10226/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/res/res_odbc.c b/res/res_odbc.c</span><br><span>index 36e4829..9622beb 100644</span><br><span>--- a/res/res_odbc.c</span><br><span>+++ b/res/res_odbc.c</span><br><span>@@ -443,23 +443,20 @@</span><br><span> {</span><br><span>    struct ast_str *errors = ast_str_thread_get(&errors_buf, 16);</span><br><span>    SQLINTEGER nativeerror = 0;</span><br><span style="color: hsl(0, 100%, 40%);">-     SQLINTEGER numfields = 0;</span><br><span>    SQLSMALLINT diagbytes = 0;</span><br><span>   SQLSMALLINT i;</span><br><span>       unsigned char state[10];</span><br><span>     unsigned char diagnostic[256];</span><br><span> </span><br><span>   ast_str_reset(errors);</span><br><span style="color: hsl(0, 100%, 40%);">-  SQLGetDiagField(handle_type, handle, 1, SQL_DIAG_NUMBER, &numfields,</span><br><span style="color: hsl(0, 100%, 40%);">-                        SQL_IS_INTEGER, &diagbytes);</span><br><span style="color: hsl(0, 100%, 40%);">-        for (i = 0; i < numfields; i++) {</span><br><span style="color: hsl(0, 100%, 40%);">-            SQLGetDiagRec(handle_type, handle, i + 1, state, &nativeerror,</span><br><span style="color: hsl(0, 100%, 40%);">-                              diagnostic, sizeof(diagnostic), &diagbytes);</span><br><span style="color: hsl(120, 100%, 40%);">+      i = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+        while (SQLGetDiagRec(handle_type, handle, ++i, state, &nativeerror,</span><br><span style="color: hsl(120, 100%, 40%);">+               diagnostic, sizeof(diagnostic), &diagbytes) == SQL_SUCCESS) {</span><br><span>            ast_str_append(&errors, 0, "%s%s", ast_str_strlen(errors) ? "," : "", state);</span><br><span>              ast_log(LOG_WARNING, "%s returned an error: %s: %s\n", operation, state, diagnostic);</span><br><span>              /* XXX Why is this here? */</span><br><span>          if (i > 10) {</span><br><span style="color: hsl(0, 100%, 40%);">-                        ast_log(LOG_WARNING, "Oh, that was good.  There are really %d diagnostics?\n", (int)numfields);</span><br><span style="color: hsl(120, 100%, 40%);">+                     ast_log(LOG_WARNING, "There are more than 10 diagnostic records! Ignore the rest.\n");</span><br><span>                     break;</span><br><span>               }</span><br><span>    }</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/10226">change 10226</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/10226"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 13 </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: Iba5ae5470ac49ecd911dd084effbe9efac68ccc1 </div>
<div style="display:none"> Gerrit-Change-Number: 10226 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Alexei Gradinari <alex2grad@gmail.com> </div>