r17184 - gnucash/branches/gda-dev2/src - Add new versions table. This table tracks the version for each of the

Phil Longstaff plongstaff at cvs.gnucash.org
Sun Jun 1 10:59:28 EDT 2008


Author: plongstaff
Date: 2008-06-01 10:59:27 -0400 (Sun, 01 Jun 2008)
New Revision: 17184
Trac: http://svn.gnucash.org/trac/changeset/17184

Modified:
   gnucash/branches/gda-dev2/src/backend/gda/gnc-account-gda.c
   gnucash/branches/gda-dev2/src/backend/gda/gnc-backend-gda.c
   gnucash/branches/gda-dev2/src/backend/gda/gnc-backend-util-gda.c
   gnucash/branches/gda-dev2/src/backend/gda/gnc-backend-util-gda.h
   gnucash/branches/gda-dev2/src/backend/gda/gnc-book-gda.c
   gnucash/branches/gda-dev2/src/backend/gda/gnc-budget-gda.c
   gnucash/branches/gda-dev2/src/backend/gda/gnc-commodity-gda.c
   gnucash/branches/gda-dev2/src/backend/gda/gnc-lots-gda.c
   gnucash/branches/gda-dev2/src/backend/gda/gnc-price-gda.c
   gnucash/branches/gda-dev2/src/backend/gda/gnc-recurrence-gda.c
   gnucash/branches/gda-dev2/src/backend/gda/gnc-schedxaction-gda.c
   gnucash/branches/gda-dev2/src/backend/gda/gnc-slots-gda.c
   gnucash/branches/gda-dev2/src/backend/gda/gnc-transaction-gda.c
   gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-bill-term-gda.c
   gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-customer-gda.c
   gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-employee-gda.c
   gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-entry-gda.c
   gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-invoice-gda.c
   gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-job-gda.c
   gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-order-gda.c
   gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-tax-table-gda.c
   gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-vendor-gda.c
Log:
Add new versions table.  This table tracks the version for each of the
tables.  The backend pieces can then compare this version number against
the current version number and update the table structure accordingly.



Modified: gnucash/branches/gda-dev2/src/backend/gda/gnc-account-gda.c
===================================================================
--- gnucash/branches/gda-dev2/src/backend/gda/gnc-account-gda.c	2008-05-31 23:53:51 UTC (rev 17183)
+++ gnucash/branches/gda-dev2/src/backend/gda/gnc-account-gda.c	2008-06-01 14:59:27 UTC (rev 17184)
@@ -46,6 +46,7 @@
 static QofLogModule log_module = G_LOG_DOMAIN;
 
 #define TABLE_NAME "accounts"
+#define TABLE_VERSION 1
 
 static gpointer get_parent( gpointer pObject, const QofParam* );
 static void set_parent( gpointer pObject, gpointer pValue );
@@ -292,9 +293,19 @@
 static void
 create_account_tables( GncGdaBackend* be )
 {
+	gint version;
+
 	g_return_if_fail( be != NULL );
 
-    gnc_gda_create_table_if_needed( be, TABLE_NAME, col_table );
+	version = gnc_gda_get_table_version( be, TABLE_NAME );
+    if( version == 0 ) {
+    	GError* error = NULL;
+
+        gnc_gda_create_table( be, TABLE_NAME, TABLE_VERSION, col_table, &error );
+        if( error != NULL ) {
+            PERR( "Error creating table: %s\n", error->message );
+        }
+    }
 }
 
 /* ================================================================= */
@@ -382,8 +393,8 @@
     {
         GNC_GDA_BACKEND_VERSION,
         GNC_ID_ACCOUNT,
-        gnc_gda_save_account,				/* commit */
-        load_all_accounts,				/* initial_load */
+        gnc_gda_save_account,		/* commit */
+        load_all_accounts,			/* initial_load */
         create_account_tables		/* create_tables */
     };
 

Modified: gnucash/branches/gda-dev2/src/backend/gda/gnc-backend-gda.c
===================================================================
--- gnucash/branches/gda-dev2/src/backend/gda/gnc-backend-gda.c	2008-05-31 23:53:51 UTC (rev 17183)
+++ gnucash/branches/gda-dev2/src/backend/gda/gnc-backend-gda.c	2008-06-01 14:59:27 UTC (rev 17184)
@@ -311,6 +311,9 @@
         PERR( "gda_dict_update_dbms_meta_data() error: %s\n", error->message );
     }
 
+	// Set up table version information
+	_init_version_info( be );
+
     // Call all object backends to create any required tables
     qof_object_foreach_backend( GNC_GDA_BACKEND, create_tables_cb, be );
 
@@ -346,6 +349,7 @@
         g_object_unref( G_OBJECT(be->pClient ) );
         be->pClient = NULL;
     }
+	_finalize_version_info( be );
 
     LEAVE (" ");
 }
@@ -621,6 +625,8 @@
         }
     }
 
+	_reset_version_info( be );
+
     // Update the dictionary because new tables may exist
     gda_dict_update_dbms_meta_data( be->pDict, 0, NULL, &error );
     if( error != NULL ) {

Modified: gnucash/branches/gda-dev2/src/backend/gda/gnc-backend-util-gda.c
===================================================================
--- gnucash/branches/gda-dev2/src/backend/gda/gnc-backend-util-gda.c	2008-05-31 23:53:51 UTC (rev 17183)
+++ gnucash/branches/gda-dev2/src/backend/gda/gnc-backend-util-gda.c	2008-06-01 14:59:27 UTC (rev 17184)
@@ -58,6 +58,9 @@
     gnc_gda_query_info* pQueryInfo;
 } gda_backend;
 
+static void register_table_version( const GncGdaBackend* be, const gchar* table_name, gint version );
+static gint get_table_version( const GncGdaBackend* be, const gchar* table_name );
+
 /* ================================================================= */
 void
 gnc_gda_add_field_to_query( GdaQuery* query, const gchar* col_name, const GValue* value )
