gnucash maint: Bug 795276 - Invalid date on price stops file from being parsed.

John Ralls jralls at code.gnucash.org
Tue Jun 12 17:56:36 EDT 2018


Updated	 via  https://github.com/Gnucash/gnucash/commit/c8861d46 (commit)
	from  https://github.com/Gnucash/gnucash/commit/91795052 (commit)



commit c8861d4666ff884812d2be1c786bde621e970b16
Author: John Ralls <jralls at ceridwen.us>
Date:   Tue Jun 12 14:53:27 2018 -0700

    Bug 795276 - Invalid date on price stops file from being parsed.
    
    Instead of reporting an error and declining to load the file (XML)
    or failing to enter a value (SQL) when a bad date is found in the
    database, use a 0 time stamp (1970-01-01 00:00:00 UTC). Adds a warning
    in SQL backends; there was one already in XML.

diff --git a/libgnucash/backend/sql/gnc-sql-column-table-entry.cpp b/libgnucash/backend/sql/gnc-sql-column-table-entry.cpp
index cba8d17..63a4f7a 100644
--- a/libgnucash/backend/sql/gnc-sql-column-table-entry.cpp
+++ b/libgnucash/backend/sql/gnc-sql-column-table-entry.cpp
@@ -401,7 +401,9 @@ GncSqlColumnTableEntryImpl<CT_TIMESPEC>::load (const GncSqlBackend* sql_be,
         }
         catch (std::invalid_argument&)
         {
-            return;
+            PWARN("An invalid date was found in your database."
+                  "It has been set to 1 January 1970.");
+            ts.tv_sec = 0;
         }
     }
     set_parameter(pObject, &ts,
diff --git a/libgnucash/backend/xml/gnc-entry-xml-v2.cpp b/libgnucash/backend/xml/gnc-entry-xml-v2.cpp
index f87be3f..a25fb56 100644
--- a/libgnucash/backend/xml/gnc-entry-xml-v2.cpp
+++ b/libgnucash/backend/xml/gnc-entry-xml-v2.cpp
@@ -244,7 +244,7 @@ set_time64 (xmlNodePtr node, GncEntry* entry,
               void (*func) (GncEntry* entry, time64 ts))
 {
     time64 time = dom_tree_to_time64 (node);
-    if (!dom_tree_valid_time64 (time, node->name)) return FALSE;
+    if (!dom_tree_valid_time64 (time, node->name)) time = 0;
     func (entry, time);
     return TRUE;
 }
diff --git a/libgnucash/backend/xml/gnc-invoice-xml-v2.cpp b/libgnucash/backend/xml/gnc-invoice-xml-v2.cpp
index 1d3aef2..b2f45f5 100644
--- a/libgnucash/backend/xml/gnc-invoice-xml-v2.cpp
+++ b/libgnucash/backend/xml/gnc-invoice-xml-v2.cpp
@@ -188,7 +188,7 @@ set_time64 (xmlNodePtr node, GncInvoice* invoice,
               void (*func) (GncInvoice* invoice, time64 time))
 {
     time64 time = dom_tree_to_time64 (node);
-    if (!dom_tree_valid_time64 (time, node->name)) return FALSE;
+    if (!dom_tree_valid_time64 (time, node->name)) time = 0;
     func (invoice, time);
     return TRUE;
 }
diff --git a/libgnucash/backend/xml/gnc-order-xml-v2.cpp b/libgnucash/backend/xml/gnc-order-xml-v2.cpp
index bb27192..a101d15 100644
--- a/libgnucash/backend/xml/gnc-order-xml-v2.cpp
+++ b/libgnucash/backend/xml/gnc-order-xml-v2.cpp
@@ -135,7 +135,7 @@ set_time64 (xmlNodePtr node, GncOrder* order,
               void (*func) (GncOrder* order, time64 tt))
 {
     time64 time = dom_tree_to_time64 (node);
-    if (!dom_tree_valid_time64 (time, node->name)) return FALSE;
+    if (!dom_tree_valid_time64 (time, node->name)) time = 0;
     func (order, time);
     return TRUE;
 }
diff --git a/libgnucash/backend/xml/gnc-pricedb-xml-v2.cpp b/libgnucash/backend/xml/gnc-pricedb-xml-v2.cpp
index 6bb7dd2..fbde09a 100644
--- a/libgnucash/backend/xml/gnc-pricedb-xml-v2.cpp
+++ b/libgnucash/backend/xml/gnc-pricedb-xml-v2.cpp
@@ -114,7 +114,7 @@ price_parse_xml_sub_node (GNCPrice* p, xmlNodePtr sub_node, QofBook* book)
     else if (g_strcmp0 ("price:time", (char*)sub_node->name) == 0)
     {
         time64 time = dom_tree_to_time64 (sub_node);
-        if (!dom_tree_valid_time64 (time, sub_node->name)) return FALSE;
+        if (!dom_tree_valid_time64 (time, sub_node->name)) time = 0;
         Timespec ts {time, 0};
         gnc_price_set_time (p, ts);
     }
diff --git a/libgnucash/backend/xml/gnc-transaction-xml-v2.cpp b/libgnucash/backend/xml/gnc-transaction-xml-v2.cpp
index ba19590..6a397f6 100644
--- a/libgnucash/backend/xml/gnc-transaction-xml-v2.cpp
+++ b/libgnucash/backend/xml/gnc-transaction-xml-v2.cpp
@@ -283,7 +283,7 @@ spl_reconcile_date_handler (xmlNodePtr node, gpointer data)
 {
     struct split_pdata* pdata = static_cast<decltype (pdata)> (data);
     time64 time  = dom_tree_to_time64 (node);
-    if (!dom_tree_valid_time64 (time, node->name)) return FALSE;
+    if (!dom_tree_valid_time64 (time, node->name)) time = 0;
     xaccSplitSetDateReconciledSecs (pdata->split, time);
     return TRUE;
 }
@@ -438,7 +438,7 @@ set_tran_time64 (xmlNodePtr node, Transaction * trn,
         void (*func) (Transaction *, time64))
 {
     time64 time = dom_tree_to_time64 (node);
-    if (!dom_tree_valid_time64 (time, node->name)) return FALSE;
+    if (!dom_tree_valid_time64 (time, node->name)) time = 0;
     func (trn, time);
     return TRUE;
 }
@@ -448,7 +448,7 @@ set_tran_date (xmlNodePtr node, Transaction* trn,
                void (*func) (Transaction* trn, const Timespec* tm))
 {
     time64 time = dom_tree_to_time64 (node);
-    if (!dom_tree_valid_time64 (time, node->name)) return FALSE;
+    if (!dom_tree_valid_time64 (time, node->name)) time = 0;
     Timespec ts {time, 0};
     func (trn, &ts);
     return TRUE;
diff --git a/libgnucash/backend/xml/io-gncxml-v1.cpp b/libgnucash/backend/xml/io-gncxml-v1.cpp
index b9153be..c25b5cd 100644
--- a/libgnucash/backend/xml/io-gncxml-v1.cpp
+++ b/libgnucash/backend/xml/io-gncxml-v1.cpp
@@ -2960,7 +2960,7 @@ price_parse_xml_sub_node (GNCPrice* p, xmlNodePtr sub_node, QofBook* book)
     else if (g_strcmp0 ("price:time", (char*)sub_node->name) == 0)
     {
         time64 time = dom_tree_to_time64 (sub_node);
-        if (!dom_tree_valid_time64 (time, sub_node->name)) return FALSE;
+        if (!dom_tree_valid_time64 (time, sub_node->name)) time = 0;
         Timespec ts = {time, 0};
         gnc_price_set_time (p, ts);
     }
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 85fb0c0..426b3f2 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -575,6 +575,7 @@ libgnucash/backend/sql/gnc-sql-result.cpp
 libgnucash/backend/sql/gnc-tax-table-sql.cpp
 libgnucash/backend/sql/gnc-transaction-sql.cpp
 libgnucash/backend/sql/gnc-vendor-sql.cpp
+libgnucash/backend/xml/.#gnc-invoice-xml-v2.cpp
 libgnucash/backend/xml/gnc-account-xml-v2.cpp
 libgnucash/backend/xml/gnc-address-xml-v2.cpp
 libgnucash/backend/xml/gnc-backend-xml.cpp



Summary of changes:
 libgnucash/backend/sql/gnc-sql-column-table-entry.cpp | 4 +++-
 libgnucash/backend/xml/gnc-entry-xml-v2.cpp           | 2 +-
 libgnucash/backend/xml/gnc-invoice-xml-v2.cpp         | 2 +-
 libgnucash/backend/xml/gnc-order-xml-v2.cpp           | 2 +-
 libgnucash/backend/xml/gnc-pricedb-xml-v2.cpp         | 2 +-
 libgnucash/backend/xml/gnc-transaction-xml-v2.cpp     | 6 +++---
 libgnucash/backend/xml/io-gncxml-v1.cpp               | 2 +-
 po/POTFILES.in                                        | 1 +
 8 files changed, 12 insertions(+), 9 deletions(-)



More information about the gnucash-changes mailing list