gnucash maint: Multiple changes pushed

Geert Janssens gjanssens at code.gnucash.org
Fri Jul 6 16:32:11 EDT 2018


Updated	 via  https://github.com/Gnucash/gnucash/commit/9d5712ef (commit)
	 via  https://github.com/Gnucash/gnucash/commit/87578184 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/f067e832 (commit)
	from  https://github.com/Gnucash/gnucash/commit/49bd9c41 (commit)



commit 9d5712ef09f71199dd2c03c8aed92c095e0c8a59
Author: Geert Janssens <geert at kobaltwit.be>
Date:   Fri Jul 6 22:32:01 2018 +0200

    Use same 'force' logic sequence for sqlite and other dbs

diff --git a/libgnucash/backend/dbi/gnc-backend-dbi.cpp b/libgnucash/backend/dbi/gnc-backend-dbi.cpp
index bbb0d97..c67e567 100644
--- a/libgnucash/backend/dbi/gnc-backend-dbi.cpp
+++ b/libgnucash/backend/dbi/gnc-backend-dbi.cpp
@@ -405,7 +405,9 @@ GncDbiBackend<DbType::DBI_SQLITE>::session_begin(QofSession* session,
 
     if (create && file_exists)
     {
-        if (!force)
+        if (force)
+            g_unlink (filepath.c_str());
+        else
         {
             set_error (ERR_BACKEND_STORE_EXISTS);
             auto msg = "Might clobber, no force";
@@ -413,8 +415,6 @@ GncDbiBackend<DbType::DBI_SQLITE>::session_begin(QofSession* session,
             LEAVE("Error");
             return;
         }
-        else
-            g_unlink (filepath.c_str());
     }
 
     connect(nullptr);

commit 875781847a39113148f6ed9c3bab5fcc6d9e960b
Author: Geert Janssens <geert at kobaltwit.be>
Date:   Fri Jul 6 22:30:15 2018 +0200

    Bug 796724 - Can't overwrite gnucash DB on MariaDB

diff --git a/libgnucash/backend/dbi/gnc-backend-dbi.cpp b/libgnucash/backend/dbi/gnc-backend-dbi.cpp
index e00c22e..bbb0d97 100644
--- a/libgnucash/backend/dbi/gnc-backend-dbi.cpp
+++ b/libgnucash/backend/dbi/gnc-backend-dbi.cpp
@@ -652,64 +652,80 @@ GncDbiBackend<Type>::session_begin (QofSession* session, const char* book_id,
             LEAVE("Error");
             return;
         }
-        if (create && !force && save_may_clobber_data (conn,
-                                                       uri.quote_dbname(Type)))
+        if (create && save_may_clobber_data (conn, uri.quote_dbname(Type)))
         {
-            set_error (ERR_BACKEND_STORE_EXISTS);
-            PWARN ("Databse already exists, Might clobber it.");
-            dbi_conn_close(conn);
-            LEAVE("Error");
-            return;
+            if (force)
+            {
+                // Drop DB
+                if (Type == DbType::DBI_PGSQL)
+                    dbi_conn_select_db (conn, "template1");
+                else if (Type == DbType::DBI_MYSQL)
+                    dbi_conn_select_db (conn, "mysql");
+                else
+                    PWARN ("Unknown database type, don't know how to connect to a system database. Dropping existing database may fail.");
+
+                if (!dbi_conn_queryf (conn, "DROP DATABASE %s",
+                                 uri.quote_dbname(Type).c_str()))
+                    PWARN ("Failed to drop database %s prior to recreating it. Creation will likely fail.",
+                           uri.quote_dbname(Type).c_str());
+            }
+            else
+            {
+                set_error (ERR_BACKEND_STORE_EXISTS);
+                PWARN ("Databse already exists, Might clobber it.");
+                dbi_conn_close(conn);
+                LEAVE("Error");
+                return;
+            }
         }
 
     }
-    else
+    else if (m_exists)
+    {
+        PERR ("Unable to connect to database '%s'\n", uri.dbname());
+        set_error (ERR_BACKEND_SERVER_ERR);
+        dbi_conn_close(conn);
+        LEAVE("Error");
+        return;
+    }
+    else if (!create)
     {
+        PERR ("Database '%s' does not exist\n", uri.dbname());
+        set_error(ERR_BACKEND_NO_SUCH_DB);
+        std::string msg{"Database "};
+        set_message(msg + uri.dbname() + " not found");
+        LEAVE("Error");
+        return;
+    }
 
-        if (m_exists)
+    if (create)
+    {
+        if (!create_database(conn, uri.quote_dbname(Type).c_str()))
         {
-            PERR ("Unable to connect to database '%s'\n", uri.dbname());
-            set_error (ERR_BACKEND_SERVER_ERR);
             dbi_conn_close(conn);
             LEAVE("Error");
             return;
         }
-
-        if (create)
+        conn = conn_setup(options, uri);
+        result = dbi_conn_connect (conn);
+        if (result < 0)
         {
-            if (!create_database(conn, uri.quote_dbname(Type).c_str()))
-            {
-                dbi_conn_close(conn);
-                LEAVE("Error");
-                return;
-            }
-            conn = conn_setup(options, uri);
-            result = dbi_conn_connect (conn);
-            if (result < 0)
-            {
-                PERR ("Unable to create database '%s'\n", uri.dbname());
-                set_error (ERR_BACKEND_SERVER_ERR);
-                dbi_conn_close(conn);
-                LEAVE("Error");
-                return;
-            }
-            if (Type == DbType::DBI_MYSQL)
-                adjust_sql_options (conn);
-            if (!conn_test_dbi_library(conn))
-            {
-                if (Type == DbType::DBI_PGSQL)
-                    dbi_conn_select_db (conn, "template1");
-                dbi_conn_queryf (conn, "DROP DATABASE %s",
-                                 uri.quote_dbname(Type).c_str());
-                dbi_conn_close(conn);
-                return;
-            }
+            PERR ("Unable to create database '%s'\n", uri.dbname());
+            set_error (ERR_BACKEND_SERVER_ERR);
+            dbi_conn_close(conn);
+            LEAVE("Error");
+            return;
         }
-        else
+        if (Type == DbType::DBI_MYSQL)
+            adjust_sql_options (conn);
+        if (!conn_test_dbi_library(conn))
         {
-            set_error(ERR_BACKEND_NO_SUCH_DB);
-            std::string msg{"Database "};
-            set_message(msg + uri.dbname() + " not found");
+            if (Type == DbType::DBI_PGSQL)
+                dbi_conn_select_db (conn, "template1");
+            dbi_conn_queryf (conn, "DROP DATABASE %s",
+                                uri.quote_dbname(Type).c_str());
+            dbi_conn_close(conn);
+            return;
         }
     }
 

commit f067e8328e7299a3eff81aec646878f0b82852fa
Author: Geert Janssens <geert at kobaltwit.be>
Date:   Fri Jul 6 22:00:08 2018 +0200

    Allow saving to xml over an existing sqlite3 file and the other way around
    
    A type check on the pre-existing file was preventing this. The type check however
    only makes sense when opening files, not when overwriting.

diff --git a/libgnucash/engine/qofsession.cpp b/libgnucash/engine/qofsession.cpp
index fbebf26..0c57736 100644
--- a/libgnucash/engine/qofsession.cpp
+++ b/libgnucash/engine/qofsession.cpp
@@ -180,7 +180,9 @@ QofSessionImpl::load_backend (std::string access_method) noexcept
             continue;
         }
         PINFO (" Selected provider %s", prov->provider_name);
