gnucash unstable: Multiple changes pushed

Geert Janssens gjanssens at code.gnucash.org
Fri Mar 30 13:03:05 EDT 2018


Updated	 via  https://github.com/Gnucash/gnucash/commit/7271ce3d (commit)
	 via  https://github.com/Gnucash/gnucash/commit/15227727 (commit)
	from  https://github.com/Gnucash/gnucash/commit/2ea165c7 (commit)



commit 7271ce3deebcd8d05b8651776ebf49a1b390d993
Author: Geert Janssens <geert at kobaltwit.be>
Date:   Fri Mar 30 18:55:49 2018 +0200

    Add feature kvp frame to the dbi test file

diff --git a/libgnucash/backend/dbi/test/test-dbi.xml b/libgnucash/backend/dbi/test/test-dbi.xml
index 88c9519..6b932e6 100644
--- a/libgnucash/backend/dbi/test/test-dbi.xml
+++ b/libgnucash/backend/dbi/test/test-dbi.xml
@@ -32,6 +32,17 @@
 <gnc:count-data cd:type="book">1</gnc:count-data>
 <gnc:book version="2.0.0">
 <book:id type="guid">b3166809e9731aec1f040d1c9fc19e84</book:id>
+<book:slots>
+  <slot>
+    <slot:key>features</slot:key>
+    <slot:value type="frame">
+      <slot>
+        <slot:key>Account GUID based bayesian with flat KVP</slot:key>
+        <slot:value type="string">Use account GUID as key for bayesian data and store KVP flat (requires at least Gnucash 2.6.19)</slot:value>
+      </slot>
+    </slot:value>
+  </slot>
+</book:slots>
 <gnc:count-data cd:type="commodity">1</gnc:count-data>
 <gnc:count-data cd:type="account">12</gnc:count-data>
 <gnc:count-data cd:type="transaction">5</gnc:count-data>

commit 152277274f4feb9b2e53be6163724ed74e8a2886
Author: Geert Janssens <geert at kobaltwit.be>
Date:   Fri Mar 30 18:18:21 2018 +0200

    Fix slot loading in sql backend
    
    Be smarter about what is path and key for each slot.
    Instead of assuming a slash is always a path separator (first attempt
    on unstable) or never a separator (second attempt),
    track the parent path while loading kvp slots from the db
    and deduce the slot's name by substracting this parent path.

diff --git a/libgnucash/backend/sql/gnc-slots-sql.cpp b/libgnucash/backend/sql/gnc-slots-sql.cpp
index 17d7425..7f579c1 100644
--- a/libgnucash/backend/sql/gnc-slots-sql.cpp
+++ b/libgnucash/backend/sql/gnc-slots-sql.cpp
@@ -74,6 +74,7 @@ struct slot_info_t
     context_t context;
     KvpValue* pKvpValue;
     std::string path;
+    std::string parent_path;
 };
 
 
@@ -198,21 +199,13 @@ get_final_delim(std::string& path)
 }
 
 static std::string
-get_key_from_path (std::string path)
+get_key (slot_info_t* pInfo)
 {
-    auto idx = get_final_delim(path);
-    if (idx == std::string::npos)
-        return path;
-    return path.substr(idx + 1);
-}
+    if (!pInfo) return "";
 
-static std::string
-get_path_from_path (std::string path)
-{
-    auto idx = get_final_delim(path);
-    if (idx == std::string::npos)
-        return "";
-    return path.substr(0, idx);
+    auto path = pInfo->path;
+    path.erase (0, pInfo->parent_path.size());
+    return path;
 }
 
 static void
@@ -225,7 +218,8 @@ set_slot_from_value (slot_info_t* pInfo, KvpValue* pValue)
     {
     case FRAME:
     {
-        pInfo->pKvpFrame->set ({pInfo->path}, pValue);
+        auto key = get_key (pInfo);
+        pInfo->pKvpFrame->set ({key}, pValue);
         break;
     }
     case LIST:
@@ -236,8 +230,8 @@ set_slot_from_value (slot_info_t* pInfo, KvpValue* pValue)
     case NONE:
     default:
     {
-        auto key = get_key_from_path (pInfo->path);
-        auto path = get_path_from_path (pInfo->path);
+        auto key = get_key (pInfo);
+        auto path = pInfo->parent_path;
         auto frame = pInfo->pKvpFrame;
         if (!path.empty())
         {
@@ -281,6 +275,8 @@ set_path (gpointer pObject,  gpointer pValue)
 {
     slot_info_t* pInfo = (slot_info_t*)pObject;
     pInfo->path = static_cast<char*>(pValue);
+    if (pInfo->path.find (pInfo->parent_path) != 0)
+        pInfo->parent_path.clear();
 }
 
 static KvpValue::Type
@@ -457,7 +453,7 @@ set_guid_val (gpointer pObject,  gpointer pValue)
     {
         slot_info_t* newInfo = slot_info_copy (pInfo, (GncGUID*)pValue);
         KvpValue* pValue = NULL;
-        auto key = get_key_from_path (pInfo->path);
+        auto key = get_key (pInfo);
 
         newInfo->context = LIST;
 
@@ -478,14 +474,14 @@ set_guid_val (gpointer pObject,  gpointer pValue)
         case LIST:
         {
             auto value = new KvpValue {newFrame};
-            newInfo->path = get_key_from_path (pInfo->path);
+            newInfo->path = get_key (pInfo);
             pInfo->pList = g_list_append (pInfo->pList, value);
             break;
         }
         case FRAME:
         default:
         {
-            auto key = get_key_from_path (pInfo->path);
+            auto key = get_key (pInfo);
             pInfo->pKvpFrame->set ({key.c_str()}, new KvpValue {newFrame});
             break;
         }
@@ -575,7 +571,10 @@ slot_info_copy (slot_info_t* pInfo, GncGUID* guid)
     newSlot->pList = pInfo->pList;
     newSlot->context = pInfo->context;
     newSlot->pKvpValue = pInfo->pKvpValue;
-    newSlot->path.clear();
+    if (!pInfo->path.empty())
+        newSlot->parent_path = pInfo->path + "/";
+    else
+        newSlot->parent_path = pInfo->parent_path;
     return newSlot;
 }
 
@@ -589,12 +588,8 @@ save_slot (const char* key, KvpValue* value, slot_info_t & slot_info)
     {
         return;
     }
-    auto curlen = slot_info.path.length();
     slot_info.pKvpValue = value;
-    if (curlen != 0)
-        slot_info.path += "/";
-
-    slot_info.path += key;
+    slot_info.path = slot_info.parent_path + key;
     slot_info.value_type = value->get_type ();
 
     switch (slot_info.value_type)
@@ -650,8 +645,6 @@ save_slot (const char* key, KvpValue* value, slot_info_t & slot_info)
     }
     break;
     }
-
-    slot_info.path.erase(curlen);
 }
 
 gboolean



Summary of changes:
 libgnucash/backend/dbi/test/test-dbi.xml | 11 ++++++++
 libgnucash/backend/sql/gnc-slots-sql.cpp | 47 ++++++++++++++------------------
 2 files changed, 31 insertions(+), 27 deletions(-)



More information about the gnucash-changes mailing list