@@ -1485,7 +1488,7 @@
 }
 
 GdaDataModel*
-gnc_gda_execute_sql( const GncGdaBackend* be, const gchar* sql )
+gnc_gda_execute_select_sql( const GncGdaBackend* be, const gchar* sql )
 {
 	GdaCommand* cmd;
     GError* error = NULL;
@@ -1504,6 +1507,26 @@
 	return model;
 }
 
+gint
+gnc_gda_execute_nonselect_sql( const GncGdaBackend* be, const gchar* sql )
+{
+	GdaCommand* cmd;
+    GError* error = NULL;
+	gint ret;
+
+	g_return_val_if_fail( be != NULL, 0 );
+	g_return_val_if_fail( sql != NULL, 0 );
+
+	cmd = gda_command_new( sql, GDA_COMMAND_TYPE_SQL, 0 );
+    ret = gda_connection_execute_non_select_command( be->pConnection, cmd, NULL, &error );
+	gda_command_free( cmd );
+    if( error != NULL ) {
+        PERR( "SQL error: %s\n", error->message );
+    }
+
+	return ret;
+}
+
 int
 gnc_gda_execute_select_get_count( const GncGdaBackend* be, const gchar* sql )
 {
@@ -1513,7 +1536,7 @@
 	g_return_val_if_fail( be != NULL, 0 );
 	g_return_val_if_fail( sql != NULL, 0 );
 
-    model = gnc_gda_execute_sql( be, sql );
+    model = gnc_gda_execute_select_sql( be, sql );
     if( model != NULL ) {
         count = gda_data_model_get_n_rows( model );
     }
@@ -1818,9 +1841,9 @@
     }
 }
 
-gboolean
-gnc_gda_create_table( const GncGdaBackend* be, const gchar* table_name,
-                    const col_cvt_t* col_table, GError** error )
+static gboolean
+create_table( const GncGdaBackend* be, const gchar* table_name,
+				const col_cvt_t* col_table, GError** error )
 {
     GdaServerOperation *op;
     GdaServerProvider *server;
@@ -1881,6 +1904,19 @@
 }
 
 gboolean
+gnc_gda_create_table( const GncGdaBackend* be, const gchar* table_name,
+					gint table_version, const col_cvt_t* col_table, GError** error )
+{
+	gboolean ok;
+
+	ok = create_table( be, table_name, col_table, error );
+	if( ok ) {
+		register_table_version( be, table_name, table_version );
+	}
+	return ok;
+}
+
+gboolean
 gnc_gda_create_index( const GncGdaBackend* be, const gchar* index_name,
 					const gchar* table_name,
                     const col_cvt_t* col_table, GError** error )
@@ -1964,11 +2000,33 @@
     return TRUE;
 }
 
-gboolean gnc_gda_does_table_exist( const GncGdaBackend* be, const gchar* table_name )
+gint
+gnc_gda_get_table_version( const GncGdaBackend* be, const gchar* table_name )
 {
     GdaDictTable* table;
     GdaDictDatabase* db;
 
+	g_return_val_if_fail( be != NULL, 0 );
+	g_return_val_if_fail( table_name != NULL, 0 );
+
+	/* If the db is pristine because it's being saved, the table does not
+	 * exist.  This gets around a GDA-3 bug where deleting all tables and
+	 * updating the meta-data leaves the meta-data still thinking 1 table
+	 * exists.
+	 */
+	if( be->is_pristine_db ) {
+		return 0;
+	}
+
+	return get_table_version( be, table_name );
+}
+
+static gboolean
+does_table_exist( const GncGdaBackend* be, const gchar* table_name )
+{
+    GdaDictTable* table;
+    GdaDictDatabase* db;
+
 	g_return_val_if_fail( be != NULL, FALSE );
 	g_return_val_if_fail( table_name != NULL, FALSE );
 
@@ -1992,23 +2050,6 @@
 	}
 }
 
-void gnc_gda_create_table_if_needed( const GncGdaBackend* be,
-			                        const gchar* table_name,
-									const col_cvt_t* col_table )
-{
-	g_return_if_fail( be != NULL );
-	g_return_if_fail( table_name != NULL );
-	g_return_if_fail( col_table != NULL );
-
-    if( !gnc_gda_does_table_exist( be, table_name ) ) {
-    	GError* error = NULL;
-
-        gnc_gda_create_table( be, table_name, col_table, &error );
-        if( error != NULL ) {
-            PERR( "Error creating table: %s\n", error->message );
-        }
-    }
-}
 /* ================================================================= */
 #if 0
 static gboolean
@@ -2103,4 +2144,147 @@
                                 db_name, error );
 }
 #endif