-        if (!prov->type_check (m_book_id.c_str ()))
+        // Only do a type check when trying to open an existing file
+        // When saving over an existing file the contents of the original file don't matter
+        if (!m_creating && !prov->type_check (m_book_id.c_str ()))
         {
             PINFO("Provider, %s, reported not being usable for book, %s.",
                     prov->provider_name, m_book_id.c_str ());
@@ -303,6 +305,7 @@ QofSessionImpl::begin (std::string new_book_id, bool ignore_lock,
     destroy_backend ();
     /* Store the session URL  */
     m_book_id = new_book_id;
+    m_creating = create;
     if (filename)
         load_backend ("file");
     else                       /* access method found, load appropriate backend */
@@ -481,7 +484,7 @@ QofSessionImpl::save (QofPercentageFunc percentage_func) noexcept
     }
     else
     {
-        push_error (ERR_BACKEND_NO_HANDLER, "failod to load backend");
+        push_error (ERR_BACKEND_NO_HANDLER, "failed to load backend");
         LEAVE("error -- No backend!");
     }
     m_saving = false;
diff --git a/libgnucash/engine/qofsession.hpp b/libgnucash/engine/qofsession.hpp
index 57a2425..7820e08 100644
--- a/libgnucash/engine/qofsession.hpp
+++ b/libgnucash/engine/qofsession.hpp
@@ -95,6 +95,7 @@ private:
     std::string m_book_id;
 
     bool m_saving;
+    bool m_creating;
 
     /* If any book subroutine failed, this records the failure reason
      * (file not found, etc).



Summary of changes:
 libgnucash/backend/dbi/gnc-backend-dbi.cpp | 110 +++++++++++++++++------------
 libgnucash/engine/qofsession.cpp           |   7 +-
 libgnucash/engine/qofsession.hpp           |   1 +
 3 files changed, 69 insertions(+), 49 deletions(-)



More information about the gnucash-changes mailing list