gnucash maint: Multiple changes pushed

John Ralls jralls at code.gnucash.org
Fri May 20 13:01:12 EDT 2016


Updated	 via  https://github.com/Gnucash/gnucash/commit/592ad99d (commit)
	 via  https://github.com/Gnucash/gnucash/commit/818fe73a (commit)
	 via  https://github.com/Gnucash/gnucash/commit/ef8f6375 (commit)
	from  https://github.com/Gnucash/gnucash/commit/0e17ebdc (commit)



commit 592ad99ddea4f15a49f9bee42ff27374057c8484
Author: John Ralls <jralls at ceridwen.us>
Date:   Thu May 19 14:23:23 2016 -0700

    Move adjust_sql_options_string declaration to gnc-backend-dbi-priv.h.
    
    It shouldn't be public, it needs to be exported only to the test file.

diff --git a/src/backend/dbi/gnc-backend-dbi-priv.h b/src/backend/dbi/gnc-backend-dbi-priv.h
index 8037e22..6e816e8 100644
--- a/src/backend/dbi/gnc-backend-dbi-priv.h
+++ b/src/backend/dbi/gnc-backend-dbi-priv.h
@@ -114,4 +114,7 @@ typedef struct
 
 } GncDbiSqlConnection;
 
+/* external access required for tests */
+gchar* adjust_sql_options_string(const gchar *);
+
 #endif //GNC_BACKEND_DBI_PRIV_H
diff --git a/src/backend/dbi/gnc-backend-dbi.h b/src/backend/dbi/gnc-backend-dbi.h
index 03466d2..f228134 100644
--- a/src/backend/dbi/gnc-backend-dbi.h
+++ b/src/backend/dbi/gnc-backend-dbi.h
@@ -38,9 +38,6 @@ void gnc_module_init_backend_dbi(void);
  * statically linked into the application. */
 void gnc_module_finalize_backend_dbi(void);
 
-/* external access required for tests */
-gchar* adjust_sql_options_string(const gchar *);
-
 #ifndef GNC_NO_LOADABLE_MODULES
 /** This is the standarized initialization function of a qof_backend
  * GModule, but compiling this can be disabled by defining
diff --git a/src/backend/dbi/test/test-backend-dbi-basic.c b/src/backend/dbi/test/test-backend-dbi-basic.c
index c65442a..04cf131 100644
--- a/src/backend/dbi/test/test-backend-dbi-basic.c
+++ b/src/backend/dbi/test/test-backend-dbi-basic.c
@@ -50,8 +50,6 @@
 #include "gncInvoice.h"
 /* For test_conn_index_functions */
 #include "../gnc-backend-dbi-priv.h"
-/* For test_adjust_options_string */
-#include "../gnc-backend-dbi.h"
 /* For version_control */
 #include <gnc-prefs.h>
 #include <qofsession-p.h>

commit 818fe73a05dec77dbd98fcfb7c7e2fc25c307a13
Author: John Ralls <jralls at ceridwen.us>
Date:   Thu May 19 14:08:55 2016 -0700

    Remove unnecessary g_strdup_printf.
    
    SQL_OPTION_TO_REMOVE is substituted during preprocessing so it can be
    inlined in the string initialization, no need for heap allocation or
    runtime composition.

diff --git a/src/backend/dbi/gnc-backend-dbi.c b/src/backend/dbi/gnc-backend-dbi.c
index e1eeafe..f075202 100644
--- a/src/backend/dbi/gnc-backend-dbi.c
+++ b/src/backend/dbi/gnc-backend-dbi.c
@@ -802,11 +802,11 @@ adjust_sql_options_string (const gchar *str)
     gchar* regex_str = NULL;
     gchar* answer = NULL;
 
-    regex_str = g_strdup_printf( "(?:,%s$|\\b%s\\b,?)",
-        SQL_OPTION_TO_REMOVE, SQL_OPTION_TO_REMOVE );
     /* Build a regex string that will find the pattern at the beginning, end or
      * within the string as a whole word, comma separated.
      */
