r20223 - gnucash/trunk - Change GNC_RESAVE_VERSION to GNUCASH_RESAVE_VERSION so that it's similar to the other version macros; define it at the top of configure.ac so that it's obvious to everybody; and store the current Gnucash version only when doing a full save so that retrospective changes to GNUCASH_RESAVE_VERSION won't skip a resave because the database has been touchedby a newer version.

John Ralls jralls at code.gnucash.org
Tue Feb 1 19:04:30 EST 2011


Author: jralls
Date: 2011-02-01 19:04:29 -0500 (Tue, 01 Feb 2011)
New Revision: 20223
Trac: http://svn.gnucash.org/trac/changeset/20223

Modified:
   gnucash/trunk/configure.ac
   gnucash/trunk/src/backend/dbi/Makefile.am
   gnucash/trunk/src/backend/dbi/gnc-backend-dbi.c
   gnucash/trunk/src/backend/dbi/test/test-dbi-stuff.c
   gnucash/trunk/src/backend/sql/gnc-backend-sql.c
   gnucash/trunk/src/backend/sql/gnc-backend-sql.h
Log:
Change GNC_RESAVE_VERSION to GNUCASH_RESAVE_VERSION so that it's similar to the other version macros; define it at the top of configure.ac so that it's obvious to everybody; and store the current Gnucash version only when doing a full save so that retrospective changes to GNUCASH_RESAVE_VERSION won't skip a resave because the database has been touchedby a newer version.

Modified: gnucash/trunk/configure.ac
===================================================================
--- gnucash/trunk/configure.ac	2011-02-01 21:04:58 UTC (rev 20222)
+++ gnucash/trunk/configure.ac	2011-02-02 00:04:29 UTC (rev 20223)
@@ -27,7 +27,11 @@
 #Change this in development versions when changing anything that
 #affects stored data structures. Reset to zero when bumping version.
 GNUCASH_NANO_VERSION=0
-
+#This should be the earliest version in the form XXMMUUNN (XX=MAJOR,
+#MM=MINOR, UU=MICRO, NN=NANO) or SVN revision if before 2.4.1 which is
+#storage-compatible with the current version. See the comments in
+#src/backend/dbi/gnc-backend-dbi.c:gnc_dbi_load.
+GNUCASH_RESAVE_VERSION=19920
 # Initialize automake -- make sure we have at least version 1.9
 AM_INIT_AUTOMAKE([1.9 dist-bzip2])
 
@@ -82,6 +86,8 @@
     [GnuCash Micro version number])
 AC_DEFINE_UNQUOTED(GNUCASH_NANO_VERSION, $GNUCASH_NANO_VERSION,
     [GnuCash Nano version number])
+AC_DEFINE_UNQUOTED(GNUCASH_RESAVE_VERSION, $GNUCASH_RESAVE_VERSION,
+    [GnuCash earliest compatible databaseversion number])
 AC_DEFINE_UNQUOTED(GNUCASH_LATEST_STABLE_SERIES, "$GNUCASH_LATEST_STABLE_SERIES",
     [Most recent stable GnuCash series])
 

Modified: gnucash/trunk/src/backend/dbi/Makefile.am
===================================================================
--- gnucash/trunk/src/backend/dbi/Makefile.am	2011-02-01 21:04:58 UTC (rev 20222)
+++ gnucash/trunk/src/backend/dbi/Makefile.am	2011-02-02 00:04:29 UTC (rev 20223)
@@ -33,6 +33,7 @@
    ${GCONF_LIBS} \
    ${top_builddir}/src/backend/sql/libgnc-backend-sql.la \
    ${top_builddir}/src/engine/libgncmod-engine.la \
+   ${top_builddir}/src/app-utils/libgncmod-app-utils.la \
    ${top_builddir}/src/libqof/qof/libgnc-qof.la \
    ${LIBDBI_LIBS}
 

Modified: gnucash/trunk/src/backend/dbi/gnc-backend-dbi.c
===================================================================
--- gnucash/trunk/src/backend/dbi/gnc-backend-dbi.c	2011-02-01 21:04:58 UTC (rev 20222)
+++ gnucash/trunk/src/backend/dbi/gnc-backend-dbi.c	2011-02-02 00:04:29 UTC (rev 20223)
@@ -1204,6 +1204,15 @@
 
 /* ================================================================= */
 
