gnucash unstable: Multiple changes pushed
John Ralls
jralls at code.gnucash.org
Fri Mar 16 19:52:23 EDT 2018
Updated via https://github.com/Gnucash/gnucash/commit/8fe2cb6f (commit)
via https://github.com/Gnucash/gnucash/commit/e5561bd7 (commit)
via https://github.com/Gnucash/gnucash/commit/74d94650 (commit)
from https://github.com/Gnucash/gnucash/commit/9b890124 (commit)
commit 8fe2cb6fa885c821afebaaaa51475bf72ed83151
Author: John Ralls <jralls at ceridwen.us>
Date: Fri Mar 16 16:47:11 2018 -0700
Fix date corruption in SQL load.
Four date elements were affected: GncEntry::date, GncEntry::date_entered,
GncInvoice::opened, and GncInvoice::posted. The problem arose during the
cleansing of Timespec from the reports; the setter functions for those
elements were converted to time64 but no provision was made to the SQL
backend to pass them time64 instead of Timespec*.
This commit adds a new column type, CT_TIME64, and changes the column
types for those elements to CT_TIME64.
diff --git a/libgnucash/backend/sql/gnc-entry-sql.cpp b/libgnucash/backend/sql/gnc-entry-sql.cpp
index 9beb95b..764ffa4 100644
--- a/libgnucash/backend/sql/gnc-entry-sql.cpp
+++ b/libgnucash/backend/sql/gnc-entry-sql.cpp
@@ -70,9 +70,9 @@ static void entry_set_bill (gpointer pObject, gpointer val);
static EntryVec col_table
({
gnc_sql_make_table_entry<CT_GUID>("guid", 0, COL_NNUL | COL_PKEY, "guid"),
- gnc_sql_make_table_entry<CT_TIMESPEC>("date", 0, COL_NNUL, ENTRY_DATE,
+ gnc_sql_make_table_entry<CT_TIME64>("date", 0, COL_NNUL, ENTRY_DATE,
true),
- gnc_sql_make_table_entry<CT_TIMESPEC>("date_entered", 0, 0,
+ gnc_sql_make_table_entry<CT_TIME64>("date_entered", 0, 0,
ENTRY_DATE_ENTERED, true),
gnc_sql_make_table_entry<CT_STRING>(
"description", MAX_DESCRIPTION_LEN, 0, "description"),
diff --git a/libgnucash/backend/sql/gnc-invoice-sql.cpp b/libgnucash/backend/sql/gnc-invoice-sql.cpp
index 769aa2d..e0cc87a 100644
--- a/libgnucash/backend/sql/gnc-invoice-sql.cpp
+++ b/libgnucash/backend/sql/gnc-invoice-sql.cpp
@@ -67,9 +67,9 @@ static EntryVec col_table
gnc_sql_make_table_entry<CT_GUID>("guid", 0, COL_NNUL | COL_PKEY, "guid"),
gnc_sql_make_table_entry<CT_STRING>("id", MAX_ID_LEN, COL_NNUL, INVOICE_ID,
true),
- gnc_sql_make_table_entry<CT_TIMESPEC>("date_opened", 0, 0, INVOICE_OPENED,
+ gnc_sql_make_table_entry<CT_TIME64>("date_opened", 0, 0, INVOICE_OPENED,
true),
- gnc_sql_make_table_entry<CT_TIMESPEC>("date_posted", 0, 0, INVOICE_POSTED,
+ gnc_sql_make_table_entry<CT_TIME64>("date_posted", 0, 0, INVOICE_POSTED,
true),
gnc_sql_make_table_entry<CT_STRING>("notes", MAX_NOTES_LEN, COL_NNUL,
"notes"),
diff --git a/libgnucash/backend/sql/gnc-sql-column-table-entry.cpp b/libgnucash/backend/sql/gnc-sql-column-table-entry.cpp
index 6080679..09d6f3a 100644
--- a/libgnucash/backend/sql/gnc-sql-column-table-entry.cpp
+++ b/libgnucash/backend/sql/gnc-sql-column-table-entry.cpp
@@ -454,6 +454,67 @@ GncSqlColumnTableEntryImpl<CT_TIMESPEC>::add_to_query(QofIdTypeConst obj_name,
"NULL"));
}
}
+/* ----------------------------------------------------------------- */
+typedef time64 (*Time64AccessFunc) (const gpointer);
+typedef void (*Time64SetterFunc) (const gpointer, time64);
+
+template<> void
+GncSqlColumnTableEntryImpl<CT_TIME64>::load (const GncSqlBackend* sql_be,
+ GncSqlRow& row,
+ QofIdTypeConst obj_name,
+ gpointer pObject)
+ const noexcept
+{
+ time64 t;
+ g_return_if_fail (m_gobj_param_name != nullptr || get_setter(obj_name) != nullptr);
+ try
+ {
+ t = row.get_time64_at_col (m_col_name);
+ }
+ catch (std::invalid_argument)
+ {
+ try
+ {
+ auto val = row.get_string_at_col(m_col_name);
+ GncDateTime time(val);
+ t = static_cast<time64>(time);
+ }
+ catch (std::invalid_argument)
+ {
+ return;
+ }
+ }
+ set_parameter(pObject, t,
+ reinterpret_cast<Time64SetterFunc>(get_setter(obj_name)),
+ m_gobj_param_name);
+}
+
+template<> void
+GncSqlColumnTableEntryImpl<CT_TIME64>::add_to_table(ColVec& vec) const noexcept
+{
+
+ GncSqlColumnInfo info{*this, BCT_DATETIME, TIMESPEC_COL_SIZE, FALSE};
+ vec.emplace_back(std::move(info));
+}
+
+template<> void
+GncSqlColumnTableEntryImpl<CT_TIME64>::add_to_query(QofIdTypeConst obj_name,
+ const gpointer pObject,
+ PairVec& vec) const noexcept
+{
+ auto t = get_row_value_from_object<time64>(obj_name, pObject);
+ if (t > MINTIME && t < MAXTIME)
+ {
+ GncDateTime time(t);
+ vec.emplace_back (std::make_pair (std::string{m_col_name},
+ time.format_zulu ("'%Y-%m-%d %H:%M:%S'")));
+ }
+ else
+ {
+ vec.emplace_back (std::make_pair (std::string{m_col_name},
+ "NULL"));
+ }
+}
/* ----------------------------------------------------------------- */
#define DATE_COL_SIZE 8
diff --git a/libgnucash/backend/sql/gnc-sql-column-table-entry.hpp b/libgnucash/backend/sql/gnc-sql-column-table-entry.hpp
index 28fbb64..a98801a 100644
--- a/libgnucash/backend/sql/gnc-sql-column-table-entry.hpp
+++ b/libgnucash/backend/sql/gnc-sql-column-table-entry.hpp
@@ -70,6 +70,7 @@ enum GncSqlObjectType
CT_INT,
CT_INT64,
CT_TIMESPEC,
+ CT_TIME64,
CT_GDATE,
CT_NUMERIC,
CT_DOUBLE,
commit e5561bd7abe0da25f2bebd639779b868cbd6d351
Author: John Ralls <jralls at ceridwen.us>
Date: Fri Mar 16 13:59:04 2018 -0700
Fix lost Bayesian matches in SQL backend.
The import-map-bayes uses a three-part key that uses the same delimiter
as a path and the SQL backend was throwing away everything except the
account guid.
Added more slot types including import-map-bayes ones to the test xml
file to help debug this and to catch it in the future.
Also don't pass std::string.c_str() to a std::vector<std::string>
constructor, just pass the string.
diff --git a/libgnucash/backend/dbi/test/test-dbi.xml b/libgnucash/backend/dbi/test/test-dbi.xml
index 5ea03f5..88c9519 100644
--- a/libgnucash/backend/dbi/test/test-dbi.xml
+++ b/libgnucash/backend/dbi/test/test-dbi.xml
@@ -104,6 +104,65 @@
</act:commodity>
<act:commodity-scu>100</act:commodity-scu>
<act:description>Checking Account</act:description>
+ <act:slots>
+ <slot>
+ <slot:key>hbci</slot:key>
+ <slot:value type="frame">
+ <slot>
+ <slot:key>account-id</slot:key>
+ <slot:value type="string">998877665544</slot:value>
+ </slot>
+ <slot>
+ <slot:key>account-uid</slot:key>
+ <slot:value type="integer">4</slot:value>
+ </slot>
+ <slot>
+ <slot:key>bank-code</slot:key>
+ <slot:value type="string">123456789</slot:value>
+ </slot>
+ <slot>
+ <slot:key>trans-retrieval</slot:key>
+ <slot:value type="timespec">
+ <ts:date>2014-07-29 13:53:22 -0700</ts:date>
+ </slot:value>
+ </slot>
+ </slot:value>
+ </slot>
+ <slot>
+ <slot:key>import-map-bayes/JOE'S/2fb5eba53d140bc237d8bae2fca3ddee</slot:key>
+ <slot:value type="integer">2</slot:value>
+ </slot>
+ <slot>
+ <slot:key>import-map-bayes/KAISER/2fb5eba53d140bc237d8bae2fca3ddee</slot:key>
+ <slot:value type="integer">4</slot:value>
+ </slot>
+ <slot>
+ <slot:key>reconcile-info</slot:key>
+ <slot:value type="frame">
+ <slot>
+ <slot:key>include-children</slot:key>
+ <slot:value type="integer">0</slot:value>
+ </slot>
+ <slot>
+ <slot:key>last-date</slot:key>
+ <slot:value type="integer">1412924399</slot:value>
+ </slot>
+ <slot>
+ <slot:key>last-interval</slot:key>
+ <slot:value type="frame">
+ <slot>
+ <slot:key>days</slot:key>
+ <slot:value type="integer">26</slot:value>
+ </slot>
+ <slot>
+ <slot:key>months</slot:key>
+ <slot:value type="integer">0</slot:value>
+ </slot>
+ </slot:value>
+ </slot>
+ </slot:value>
+ </slot>
+ </act:slots>
<act:parent type="guid">b9e822465cc7e808797aaa51fd6f8d23</act:parent>
</gnc:account>
<gnc:account version="2.0.0">
@@ -233,6 +292,37 @@
<act:parent type="guid">aa435e75fdee71adc1c51e53ea390638</act:parent>
</gnc:account>
<gnc:account version="2.0.0">
+ <act:name>Liabilities</act:name>
+ <act:id type="guid">334baa3103961830eeccf42fe5a0d5de</act:id>
+ <act:type>LIABILITY</act:type>
+ <act:commodity>
+ <cmdty:space>ISO4217</cmdty:space>
+ <cmdty:id>CAD</cmdty:id>
+ </act:commodity>
+ <act:commodity-scu>100</act:commodity-scu>
+ <act:description>Liabilities</act:description>
+ <act:slots>
+ <slot>
+ <slot:key>placeholder</slot:key>
+ <slot:value type="string">true</slot:value>
+ </slot>
+ </act:slots>
+ <act:parent type="guid">aa435e75fdee71adc1c51e53ea390638</act:parent>
+</gnc:account>
+<gnc:account version="2.0.0">
+ <act:name>CapOne</act:name>
+ <act:id type="guid">fece54740af23814b1ba6f89fb64307d</act:id>
+ <act:type>CREDIT</act:type>
+ <act:commodity>
+ <cmdty:space>ISO4217</cmdty:space>
+ <cmdty:id>CAD</cmdty:id>
+ </act:commodity>
+ <act:commodity-scu>100</act:commodity-scu>
+ <act:code>1801</act:code>
+ <act:description>Capital One Visa</act:description>
+ <act:parent type="guid">334baa3103961830eeccf42fe5a0d5de</act:parent>
+</gnc:account>
+<gnc:account version="2.0.0">
<act:name>Equity</act:name>
<act:id type="guid">0886d667a89c69aa33a1f99ff68e1348</act:id>
<act:type>EQUITY</act:type>
@@ -613,6 +703,77 @@
</gnc:recurrence>
</sx:schedule>
</gnc:schedxaction>
+<gnc:GncEntry version="2.0.0">
+ <entry:guid type="guid">86fa5bb1ff0fa546674458823e5920bf</entry:guid>
+ <entry:date>
+ <ts:date>2010-12-07 00:00:00 -0800</ts:date>
+ </entry:date>
+ <entry:entered>
+ <ts:date>2010-12-07 17:10:43 -0800</ts:date>
+ </entry:entered>
+ <entry:bill type="guid">2c2889c46f3d813ede18cd1a642c48b0</entry:bill>
+ <entry:billable>0</entry:billable>
+ <entry:b-taxable>1</entry:b-taxable>
+ <entry:b-taxincluded>0</entry:b-taxincluded>
+ <entry:b-pay>CASH</entry:b-pay>
+</gnc:GncEntry>
+<gnc:GncInvoice version="2.0.0">
+ <invoice:guid type="guid">2c2889c46f3d813ede18cd1a642c48b0</invoice:guid>
+ <invoice:id>1</invoice:id>
+ <invoice:owner version="2.0.0">
+ <owner:type>gncJob</owner:type>
+ <owner:id type="guid">bf58b11a019e7fdb5860af876ed0a870</owner:id>
+ </invoice:owner>
+ <invoice:opened>
+ <ts:date>2010-12-07 00:00:00 -0800</ts:date>
+ </invoice:opened>
+ <invoice:active>1</invoice:active>
+ <invoice:currency>
+ <cmdty:space>ISO4217</cmdty:space>
+ <cmdty:id>USD</cmdty:id>
+ </invoice:currency>
+</gnc:GncInvoice>
+<gnc:GncJob version="2.0.0">
+ <job:guid type="guid">bf58b11a019e7fdb5860af876ed0a870</job:guid>
+ <job:id>1</job:id>
+ <job:name>Quality</job:name>
+ <job:owner version="2.0.0">
+ <owner:type>gncVendor</owner:type>
+ <owner:id type="guid">aa9051c0623c97b80cbdc14171e532ab</owner:id>
+ </job:owner>
+ <job:active>1</job:active>
+</gnc:GncJob>
+<gnc:GncTaxTable version="2.0.0">
+ <taxtable:guid type="guid">b6ab3c8f52b8b716415b07aa6c69e8e6</taxtable:guid>
+ <taxtable:name>Alameda, California</taxtable:name>
+ <taxtable:refcount>0</taxtable:refcount>
+ <taxtable:invisible>0</taxtable:invisible>
+ <taxtable:entries>
+ <gnc:GncTaxTableEntry>
+ <tte:acct type="guid">aa435e75fdee71adc1c51e53ea390638</tte:acct>
+ <tte:amount>975000/100000</tte:amount>
+ <tte:type>PERCENT</tte:type>
+ </gnc:GncTaxTableEntry>
+ </taxtable:entries>
+</gnc:GncTaxTable>
+<gnc:GncVendor version="2.0.0">
+ <vendor:guid type="guid">aa9051c0623c97b80cbdc14171e532ab</vendor:guid>
+ <vendor:name>YoYoDyne, Inc.</vendor:name>
+ <vendor:id>1</vendor:id>
+ <vendor:addr version="2.0.0">
+ <addr:name>YpYoDyne Inc.</addr:name>
+ <addr:addr1>42 Mobius Strip</addr:addr1>
+ <addr:addr2>Fremont, CA 94539</addr:addr2>
+ <addr:phone>510-555-1212</addr:phone>
+ </vendor:addr>
+ <vendor:taxincluded>USEGLOBAL</vendor:taxincluded>
+ <vendor:active>1</vendor:active>
+ <vendor:currency>
+ <cmdty:space>ISO4217</cmdty:space>
+ <cmdty:id>USD</cmdty:id>
+ </vendor:currency>
+ <vendor:use-tt>0</vendor:use-tt>
+</gnc:GncVendor>
<gnc:budget version="2.0.0">
<bgt:id type="guid">367c685aeaef6244170a1f0984665c38</bgt:id>
<bgt:name>Unnamed Budget</bgt:name>
diff --git a/libgnucash/backend/sql/gnc-slots-sql.cpp b/libgnucash/backend/sql/gnc-slots-sql.cpp
index d29f553..17d7425 100644
--- a/libgnucash/backend/sql/gnc-slots-sql.cpp
+++ b/libgnucash/backend/sql/gnc-slots-sql.cpp
@@ -225,8 +225,7 @@ set_slot_from_value (slot_info_t* pInfo, KvpValue* pValue)
{
case FRAME:
{
- auto key = get_key_from_path (pInfo->path);
- pInfo->pKvpFrame->set ({key.c_str()}, pValue);
+ pInfo->pKvpFrame->set ({pInfo->path}, pValue);
break;
}
case LIST:
@@ -242,10 +241,10 @@ set_slot_from_value (slot_info_t* pInfo, KvpValue* pValue)
auto frame = pInfo->pKvpFrame;
if (!path.empty())
{
- frame->set_path ({path.c_str(), key.c_str()}, pValue);
+ frame->set_path ({path, key}, pValue);
}
else
- frame->set ({key.c_str()}, pValue);
+ frame->set ({key}, pValue);
break;
}
}
commit 74d94650ed69e43a9a0538818123485fe993d4ef
Author: John Ralls <jralls at ceridwen.us>
Date: Thu Mar 15 16:28:01 2018 -0700
Avoid crash when committing a date outside of the valid range
Insert a NULL in its place.
diff --git a/libgnucash/backend/sql/gnc-sql-column-table-entry.cpp b/libgnucash/backend/sql/gnc-sql-column-table-entry.cpp
index 020f730..6080679 100644
--- a/libgnucash/backend/sql/gnc-sql-column-table-entry.cpp
+++ b/libgnucash/backend/sql/gnc-sql-column-table-entry.cpp
@@ -429,7 +429,7 @@ GncSqlColumnTableEntryImpl<CT_TIMESPEC>::add_to_query(QofIdTypeConst obj_name,
*/
g_return_if_fail (obj_name != NULL);
g_return_if_fail (pObject != NULL);
-
+
if (m_gobj_param_name != NULL)
{
Timespec* pts;
@@ -442,10 +442,17 @@ GncSqlColumnTableEntryImpl<CT_TIMESPEC>::add_to_query(QofIdTypeConst obj_name,
g_return_if_fail (ts_getter != NULL);
ts = (*ts_getter) (pObject);
}
-
- GncDateTime time(ts.tv_sec);
- vec.emplace_back (std::make_pair (std::string{m_col_name},
- time.format_zulu ("'%Y-%m-%d %H:%M:%S'")));
+ if (ts.tv_sec > MINTIME && ts.tv_sec < MAXTIME)
+ {
+ GncDateTime time(ts.tv_sec);
+ vec.emplace_back (std::make_pair (std::string{m_col_name},
+ time.format_zulu ("'%Y-%m-%d %H:%M:%S'")));
+ }
+ else
+ {
+ vec.emplace_back (std::make_pair (std::string{m_col_name},
+ "NULL"));
+ }
}
/* ----------------------------------------------------------------- */
Summary of changes:
libgnucash/backend/dbi/test/test-dbi.xml | 161 +++++++++++++++++++++
libgnucash/backend/sql/gnc-entry-sql.cpp | 4 +-
libgnucash/backend/sql/gnc-invoice-sql.cpp | 4 +-
libgnucash/backend/sql/gnc-slots-sql.cpp | 7 +-
.../backend/sql/gnc-sql-column-table-entry.cpp | 76 +++++++++-
.../backend/sql/gnc-sql-column-table-entry.hpp | 1 +
6 files changed, 241 insertions(+), 12 deletions(-)
More information about the gnucash-changes
mailing list