+    regex_str =  "(?:," SQL_OPTION_TO_REMOVE "$|\\b"
+        SQL_OPTION_TO_REMOVE "\\b,?)";
 
     // compile the regular expression and check for errors
     regex = g_regex_new (regex_str, 0, 0, &err);
@@ -822,7 +822,6 @@ adjust_sql_options_string (const gchar *str)
     {
         answer = g_strdup (str);
     }
-    g_free( regex_str );
     g_regex_unref (regex);
     return answer;
 }

commit ef8f63759fcf40aea858cc6650b93bdffacf3490
Author: John Ralls <jralls at ceridwen.us>
Date:   Thu May 19 14:06:02 2016 -0700

    Fix inconsistent and non-conforming whitespace and comments.

diff --git a/src/backend/dbi/gnc-backend-dbi.c b/src/backend/dbi/gnc-backend-dbi.c
index e58978b..e1eeafe 100644
--- a/src/backend/dbi/gnc-backend-dbi.c
+++ b/src/backend/dbi/gnc-backend-dbi.c
@@ -790,91 +790,94 @@ gnc_dbi_unlock( QofBackend *qbe )
 
 #define SQL_OPTION_TO_REMOVE "NO_ZERO_DATE"
 
-// Given an sql_options string returns a copy of the string adjusted as necessary.
-// In particular if the string contains SQL_OPTION_TO_REMOVE it is removed along with 
-// comma separator.
+/* Given an sql_options string returns a copy of the string adjusted as
+ * necessary. In particular if the string contains SQL_OPTION_TO_REMOVE it is
+ * removed along with comma separator.
+ */
 gchar*
-adjust_sql_options_string( const gchar *str )
+adjust_sql_options_string (const gchar *str)
 {
     GRegex* regex = NULL;
     GError* err = NULL;
     gchar* regex_str = NULL;
     gchar* answer = NULL;
-    
-    // build a regex string that will find the pattern at the beginning, end or
-    // within the string as a whole word, comma separated
+
     regex_str = g_strdup_printf( "(?:,%s$|\\b%s\\b,?)",
         SQL_OPTION_TO_REMOVE, SQL_OPTION_TO_REMOVE );
-    
+    /* Build a regex string that will find the pattern at the beginning, end or
+     * within the string as a whole word, comma separated.
+     */
+
     // compile the regular expression and check for errors
-    regex = g_regex_new( regex_str, 0, 0, &err );
-    if ( err != NULL )
+    regex = g_regex_new (regex_str, 0, 0, &err);
+    if (err != NULL)
     {
         g_error_free (err);
     } else
     {
-        answer = g_regex_replace( regex, str, -1, 0, "", 0, NULL );
+        answer = g_regex_replace (regex, str, -1, 0, "", 0, NULL);
     }
     // in case of errors set the answer to the passed in string
-    if ( !answer )
+    if (!answer)
     {
-        answer = g_strdup( str );
+        answer = g_strdup (str);
     }
     g_free( regex_str );
-    g_regex_unref( regex );
+    g_regex_unref (regex);
     return answer;
 }
 
 /* checks mysql sql_options and adjusts if necessary */
 static void