+/* ================================================================= */
+#define VERSION_TABLE_NAME "versions"
+#define MAX_TABLE_NAME_LEN 50
+#define TABLE_COL_NAME "table_name"
+#define VERSION_COL_NAME "table_version"
+
+static col_cvt_t version_table[] =
+{
+    { TABLE_COL_NAME,   CT_STRING, MAX_TABLE_NAME_LEN },
+	{ VERSION_COL_NAME, CT_INT },
+    { NULL }
+};
+
+/**
+ * Sees if the version table exists, and if it does, loads the info into
+ * the version hash table.  Otherwise, it creates an empty version table.
+ *
+ * @param be Backend struct
+ */
+void
+_init_version_info( GncGdaBackend* be )
+{
+	g_return_if_fail( be != NULL );
+
+	be->versions = g_hash_table_new( g_str_hash, g_str_equal );
+
+	if( does_table_exist( be, VERSION_TABLE_NAME ) ) {
+		GdaDataModel* model;
+		gchar* sql;
+
+		sql = g_strdup_printf( "SELECT * FROM %s", VERSION_TABLE_NAME );
+		model = gnc_gda_execute_select_sql( be, sql );
+		g_free( sql );
+		if( model != NULL ) {
+			gint numRows = gda_data_model_get_n_rows( model );
+			const GValue* name;
+			const GValue* version;
+			gint row;
+
+			for( row = 0; row < numRows; row++ ) {
+    			name = gda_data_model_get_value_at_col_name( model, TABLE_COL_NAME, row );
+				version = gda_data_model_get_value_at_col_name( model, VERSION_COL_NAME,
+																row );
+				g_hash_table_insert( be->versions,
+									(gpointer)g_value_get_string( name ),
+									GINT_TO_POINTER(g_value_get_int( version )) );
+			}
+		}
+	} else {
+		gboolean ok;
+		GError* error = NULL;
+
+		ok = create_table( be, VERSION_TABLE_NAME, version_table, &error );
+		if( error != NULL ) {
+			PERR( "Error creating versions table: %s\n", error->message );
+		}
+	}
+}
+
+/**
+ * Resets the version table information by removing all version table info.
+ * It also recreates the version table in the db.
+ *
+ * @param be Backend struct
+ */
+void
+_reset_version_info( const GncGdaBackend* be )
+{
+	gboolean ok;
+	GError* error = NULL;
+
+	g_return_if_fail( be != NULL );
+
+	ok = create_table( be, VERSION_TABLE_NAME, version_table, &error );
+	if( error != NULL ) {
+		PERR( "Error creating versions table: %s\n", error->message );
+	}
+	g_hash_table_remove_all( be->versions );
+}
+
+/**
+ * Finalizes the version table info by destroying the hash table.
+ *
+ * @param be Backend struct
+ */
+void
+_finalize_version_info( GncGdaBackend* be )
+{
+	g_return_if_fail( be != NULL );
+
+	g_hash_table_destroy( be->versions );
+}
+
+/**
+ * Registers the version for a table.  Registering involves updating the
+ * db version table and also the hash table.
+ *
+ * @param be Backend struct
+ * @param table_name Table name
+ * @param version Version number
+ */
+static void
+register_table_version( const GncGdaBackend* be, const gchar* table_name, gint version )
+{
+	gchar* sql;
+	gint cur_version;
+
+	g_return_if_fail( be != NULL );
+	g_return_if_fail( table_name != NULL );
+	g_return_if_fail( version > 0 );
+
+	cur_version = get_table_version( be, table_name );
+	if( cur_version != version ) {
+		if( cur_version == 0 ) {
+			sql = g_strdup_printf( "INSERT INTO %s VALUES('%s',%d)", VERSION_TABLE_NAME,
+								table_name, version );
+		} else {
+			sql = g_strdup_printf( "UPDATE %s SET %s=%d WHERE %s='%s'", VERSION_TABLE_NAME,
+								VERSION_COL_NAME, version,
+								TABLE_COL_NAME, table_name );
+		}
+		(void)gnc_gda_execute_nonselect_sql( be, sql );
+		g_free( sql );
+	}
+
+	g_hash_table_insert( be->versions, (gpointer)table_name, GINT_TO_POINTER(version) );
+}
+
+/**
+ * Returns the registered version number for a table.
+ *
+ * @param be Backend struct
+ * @param table_name Table name
+ * @return Version number
+ */
+static gint
+get_table_version( const GncGdaBackend* be, const gchar* table_name )
+{
+	g_return_val_if_fail( be != NULL, 0 );
+	g_return_val_if_fail( table_name != NULL, 0 );
+
+	return GPOINTER_TO_INT(g_hash_table_lookup( be->versions, table_name ));
+}
 /* ========================== END OF FILE ===================== */

Modified: gnucash/branches/gda-dev2/src/backend/gda/gnc-backend-util-gda.h
===================================================================
--- gnucash/branches/gda-dev2/src/backend/gda/gnc-backend-util-gda.h	2008-05-31 23:53:51 UTC (rev 17183)
+++ gnucash/branches/gda-dev2/src/backend/gda/gnc-backend-util-gda.h	2008-06-01 14:59:27 UTC (rev 17184)
@@ -49,6 +49,7 @@
 
   gint obj_total;			// Total # of objects (for percentage calculation)
   gint operations_done;		// Number of operations (save/load) done
+  GHashTable* versions;		// Version number for each table
 };
 typedef struct GncGdaBackend_struct GncGdaBackend;
 
@@ -163,7 +164,8 @@
 									gpointer pObject,
 									const col_cvt_t* table );
 GdaObject* gnc_gda_execute_query( GncGdaBackend* pBackend, GdaQuery* pQuery );
-GdaDataModel* gnc_gda_execute_sql( const GncGdaBackend* pBackend, const gchar* sql );
+GdaDataModel* gnc_gda_execute_select_sql( const GncGdaBackend* pBackend, const gchar* sql );
+gint gnc_gda_execute_nonselect_sql( const GncGdaBackend* pBackend, const gchar* sql );
 GdaQuery* gnc_gda_create_query_from_sql( const GncGdaBackend* pBackend, const gchar* sql );
 int gnc_gda_execute_select_get_count( const GncGdaBackend* pBackend, const gchar* sql );
 int gnc_gda_execute_query_get_count( GncGdaBackend* pBackend, GdaQuery* query );
@@ -174,15 +176,13 @@
 									const gchar* table_name,
 									QofIdTypeConst obj_name, const gpointer pObject,
 									const col_cvt_t* table );
-gboolean gnc_gda_does_table_exist( const GncGdaBackend* be, const gchar* table_name );
-gboolean gnc_gda_create_table( const GncGdaBackend* be,
-						const gchar* table_name, const col_cvt_t* col_table,
-						GError** error );
+gint gnc_gda_get_table_version( const GncGdaBackend* be, const gchar* table_name );
+gboolean gnc_gda_create_table( const GncGdaBackend* be, const gchar* table_name,
+								gint table_version, const col_cvt_t* col_table,
+								GError** error );
 gboolean gnc_gda_create_index( const GncGdaBackend* be, const gchar* index_name,
 						const gchar* table_name, const col_cvt_t* col_table,
 						GError** error );
