Skip to content

Commit

Permalink
Improve error reporting on DBI large number test failures.
Browse files Browse the repository at this point in the history
There are other reasons than the original bug that can cause failure,
get some more information to understand what's going on.
  • Loading branch information
jralls committed Jul 10, 2023
1 parent c8e3dbe commit f2d9230
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions libgnucash/backend/dbi/gnc-backend-dbi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ error_handler<DbType::DBI_MYSQL> (dbi_conn conn, void* user_data)
if (!dbi_be->connected())
{
PINFO ("DBI error: %s\n", msg);
PINFO ("Note: GbcDbiSqlConnection not yet initialized. Skipping further error processing.");
PINFO ("Note: GncDbiSqlConnection not yet initialized. Skipping further error processing.");
return;
}

Expand Down Expand Up @@ -1205,6 +1205,21 @@ gnc_module_finalize_backend_dbi (void)

/* --------------------------------------------------------- */

static void
log_failed_field(dbi_result result, const char* fieldname)
{
auto idx = dbi_result_get_field_idx(result, fieldname);
if (dbi_result_field_is_null_idx(result, idx))
PERR("Result field %s is NULL", fieldname);
else
{
auto type = dbi_result_get_field_type_idx(result, idx);
auto attribs = dbi_result_get_field_attribs_idx(result, idx);
PERR("Result field %s has type %d and attribs %d",
fieldname, type, attribs);
}
}

/** Users discovered a bug in some distributions of libdbi, where if
* it is compiled on certain versions of gcc with the -ffast-math
* compiler option it fails to correctly handle saving of 64-bit
Expand Down Expand Up @@ -1246,7 +1261,7 @@ dbi_library_test (dbi_conn conn)
dbi_result_free (result);
auto locale = gnc_push_locale (LC_NUMERIC, "C");
result = dbi_conn_query (conn, "SELECT * FROM numtest");
if (result == nullptr)
if (result == nullptr || !dbi_result_get_numrows(result))
{
const char* errmsg;
dbi_conn_error (conn, &errmsg);
Expand All @@ -1259,8 +1274,14 @@ dbi_library_test (dbi_conn conn)
while (dbi_result_next_row (result))
{
resultlonglong = dbi_result_get_longlong (result, "test_int");
if (!resultlonglong)
log_failed_field(result, "test_int");
resultulonglong = dbi_result_get_ulonglong (result, "test_unsigned");
if (!resultulonglong)
log_failed_field(result, "test_unsigned");
resultdouble = dbi_result_get_double (result, "test_double");
if (!resultdouble)
log_failed_field(result, "test_double");
}
dbi_conn_query (conn, "DROP TABLE numtest");
gnc_pop_locale (LC_NUMERIC, locale);
Expand Down

0 comments on commit f2d9230

Please sign in to comment.