gnucash stable: Improve error reporting on DBI large number test failures.

John Ralls jralls at code.gnucash.org
Mon Jul 10 16:26:03 EDT 2023


Updated	 via  https://github.com/Gnucash/gnucash/commit/f2d92302 (commit)
	from  https://github.com/Gnucash/gnucash/commit/c8e3dbe2 (commit)



commit f2d92302997727cffd37efb6500789d15bc2c630
Author: John Ralls <jralls at ceridwen.us>
Date:   Mon Jul 10 13:23:31 2023 -0700

    Improve error reporting on DBI large number test failures.
    
    There are other reasons than the original bug that can cause failure,
    get some more information to understand what's going on.

diff --git a/libgnucash/backend/dbi/gnc-backend-dbi.cpp b/libgnucash/backend/dbi/gnc-backend-dbi.cpp
index f15aa0567c..1235ad1b9f 100644
--- a/libgnucash/backend/dbi/gnc-backend-dbi.cpp
+++ b/libgnucash/backend/dbi/gnc-backend-dbi.cpp
@@ -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;
     }
 
@@ -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
@@ -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);
@@ -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);



Summary of changes:
 libgnucash/backend/dbi/gnc-backend-dbi.cpp | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)



More information about the gnucash-changes mailing list