<p>Kevin Harwell <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/10285">View Change</a></p><div style="white-space:pre-wrap">Approvals:
George Joseph: Looks good to me, but someone else must approve
Joshua Colp: Looks good to me, but someone else must approve
Kevin Harwell: Looks good to me, approved; Approved for Submit
</div><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>Also this patch adds calls of ast_odbc_print_errors on SQL_ERROR<br>to res_config_odbc.<br><br>ASTERISK-28065 #close<br><br>Change-Id: Iba5ae5470ac49ecd911dd084effbe9efac68ccc1<br>---<br>M res/res_config_odbc.c<br>M res/res_odbc.c<br>2 files changed, 10 insertions(+), 7 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/res/res_config_odbc.c b/res/res_config_odbc.c</span><br><span>index be920d6..6eea305 100644</span><br><span>--- a/res/res_config_odbc.c</span><br><span>+++ b/res/res_config_odbc.c</span><br><span>@@ -116,6 +116,9 @@</span><br><span> </span><br><span> res = SQLPrepare(stmt, (unsigned char *)cps->sql, SQL_NTS);</span><br><span> if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (res == SQL_ERROR) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_odbc_print_errors(SQL_HANDLE_STMT, stmt, "SQL Prepare");</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> ast_log(LOG_WARNING, "SQL Prepare failed! [%s]\n", cps->sql);</span><br><span> SQLFreeHandle (SQL_HANDLE_STMT, stmt);</span><br><span> return NULL;</span><br><span>@@ -631,6 +634,9 @@</span><br><span> </span><br><span> res = SQLPrepare(stmt, (unsigned char *)ast_str_buffer(sql), SQL_NTS);</span><br><span> if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (res == SQL_ERROR) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_odbc_print_errors(SQL_HANDLE_STMT, stmt, "SQL Prepare");</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> ast_log(LOG_WARNING, "SQL Prepare failed! [%s]\n", ast_str_buffer(sql));</span><br><span> SQLFreeHandle(SQL_HANDLE_STMT, stmt);</span><br><span> return NULL;</span><br><span>diff --git a/res/res_odbc.c b/res/res_odbc.c</span><br><span>index b4c1585..1c82e3f 100644</span><br><span>--- a/res/res_odbc.c</span><br><span>+++ b/res/res_odbc.c</span><br><span>@@ -431,23 +431,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/10285">change 10285</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/10285"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: Iba5ae5470ac49ecd911dd084effbe9efac68ccc1 </div>
<div style="display:none"> Gerrit-Change-Number: 10285 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Alexei Gradinari <alex2grad@gmail.com> </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins2 (1000185) </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Kevin Harwell <kharwell@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Sean Bright <sean.bright@gmail.com> </div>