+/* GNUCASH_RESAVE_VERSION indicates the earliest database version
+ * compatible with this version of Gnucash; the stored value is the
+ * earliest version of Gnucash conpatible with the database. If the
+ * GNUCASH_RESAVE_VERSION for this Gnucash is newer than the Gnucash
+ * version which created the database, a resave is offered. If the
+ * version of this Gnucash is older than the saved resave version,
+ * then the database will be loaded read-only. A resave will update
+ * both values to match this version of Gnucash.
+ */
 static void
 gnc_dbi_load( QofBackend* qbe, /*@ dependent @*/ QofBook *book, QofBackendLoadType loadType )
 {
@@ -1228,14 +1237,14 @@
 
     gnc_sql_load( &be->sql_be, book, loadType );
 
-    if ( GNC_RESAVE_VERSION > gnc_sql_get_table_version( &be->sql_be, "Gnucash" ) )
+    if ( GNUCASH_RESAVE_VERSION > gnc_sql_get_table_version( &be->sql_be, "Gnucash" ) )
     {
         /* The database was loaded with an older database schema or
          * data semantics. In order to ensure consistency, the whole
          * thing needs to be saved anew. */
         qof_backend_set_error( qbe, ERR_SQL_DB_TOO_OLD );
     }
-    else if ( GNC_RESAVE_VERSION < gnc_sql_get_table_version( &be->sql_be,
+    else if ( GNUCASH_RESAVE_VERSION < gnc_sql_get_table_version( &be->sql_be,
               "Gnucash-Resave"))
     {
         /* Worse, the database was created with a newer version. We

Modified: gnucash/trunk/src/backend/dbi/test/test-dbi-stuff.c
===================================================================
--- gnucash/trunk/src/backend/dbi/test/test-dbi-stuff.c	2011-02-01 21:04:58 UTC (rev 20222)
+++ gnucash/trunk/src/backend/dbi/test/test-dbi-stuff.c	2011-02-02 00:04:29 UTC (rev 20223)
@@ -304,7 +304,7 @@
     book = qof_session_get_book( sess );
     qof_book_begin_edit( book );
     gnc_sql_set_table_version( (GncSqlBackend*)qbe,
-                               "Gnucash", GNC_RESAVE_VERSION - 1 );
+                               "Gnucash", GNUCASH_RESAVE_VERSION - 1 );
     qof_book_commit_edit( book );
     qof_session_end( sess );
     qof_session_destroy( sess );

Modified: gnucash/trunk/src/backend/sql/gnc-backend-sql.c
===================================================================
--- gnucash/trunk/src/backend/sql/gnc-backend-sql.c	2011-02-01 21:04:58 UTC (rev 20222)
+++ gnucash/trunk/src/backend/sql/gnc-backend-sql.c	2011-02-02 00:04:29 UTC (rev 20223)
@@ -496,7 +496,7 @@
     update_progress( be );
     (void)reset_version_info( be );
     gnc_sql_set_table_version( be, "Gnucash", gnc_get_long_version() );
-    gnc_sql_set_table_version( be, "Gnucash-Resave", GNC_RESAVE_VERSION );
+    gnc_sql_set_table_version( be, "Gnucash-Resave", GNUCASH_RESAVE_VERSION );
 
     /* Create new tables */
     be->is_pristine_db = TRUE;
@@ -610,7 +610,6 @@
     gboolean is_dirty;
     gboolean is_destroying;
     gboolean is_infant;
-    const gint gnc_version = gnc_get_long_version();
 
     g_return_if_fail( be != NULL );
     g_return_if_fail( inst != NULL );
@@ -664,9 +663,6 @@
     be_data.be = be;
     be_data.inst = inst;
     be_data.is_ok = TRUE;
-    /* Set/update the application version in the database */
-    if ( gnc_sql_get_table_version( be, "Gnucash") != gnc_version )
-        gnc_sql_set_table_version( be, "Gnucash", gnc_version );
 
     qof_object_foreach_backend( GNC_SQL_BACKEND, commit_cb, &be_data );
 

Modified: gnucash/trunk/src/backend/sql/gnc-backend-sql.h
===================================================================
--- gnucash/trunk/src/backend/sql/gnc-backend-sql.h	2011-02-01 21:04:58 UTC (rev 20222)
+++ gnucash/trunk/src/backend/sql/gnc-backend-sql.h	2011-02-02 00:04:29 UTC (rev 20223)
@@ -43,25 +43,6 @@
 #include "qofbackend-p.h"
 #include <gmodule.h>
 
-/**
- * \def GNC_RESAVE_VERSION
- *
- * Defines the oldest svn revision of Gnucash which stores data in a
- * way compatible with the current version. Data stored with an older
- * version (or with no version indicated) of Gnucash will cause all
- * tables to be moved aside, new tables saved with the current storage
- * routines, and the old tables dropped. Any failures will trigger a
- * rollback to the original tables.
- *
- * Encountering a database with a newer resave version will put the
- * database in "read only" mode; a "save as" will be required to
- * obtain a new database for storing from this instance, and the user
- * will be warned of data loss.
- *
- */
-
-#define GNC_RESAVE_VERSION 19920
-
 typedef struct GncSqlConnection GncSqlConnection;
 
 /**



More information about the gnucash-changes mailing list