-adjust_sql_options( dbi_conn connection )
+adjust_sql_options (dbi_conn connection)
 {
     dbi_result result;
     gint err;
     const char* errmsg;
-    
-    result = dbi_conn_query( connection, "SELECT @@sql_mode");
+
+    result = dbi_conn_query (connection, "SELECT @@sql_mode");
     if (result)
     {
         const char* str;
-        dbi_result_first_row(result);
-        str = dbi_result_get_string_idx(result, 1);
+        dbi_result_first_row (result);
+        str = dbi_result_get_string_idx (result, 1);
         if (str)
         {
             PINFO("Initial sql_mode: %s", str);
-            if( strstr( str, SQL_OPTION_TO_REMOVE ) )
+            if (strstr (str, SQL_OPTION_TO_REMOVE))
             {
                 gchar *adjusted_str;
                 gchar *set_str;
                 dbi_result set_result;
-                
-                adjusted_str = adjust_sql_options_string( str );
+
+                adjusted_str = adjust_sql_options_string (str);
                 PINFO("Setting sql_mode to %s", adjusted_str);
-                set_str = g_strdup_printf( "SET sql_mode='%s';", adjusted_str );
-                set_result = dbi_conn_query( connection, set_str);
+                set_str = g_strdup_printf ("SET sql_mode='%s';", adjusted_str);
+                set_result = dbi_conn_query (connection, set_str);
                 if (set_result)
                 {
-                    dbi_result_free( set_result );
-                } else
+                    dbi_result_free (set_result);
+                }
+                else
                 {
-                  err = dbi_conn_error(connection, &errmsg);
-                  PERR("Unable to set sql_mode %d : %s", err, errmsg );
+                    err = dbi_conn_error (connection, &errmsg);
+                    PERR("Unable to set sql_mode %d : %s", err, errmsg );
                 }
-                g_free( adjusted_str );
-                g_free( set_str );
+                g_free (adjusted_str);
+                g_free (set_str);
             }
         }
         else
         {
-            err = dbi_conn_error(connection, &errmsg);
-            PERR("Unable to get sql_mode %d : %s", err, errmsg );
+            err = dbi_conn_error (connection, &errmsg);
+            PERR("Unable to get sql_mode %d : %s", err, errmsg);
         }
         dbi_result_free(result);
     }
     else
     {
-      err = dbi_conn_error(connection, &errmsg);
-      PERR("Unable to read sql_mode %d : %s", err, errmsg );
+        err = dbi_conn_error (connection, &errmsg);
+        PERR("Unable to read sql_mode %d : %s", err, errmsg );
     }
 }
 
diff --git a/src/backend/dbi/test/test-backend-dbi-basic.c b/src/backend/dbi/test/test-backend-dbi-basic.c
index 90627bd..c65442a 100644
--- a/src/backend/dbi/test/test-backend-dbi-basic.c
+++ b/src/backend/dbi/test/test-backend-dbi-basic.c
@@ -598,7 +598,7 @@ test_dbi_business_store_and_reload (Fixture *fixture, gconstpointer pData)
 }
 #ifndef G_OS_WIN32
 static void
-test_adjust_sql_options_string(void)
+test_adjust_sql_options_string (void)
 {
     gchar *adjusted_str;
     const char* in[] = {
@@ -623,13 +623,13 @@ test_adjust_sql_options_string(void)
         "something,NO_ZERO_DATExx,something_ else",
         "fred,jim,john"
     };
-    
+
     size_t i;
-    for( i = 0; i < sizeof(in) / sizeof(gchar*); i++)
+    for (i = 0; i < sizeof(in) / sizeof(gchar*); i++)
     {
-        gchar *adjusted_str = adjust_sql_options_string( in[i] );
-        g_assert_cmpstr( out[i],==,adjusted_str );
-        g_free( adjusted_str );
+        gchar *adjusted_str = adjust_sql_options_string (in[i]);
+        g_assert_cmpstr (out[i],==,adjusted_str);
+        g_free (adjusted_str);
     }
 }
 #endif //G_OS_WIN32



Summary of changes:
 src/backend/dbi/gnc-backend-dbi-priv.h        |  3 ++
 src/backend/dbi/gnc-backend-dbi.c             | 76 ++++++++++++++-------------
 src/backend/dbi/gnc-backend-dbi.h             |  3 --
 src/backend/dbi/test/test-backend-dbi-basic.c | 14 +++--
 4 files changed, 48 insertions(+), 48 deletions(-)



More information about the gnucash-changes mailing list