gnucash maint: Fix a couple of warnings introduced by commit 01420adb9989f49a

Geert Janssens gjanssens at code.gnucash.org
Tue Apr 17 13:45:47 EDT 2018


Updated	 via  https://github.com/Gnucash/gnucash/commit/80dbb994 (commit)
	from  https://github.com/Gnucash/gnucash/commit/87f94abc (commit)



commit 80dbb9940b77df40fc1854d0593ecf5f716597c9
Author: Geert Janssens <geert at kobaltwit.be>
Date:   Tue Apr 17 19:45:39 2018 +0200

    Fix a couple of warnings introduced by commit 01420adb9989f49a
    
    In addition make the code really use an inner join if no additional conditions are set
    which gives better performance on at least postgresql

diff --git a/libgnucash/backend/sql/gnc-transaction-sql.cpp b/libgnucash/backend/sql/gnc-transaction-sql.cpp
index ca8cb97..9457a73 100644
--- a/libgnucash/backend/sql/gnc-transaction-sql.cpp
+++ b/libgnucash/backend/sql/gnc-transaction-sql.cpp
@@ -260,7 +260,7 @@ load_splits_for_transactions (GncSqlBackend* sql_be, std::string selector)
     if (selector.empty())
     {
 	sql += SPLIT_TABLE ".* FROM " SPLIT_TABLE " INNER JOIN "
-	    TRANSACTION_TABLE " WHERE " SPLIT_TABLE "." + sskey + " = "
+	    TRANSACTION_TABLE " ON " SPLIT_TABLE "." + sskey + " = "
 	    TRANSACTION_TABLE "." + tpkey;
 	selector = "(SELECT DISTINCT " + tpkey + " FROM " TRANSACTION_TABLE ")";
     }
@@ -378,12 +378,20 @@ query_transactions (GncSqlBackend* sql_be, std::string selector)
     if (!instances.empty())
     {
 	const std::string tpkey(tx_col_table[0]->name());
-	if (selector.empty())
-	{
-	    selector = "(SELECT DISTINCT ";
-	    selector += tpkey + " FROM " TRANSACTION_TABLE +")";
-	}
+        if (!selector.empty() && (selector[0] != '('))
+        {
+            auto tselector = std::string ("(SELECT DISTINCT ");
+            tselector += tpkey + " FROM " TRANSACTION_TABLE " WHERE " + selector + ")";
+            selector = tselector;
+        }
+
         load_splits_for_transactions (sql_be, selector);
+
+        if (selector.empty())
+        {
+            selector = "(SELECT DISTINCT ";
+            selector += tpkey + " FROM " TRANSACTION_TABLE ")";
+        }
         gnc_sql_slots_load_for_sql_subquery (sql_be, selector,
 					     (BookLookupFn)xaccTransLookup);
     }



Summary of changes:
 libgnucash/backend/sql/gnc-transaction-sql.cpp | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)



More information about the gnucash-changes mailing list