[geary/mjog/921-db-locked] Geary.Db.DatabaseConnection: Add SQL debug logging when txns fail




commit e4d3abd97f9db6226d4c996ff6af9c23eb34f7f3
Author: Michael Gratton <mike vee net>
Date:   Fri Sep 4 00:39:30 2020 +1000

    Geary.Db.DatabaseConnection: Add SQL debug logging when txns fail
    
    This isn't a good place to do it, but neither GLib's error model not the
    engine's database model makes it possible to getting access to
    transaction state otherwise at the moment.

 src/engine/db/db-database-connection.vala | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)
---
diff --git a/src/engine/db/db-database-connection.vala b/src/engine/db/db-database-connection.vala
index 1e5dc41a8..5ff234bf3 100644
--- a/src/engine/db/db-database-connection.vala
+++ b/src/engine/db/db-database-connection.vala
@@ -191,8 +191,16 @@ public class Geary.Db.DatabaseConnection : Context, Connection, Logging.Source {
             // perform the transaction
             outcome = cb(txn_cx, cancellable);
         } catch (GLib.Error err) {
-            if (!(err is GLib.IOError.CANCELLED))
+            if (!(err is GLib.IOError.CANCELLED)) {
                 debug("Connection.exec_transaction: transaction threw error: %s", err.message);
+                // XXX txn logs really should be passed up with the
+                // error, or made available after the transaction, but
+                // neither GLib's error model nor Db's model allows
+                // that
+                foreach (var statement in txn_cx.transaction_log) {
+                    debug(" - %s", statement);
+                }
+            }
 
             caught_err = err;
         }
@@ -205,6 +213,15 @@ public class Geary.Db.DatabaseConnection : Context, Connection, Logging.Source {
         } catch (GLib.Error err) {
             debug("Connection.exec_transaction: Unable to %s transaction: %s", outcome.to_string(),
                 err.message);
+            if (caught_error == null) {
+                // XXX as per above, txn logs really should be passed up
+                // with the error, or made available after the
+                // transaction, but neither GLib's error model nor Db's
+                // model allows that
+                foreach (var statement in txn_cx.transaction_log) {
+                    debug(" - %s", statement);
+                }
+            }
         }
 
         if (caught_err != null) {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]