-void gnc_gda_create_table_if_needed( const GncGdaBackend* be,
-						const gchar* table_name, const col_cvt_t* col_table );
 const GUID* gnc_gda_load_guid( const GncGdaBackend* be, GdaDataModel* pModel, int row );
 const GUID* gnc_gda_load_tx_guid( const GncGdaBackend* be, GdaDataModel* pModel, int row );
 GdaQuery* gnc_gda_create_select_query( const GncGdaBackend* be, const gchar* table_name );
@@ -202,6 +202,9 @@
 guint gnc_gda_append_guid_list_to_sql( GString* str, GList* list, guint maxCount );
 
 void _retrieve_guid_( gpointer pObject, gpointer pValue );
+void _init_version_info( GncGdaBackend* be );
+void _reset_version_info( const GncGdaBackend* be );
+void _finalize_version_info( GncGdaBackend* be );
 
 G_MODULE_EXPORT const gchar *
 g_module_check_init( GModule *module );

Modified: gnucash/branches/gda-dev2/src/backend/gda/gnc-book-gda.c
===================================================================
--- gnucash/branches/gda-dev2/src/backend/gda/gnc-book-gda.c	2008-05-31 23:53:51 UTC (rev 17183)
+++ gnucash/branches/gda-dev2/src/backend/gda/gnc-book-gda.c	2008-06-01 14:59:27 UTC (rev 17184)
@@ -44,6 +44,7 @@
 #include "SX-book-p.h"
 
 #define BOOK_TABLE "books"
+#define TABLE_VERSION 1
 
 static QofLogModule log_module = G_LOG_DOMAIN;
 
@@ -180,9 +181,19 @@
 static void
 create_book_tables( GncGdaBackend* be )
 {
+	gint version;
+
 	g_return_if_fail( be != NULL );
 
-    gnc_gda_create_table_if_needed( be, BOOK_TABLE, col_table );
+	version = gnc_gda_get_table_version( be, BOOK_TABLE );
+    if( version == 0 ) {
+    	GError* error = NULL;
+
+        gnc_gda_create_table( be, BOOK_TABLE, TABLE_VERSION, col_table, &error );
+        if( error != NULL ) {
+            PERR( "Error creating table: %s\n", error->message );
+        }
+    }
 }
 
 /* ================================================================= */

Modified: gnucash/branches/gda-dev2/src/backend/gda/gnc-budget-gda.c
===================================================================
--- gnucash/branches/gda-dev2/src/backend/gda/gnc-budget-gda.c	2008-05-31 23:53:51 UTC (rev 17183)
+++ gnucash/branches/gda-dev2/src/backend/gda/gnc-budget-gda.c	2008-06-01 14:59:27 UTC (rev 17184)
@@ -44,6 +44,7 @@
 #include "gnc-budget.h"
 
 #define BUDGET_TABLE "budgets"
+#define TABLE_VERSION 1
 
 static QofLogModule log_module = G_LOG_DOMAIN;
 
@@ -83,7 +84,6 @@
     gnc_gda_load_object( be, pModel, row, GNC_ID_BUDGET, pBudget, col_table );
 	r = g_new0( Recurrence, 1 );
 	gnc_gda_recurrence_load( be, gnc_budget_get_guid( pBudget ), r );
-//    gnc_gda_slots_load( be, QOF_INSTANCE(pBudget) );
 	*pList = g_list_append( *pList, pBudget );
 
     qof_instance_mark_clean( QOF_INSTANCE(pBudget) );
@@ -121,9 +121,19 @@
 static void
 create_budget_tables( GncGdaBackend* be )
 {
+	gint version;
+
 	g_return_if_fail( be != NULL );
 
-    gnc_gda_create_table_if_needed( be, BUDGET_TABLE, col_table );
+	version = gnc_gda_get_table_version( be, BUDGET_TABLE );
+    if( version == 0 ) {
+    	GError* error = NULL;
+
+        gnc_gda_create_table( be, BUDGET_TABLE, TABLE_VERSION, col_table, &error );
+        if( error != NULL ) {
+            PERR( "Error creating table: %s\n", error->message );
+        }
+    }
 }
 
 /* ================================================================= */

Modified: gnucash/branches/gda-dev2/src/backend/gda/gnc-commodity-gda.c
===================================================================
--- gnucash/branches/gda-dev2/src/backend/gda/gnc-commodity-gda.c	2008-05-31 23:53:51 UTC (rev 17183)
+++ gnucash/branches/gda-dev2/src/backend/gda/gnc-commodity-gda.c	2008-06-01 14:59:27 UTC (rev 17184)
@@ -48,6 +48,7 @@
 static void set_quote_source_name( gpointer pObject, gpointer pValue );
 
 #define COMMODITIES_TABLE "commodities"
+#define TABLE_VERSION 1
 
 #define COMMODITY_MAX_NAMESPACE_LEN 2048
 #define COMMODITY_MAX_MNEMONIC_LEN 2048
@@ -173,9 +174,19 @@
 static void
 create_commodities_tables( GncGdaBackend* be )
 {
+	gint version;
+
 	g_return_if_fail( be != NULL );
 
-    gnc_gda_create_table_if_needed( be, COMMODITIES_TABLE, col_table );
+	version = gnc_gda_get_table_version( be, COMMODITIES_TABLE );
+    if( version == 0 ) {
+    	GError* error = NULL;
+
+        gnc_gda_create_table( be, COMMODITIES_TABLE, TABLE_VERSION, col_table, &error );
+        if( error != NULL ) {
+            PERR( "Error creating table: %s\n", error->message );
+        }
+    }
 }
 
 /* ================================================================= */

Modified: gnucash/branches/gda-dev2/src/backend/gda/gnc-lots-gda.c
===================================================================
--- gnucash/branches/gda-dev2/src/backend/gda/gnc-lots-gda.c	2008-05-31 23:53:51 UTC (rev 17183)
+++ gnucash/branches/gda-dev2/src/backend/gda/gnc-lots-gda.c	2008-06-01 14:59:27 UTC (rev 17184)
@@ -42,6 +42,7 @@
 static QofLogModule log_module = G_LOG_DOMAIN;
 
 #define TABLE_NAME "lots"
