diff --git a/configure.ac b/configure.ac index 1a281f1a25..b614495453 100644 --- a/configure.ac +++ b/configure.ac @@ -27,7 +27,11 @@ AC_CONFIG_SRCDIR(src/engine/Transaction.h) #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 @@ AC_DEFINE_UNQUOTED(GNUCASH_MICRO_VERSION, $GNUCASH_MICRO_VERSION, [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]) diff --git a/src/backend/dbi/Makefile.am b/src/backend/dbi/Makefile.am index 1cfa7d34b4..b272e2f60f 100644 --- a/src/backend/dbi/Makefile.am +++ b/src/backend/dbi/Makefile.am @@ -33,6 +33,7 @@ libgncmod_backend_dbi_la_LIBADD = \ ${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} diff --git a/src/backend/dbi/gnc-backend-dbi.c b/src/backend/dbi/gnc-backend-dbi.c index 63b2b70385..7ae1911cb7 100644 --- a/src/backend/dbi/gnc-backend-dbi.c +++ b/src/backend/dbi/gnc-backend-dbi.c @@ -1204,6 +1204,15 @@ gnc_dbi_destroy_backend( /*@ only @*/ QofBackend *be ) /* ================================================================= */ +/* 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_dbi_load( QofBackend* qbe, /*@ dependent @*/ QofBook *book, QofBackendLoadTy 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 diff --git a/src/backend/dbi/test/test-dbi-stuff.c b/src/backend/dbi/test/test-dbi-stuff.c index a0e5050e47..1a48ccb011 100644 --- a/src/backend/dbi/test/test-dbi-stuff.c +++ b/src/backend/dbi/test/test-dbi-stuff.c @@ -304,7 +304,7 @@ test_dbi_version_control( const gchar* driver, const gchar* url ) 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 ); diff --git a/src/backend/sql/gnc-backend-sql.c b/src/backend/sql/gnc-backend-sql.c index cd8071c0f2..d904243481 100644 --- a/src/backend/sql/gnc-backend-sql.c +++ b/src/backend/sql/gnc-backend-sql.c @@ -496,7 +496,7 @@ gnc_sql_sync_all( GncSqlBackend* be, /*@ dependent @*/ QofBook *book ) 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 @@ gnc_sql_commit_edit( GncSqlBackend *be, QofInstance *inst ) 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 @@ gnc_sql_commit_edit( GncSqlBackend *be, QofInstance *inst ) 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 ); diff --git a/src/backend/sql/gnc-backend-sql.h b/src/backend/sql/gnc-backend-sql.h index 1d8ca47a64..2b6f1b2883 100644 --- a/src/backend/sql/gnc-backend-sql.h +++ b/src/backend/sql/gnc-backend-sql.h @@ -43,25 +43,6 @@ #include "qofbackend-p.h" #include -/** - * \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; /**