+#define TABLE_VERSION 1
 
 static gpointer get_lot_account( gpointer pObject, const QofParam* param );
 static void set_lot_account( gpointer pObject, gpointer pValue );
@@ -110,7 +111,6 @@
     lot = gnc_lot_new( be->primary_book );
 
     gnc_gda_load_object( be, pModel, row, GNC_ID_LOT, lot, col_table );
-//    gnc_gda_slots_load( be, QOF_INSTANCE(lot) );
 	*pList = g_list_append( *pList, lot );
 
     qof_instance_mark_clean( QOF_INSTANCE(lot) );
@@ -148,9 +148,19 @@
 static void
 create_lots_tables( GncGdaBackend* be )
 {
+	gint version;
+
 	g_return_if_fail( be != NULL );
 
-    gnc_gda_create_table_if_needed( be, TABLE_NAME, col_table );
+	version = gnc_gda_get_table_version( be, TABLE_NAME );
+    if( version == 0 ) {
+    	GError* error = NULL;
+
+        gnc_gda_create_table( be, TABLE_NAME, TABLE_VERSION, col_table, &error );
+        if( error != NULL ) {
+            PERR( "Error creating table: %s\n", error->message );
+        }
+    }
 }
 
 /* ================================================================= */

Modified: gnucash/branches/gda-dev2/src/backend/gda/gnc-price-gda.c
===================================================================
--- gnucash/branches/gda-dev2/src/backend/gda/gnc-price-gda.c	2008-05-31 23:53:51 UTC (rev 17183)
+++ gnucash/branches/gda-dev2/src/backend/gda/gnc-price-gda.c	2008-06-01 14:59:27 UTC (rev 17184)
@@ -43,6 +43,7 @@
 static QofLogModule log_module = G_LOG_DOMAIN;
 
 #define TABLE_NAME "prices"
+#define TABLE_VERSION 1
 
 #define PRICE_MAX_SOURCE_LEN 2048
 #define PRICE_MAX_TYPE_LEN 2048
@@ -121,9 +122,19 @@
 static void
 create_prices_tables( GncGdaBackend* be )
 {
+	gint version;
+
 	g_return_if_fail( be != NULL );
 
-    gnc_gda_create_table_if_needed( be, TABLE_NAME, col_table );
+	version = gnc_gda_get_table_version( be, TABLE_NAME );
+    if( version == 0 ) {
+    	GError* error = NULL;
+
+        gnc_gda_create_table( be, TABLE_NAME, TABLE_VERSION, col_table, &error );
+        if( error != NULL ) {
+            PERR( "Error creating table: %s\n", error->message );
+        }
+    }
 }
 
 /* ================================================================= */

Modified: gnucash/branches/gda-dev2/src/backend/gda/gnc-recurrence-gda.c
===================================================================
--- gnucash/branches/gda-dev2/src/backend/gda/gnc-recurrence-gda.c	2008-05-31 23:53:51 UTC (rev 17183)
+++ gnucash/branches/gda-dev2/src/backend/gda/gnc-recurrence-gda.c	2008-06-01 14:59:27 UTC (rev 17184)
@@ -42,6 +42,7 @@
 static QofLogModule log_module = G_LOG_DOMAIN;
 
 #define TABLE_NAME "recurrences"
+#define TABLE_VERSION 1
 
 #define BUDGET_MAX_RECURRENCE_PERIOD_TYPE_LEN 2048
 
@@ -354,9 +355,19 @@
 static void
 create_recurrence_tables( GncGdaBackend* be )
 {
+	gint version;
+
 	g_return_if_fail( be != NULL );
 
-    gnc_gda_create_table_if_needed( be, TABLE_NAME, col_table );
+	version = gnc_gda_get_table_version( be, TABLE_NAME );
+    if( version == 0 ) {
+    	GError* error = NULL;
+
+        gnc_gda_create_table( be, TABLE_NAME, TABLE_VERSION, col_table, &error );
+        if( error != NULL ) {
+            PERR( "Error creating table: %s\n", error->message );
+        }
+    }
 }
 
 /* ================================================================= */

Modified: gnucash/branches/gda-dev2/src/backend/gda/gnc-schedxaction-gda.c
===================================================================
--- gnucash/branches/gda-dev2/src/backend/gda/gnc-schedxaction-gda.c	2008-05-31 23:53:51 UTC (rev 17183)
+++ gnucash/branches/gda-dev2/src/backend/gda/gnc-schedxaction-gda.c	2008-06-01 14:59:27 UTC (rev 17184)
@@ -45,6 +45,7 @@
 #include "gnc-recurrence-gda.h"
 
 #define SCHEDXACTION_TABLE "schedxactions"
+#define TABLE_VERSION 1
 
 static QofLogModule log_module = G_LOG_DOMAIN;
 
@@ -203,7 +204,6 @@
     gnc_gda_load_object( be, pModel, row, /*GNC_ID_SCHEDXACTION*/GNC_SX_ID, pSx, col_table );
 	gnc_gda_recurrence_load_list( be, guid, &schedule );
 	gnc_sx_set_schedule( pSx, schedule );
-//    gnc_gda_slots_load( be, QOF_INSTANCE(pSx) );
 	*pList = g_list_append( *pList, pSx );
 
     qof_instance_mark_clean( QOF_INSTANCE(pSx) );
@@ -250,9 +250,19 @@
 static void
 create_sx_tables( GncGdaBackend* be )
 {
+	gint version;
+
 	g_return_if_fail( be != NULL );
 
-    gnc_gda_create_table_if_needed( be, SCHEDXACTION_TABLE, col_table );
+	version = gnc_gda_get_table_version( be, SCHEDXACTION_TABLE );
+    if( version == 0 ) {
+    	GError* error = NULL;
+
+        gnc_gda_create_table( be, SCHEDXACTION_TABLE, TABLE_VERSION, col_table, &error );
+        if( error != NULL ) {
+            PERR( "Error creating table: %s\n", error->message );
+        }
+    }
 }
 
 /* ================================================================= */

Modified: gnucash/branches/gda-dev2/src/backend/gda/gnc-slots-gda.c
===================================================================
--- gnucash/branches/gda-dev2/src/backend/gda/gnc-slots-gda.c	2008-05-31 23:53:51 UTC (rev 17183)
+++ gnucash/branches/gda-dev2/src/backend/gda/gnc-slots-gda.c	2008-06-01 14:59:27 UTC (rev 17184)
@@ -41,6 +41,7 @@
 static QofLogModule log_module = G_LOG_DOMAIN;
 
 #define TABLE_NAME "slots"
+#define TABLE_VERSION 1
 
 typedef struct {
     GncGdaBackend* be;
@@ -550,7 +551,7 @@
 
 	// Execute the query and load the slots
 	query = gnc_gda_create_query_from_sql( be, sql->str );
-	model = gnc_gda_execute_sql( be, sql->str );
+	model = gnc_gda_execute_select_sql( be, sql->str );
     if( model != NULL ) {
         int numRows = gda_data_model_get_n_rows( model );
         int r;
@@ -569,11 +570,13 @@
 {
 	GError* error = NULL;
 	gboolean ok;
+	gint version;
 
 	g_return_if_fail( be != NULL );
 
-	if( !gnc_gda_does_table_exist( be, TABLE_NAME ) ) {
-    	gnc_gda_create_table( be, TABLE_NAME, col_table, &error );
+	version = gnc_gda_get_table_version( be, TABLE_NAME );
+	if( version == 0 ) {
+    	gnc_gda_create_table( be, TABLE_NAME, TABLE_VERSION, col_table, &error );
 		if( error != NULL ) {
 			g_critical( "GDA: unable to create SLOTS table: %s\n", error->message );
 		}

Modified: gnucash/branches/gda-dev2/src/backend/gda/gnc-transaction-gda.c
===================================================================
--- gnucash/branches/gda-dev2/src/backend/gda/gnc-transaction-gda.c	2008-05-31 23:53:51 UTC (rev 17183)
+++ gnucash/branches/gda-dev2/src/backend/gda/gnc-transaction-gda.c	2008-06-01 14:59:27 UTC (rev 17184)
@@ -50,7 +50,9 @@
 static QofLogModule log_module = G_LOG_DOMAIN;
 
 #define TRANSACTION_TABLE "transactions"
+#define TX_TABLE_VERSION 1
 #define SPLIT_TABLE "splits"
+#define SPLIT_TABLE_VERSION 1
 
 typedef struct {
     GncGdaBackend* be;
@@ -65,7 +67,6 @@
     { "guid",          CT_GUID,           0,                      COL_NNUL|COL_PKEY, "guid" },
     { "currency_guid", CT_COMMODITYREF,   0,                      COL_NNUL,          NULL, NULL,
 			(QofAccessFunc)xaccTransGetCurrency, (QofSetterFunc)xaccTransSetCurrency },
-//    { "num",           CT_STRING,         TX_MAX_NUM_LEN,         COL_NNUL,          NULL, TRANS_NUM },
     { "num",           CT_STRING,         TX_MAX_NUM_LEN,         COL_NNUL,          NULL, NULL,
 			(QofAccessFunc)xaccTransGetNum, (QofSetterFunc)xaccTransSetNum },
     { "post_date",     CT_TIMESPEC,       0,                      COL_NNUL,          NULL, NULL,
@@ -227,7 +228,7 @@
 	g_return_val_if_fail( be != NULL, bal );
 	g_return_val_if_fail( sql != NULL, bal );
 
-	model = gnc_gda_execute_sql( be, sql );
+	model = gnc_gda_execute_select_sql( be, sql );
 	if( model != NULL ) {
     	int numRows;
     	int r;
@@ -253,7 +254,7 @@
 	g_return_if_fail( be != NULL );
 	g_return_if_fail( sql != NULL );
 
-	model = gnc_gda_execute_sql( be, sql );
+	model = gnc_gda_execute_select_sql( be, sql );
 	if( model != NULL ) {
 		for( ; result_list != NULL; result_list = result_list->next ) {
 			acct_balances_t* ab = (acct_balances_t*)result_list->data;
@@ -533,7 +534,7 @@
 	g_string_append( sql, ")" );
 
 	// Execute the query and load the splits
-	model = gnc_gda_execute_sql( be, sql->str );
+	model = gnc_gda_execute_select_sql( be, sql->str );
     if( model != NULL ) {
         int numRows = gda_data_model_get_n_rows( model );
         int r;
@@ -651,10 +652,29 @@
 static void
 create_transaction_tables( GncGdaBackend* be )
 {
+	gint version;
+
 	g_return_if_fail( be != NULL );
 
-    gnc_gda_create_table_if_needed( be, TRANSACTION_TABLE, tx_col_table );
-    gnc_gda_create_table_if_needed( be, SPLIT_TABLE, split_col_table );
+	version = gnc_gda_get_table_version( be, TRANSACTION_TABLE );
+    if( version == 0 ) {
+    	GError* error = NULL;
+
+        gnc_gda_create_table( be, TRANSACTION_TABLE, TX_TABLE_VERSION, tx_col_table, &error );
+        if( error != NULL ) {
+            PERR( "Error creating table: %s\n", error->message );
+        }
+    }
+
+	version = gnc_gda_get_table_version( be, SPLIT_TABLE );
+    if( version == 0 ) {
+    	GError* error = NULL;
+
+        gnc_gda_create_table( be, SPLIT_TABLE, SPLIT_TABLE_VERSION, split_col_table, &error );
+        if( error != NULL ) {
+            PERR( "Error creating table: %s\n", error->message );
+        }
+    }
 }
 /* ================================================================= */
 static void
@@ -850,7 +870,7 @@
     guid_to_string_buff( acct_guid, guid_buf );
 	sql = g_string_new( "" );
 	g_string_printf( sql, "SELECT DISTINCT tx_guid FROM %s WHERE account_guid='%s'", SPLIT_TABLE, guid_buf );
-	model = gnc_gda_execute_sql( be, sql->str );
+	model = gnc_gda_execute_select_sql( be, sql->str );
     if( model != NULL ) {
         int numRows = gda_data_model_get_n_rows( model );
         int r;

Modified: gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-bill-term-gda.c
===================================================================
--- gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-bill-term-gda.c	2008-05-31 23:53:51 UTC (rev 17183)
+++ gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-bill-term-gda.c	2008-06-01 14:59:27 UTC (rev 17184)
@@ -47,6 +47,7 @@
 static void set_invisible( gpointer data, gboolean value );
 
 #define TABLE_NAME "billterms"
+#define TABLE_VERSION 1
 
 static col_cvt_t col_table[] =
 {
@@ -146,9 +147,19 @@
 static void
 create_billterm_tables( GncGdaBackend* be )
 {
+	gint version;
+
 	g_return_if_fail( be != NULL );
 
-    gnc_gda_create_table_if_needed( be, TABLE_NAME, col_table );
+	version = gnc_gda_get_table_version( be, TABLE_NAME );
+    if( version == 0 ) {
+    	GError* error = NULL;
+
+        gnc_gda_create_table( be, TABLE_NAME, TABLE_VERSION, col_table, &error );
+        if( error != NULL ) {
+            PERR( "Error creating table: %s\n", error->message );
+        }
+    }
 }
 
 /* ================================================================= */

Modified: gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-customer-gda.c
===================================================================
--- gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-customer-gda.c	2008-05-31 23:53:51 UTC (rev 17183)
+++ gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-customer-gda.c	2008-06-01 14:59:27 UTC (rev 17184)
@@ -44,6 +44,7 @@
 static QofLogModule log_module = G_LOG_DOMAIN;
 
 #define TABLE_NAME "customers"
+#define TABLE_VERSION 1
 
 #define MAX_NAME_LEN 2048
 #define MAX_ID_LEN 2048
@@ -127,9 +128,19 @@
 static void
 create_customer_tables( GncGdaBackend* be )
 {
+	gint version;
+
 	g_return_if_fail( be != NULL );
 
-    gnc_gda_create_table_if_needed( be, TABLE_NAME, col_table );
+	version = gnc_gda_get_table_version( be, TABLE_NAME );
+    if( version == 0 ) {
+    	GError* error = NULL;
+
+        gnc_gda_create_table( be, TABLE_NAME, TABLE_VERSION, col_table, &error );
+        if( error != NULL ) {
+            PERR( "Error creating table: %s\n", error->message );
+        }
+    }
 }
 
 /* ================================================================= */

Modified: gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-employee-gda.c
===================================================================
--- gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-employee-gda.c	2008-05-31 23:53:51 UTC (rev 17183)
+++ gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-employee-gda.c	2008-06-01 14:59:27 UTC (rev 17184)
@@ -52,6 +52,7 @@
 #define MAX_ACL_LEN 2048
 
 #define TABLE_NAME "employees"
+#define TABLE_VERSION 1
 
 static col_cvt_t col_table[] =
 {
@@ -128,9 +129,19 @@
 static void
 create_employee_tables( GncGdaBackend* be )
 {
+	gint version;
+
 	g_return_if_fail( be != NULL );
 
-    gnc_gda_create_table_if_needed( be, TABLE_NAME, col_table );
+	version = gnc_gda_get_table_version( be, TABLE_NAME );
+    if( version == 0 ) {
+    	GError* error = NULL;
+
+        gnc_gda_create_table( be, TABLE_NAME, TABLE_VERSION, col_table, &error );
+        if( error != NULL ) {
+            PERR( "Error creating table: %s\n", error->message );
+        }
+    }
 }
 
 /* ================================================================= */

Modified: gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-entry-gda.c
===================================================================
--- gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-entry-gda.c	2008-05-31 23:53:51 UTC (rev 17183)
+++ gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-entry-gda.c	2008-06-01 14:59:27 UTC (rev 17184)
@@ -47,6 +47,7 @@
 static QofLogModule log_module = G_LOG_DOMAIN;
 
 #define TABLE_NAME "entries"
+#define TABLE_VERSION 1
 #define MAX_DESCRIPTION_LEN 2048
 #define MAX_ACTION_LEN 2048
 #define MAX_NOTES_LEN 2048
@@ -147,9 +148,19 @@
 static void
 create_entry_tables( GncGdaBackend* be )
 {
+	gint version;
+
 	g_return_if_fail( be != NULL );
 
-    gnc_gda_create_table_if_needed( be, TABLE_NAME, col_table );
+	version = gnc_gda_get_table_version( be, TABLE_NAME );
+    if( version == 0 ) {
+    	GError* error = NULL;
+
+        gnc_gda_create_table( be, TABLE_NAME, TABLE_VERSION, col_table, &error );
+        if( error != NULL ) {
+            PERR( "Error creating table: %s\n", error->message );
+        }
+    }
 }
 
 /* ================================================================= */

Modified: gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-invoice-gda.c
===================================================================
--- gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-invoice-gda.c	2008-05-31 23:53:51 UTC (rev 17183)
+++ gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-invoice-gda.c	2008-06-01 14:59:27 UTC (rev 17184)
@@ -45,6 +45,7 @@
 static QofLogModule log_module = G_LOG_DOMAIN;
 
 #define TABLE_NAME "invoices"
+#define TABLE_VERSION 1
 
 #define MAX_ID_LEN 2048
 #define MAX_NOTES_LEN 2048
@@ -131,9 +132,19 @@
 static void
 create_invoice_tables( GncGdaBackend* be )
 {
+	gint version;
+
 	g_return_if_fail( be != NULL );
 
-    gnc_gda_create_table_if_needed( be, TABLE_NAME, col_table );
+	version = gnc_gda_get_table_version( be, TABLE_NAME );
+    if( version == 0 ) {
+    	GError* error = NULL;
+
+        gnc_gda_create_table( be, TABLE_NAME, TABLE_VERSION, col_table, &error );
+        if( error != NULL ) {
+            PERR( "Error creating table: %s\n", error->message );
+        }
+    }
 }
 
 /* ================================================================= */

Modified: gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-job-gda.c
===================================================================
--- gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-job-gda.c	2008-05-31 23:53:51 UTC (rev 17183)
+++ gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-job-gda.c	2008-06-01 14:59:27 UTC (rev 17184)
@@ -42,6 +42,7 @@
 static QofLogModule log_module = G_LOG_DOMAIN;
 
 #define TABLE_NAME "jobs"
+#define TABLE_VERSION 1
 
 #define MAX_ID_LEN 2048
 #define MAX_NAME_LEN 2048
@@ -114,9 +115,19 @@
 static void
 create_job_tables( GncGdaBackend* be )
 {
+	gint version;
+
 	g_return_if_fail( be != NULL );
 
-    gnc_gda_create_table_if_needed( be, TABLE_NAME, col_table );
+	version = gnc_gda_get_table_version( be, TABLE_NAME );
+    if( version == 0 ) {
+    	GError* error = NULL;
+
+        gnc_gda_create_table( be, TABLE_NAME, TABLE_VERSION, col_table, &error );
+        if( error != NULL ) {
+            PERR( "Error creating table: %s\n", error->message );
+        }
+    }
 }
 
 /* ================================================================= */

Modified: gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-order-gda.c
===================================================================
--- gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-order-gda.c	2008-05-31 23:53:51 UTC (rev 17183)
+++ gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-order-gda.c	2008-06-01 14:59:27 UTC (rev 17184)
@@ -41,6 +41,7 @@
 static QofLogModule log_module = G_LOG_DOMAIN;
 
 #define TABLE_NAME "orders"
+#define TABLE_VERSION 1
 
 #define MAX_ID_LEN 2048
 #define MAX_NOTES_LEN 2048
@@ -115,9 +116,19 @@
 static void
 create_order_tables( GncGdaBackend* be )
 {
+	gint version;
+
 	g_return_if_fail( be != NULL );
 
-    gnc_gda_create_table_if_needed( be, TABLE_NAME, col_table );
+	version = gnc_gda_get_table_version( be, TABLE_NAME );
+    if( version == 0 ) {
+    	GError* error = NULL;
+
+        gnc_gda_create_table( be, TABLE_NAME, TABLE_VERSION, col_table, &error );
+        if( error != NULL ) {
+            PERR( "Error creating table: %s\n", error->message );
+        }
+    }
 }
 
 /* ================================================================= */

Modified: gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-tax-table-gda.c
===================================================================
--- gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-tax-table-gda.c	2008-05-31 23:53:51 UTC (rev 17183)
+++ gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-tax-table-gda.c	2008-06-01 14:59:27 UTC (rev 17184)
@@ -57,6 +57,7 @@
 #define MAX_NAME_LEN 50
 
 #define TT_TABLE_NAME "taxtables"
+#define TT_TABLE_VERSION 1
 
 static col_cvt_t tt_col_table[] =
 {
@@ -73,6 +74,7 @@
 };
 
 #define TTENTRIES_TABLE_NAME "taxtable_entries"
+#define TTENTRIES_TABLE_VERSION 1
 
 static col_cvt_t ttentries_col_table[] =
 {
@@ -252,10 +254,29 @@
 static void
 create_taxtable_tables( GncGdaBackend* be )
 {
+	gint version;
+
 	g_return_if_fail( be != NULL );
 
-    gnc_gda_create_table_if_needed( be, TT_TABLE_NAME, tt_col_table );
-    gnc_gda_create_table_if_needed( be, TTENTRIES_TABLE_NAME, ttentries_col_table );
+	version = gnc_gda_get_table_version( be, TT_TABLE_NAME );
+    if( version == 0 ) {
+    	GError* error = NULL;
+
+        gnc_gda_create_table( be, TT_TABLE_NAME, TT_TABLE_VERSION, tt_col_table, &error );
+        if( error != NULL ) {
+            PERR( "Error creating table: %s\n", error->message );
+        }
+    }
+
+	version = gnc_gda_get_table_version( be, TTENTRIES_TABLE_NAME );
+    if( version == 0 ) {
+    	GError* error = NULL;
+
+        gnc_gda_create_table( be, TTENTRIES_TABLE_NAME, TTENTRIES_TABLE_VERSION, ttentries_col_table, &error );
+        if( error != NULL ) {
+            PERR( "Error creating table: %s\n", error->message );
+        }
+    }
 }
 
 /* ================================================================= */

Modified: gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-vendor-gda.c
===================================================================
--- gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-vendor-gda.c	2008-05-31 23:53:51 UTC (rev 17183)
+++ gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-vendor-gda.c	2008-06-01 14:59:27 UTC (rev 17184)
@@ -55,6 +55,7 @@
 #define MAX_TAX_INC_LEN 2048
 
 #define TABLE_NAME "vendors"
+#define TABLE_VERSION 1
 
 static col_cvt_t col_table[] =
 {
@@ -127,9 +128,19 @@
 static void
 create_vendor_tables( GncGdaBackend* be )
 {
+	gint version;
+
 	g_return_if_fail( be != NULL );
 
-    gnc_gda_create_table_if_needed( be, TABLE_NAME, col_table );
+	version = gnc_gda_get_table_version( be, TABLE_NAME );
+    if( version == 0 ) {
+    	GError* error = NULL;
+
+        gnc_gda_create_table( be, TABLE_NAME, TABLE_VERSION, col_table, &error );
+        if( error != NULL ) {
+            PERR( "Error creating table: %s\n", error->message );
+        }
+    }
 }
 
 /* ================================================================= */



More information about the gnucash-changes mailing list