r18247 - gnucash/trunk/src/backend - 1) Use 'date' type on pgsql/mysql to save date values.

Phil Longstaff plongstaff at code.gnucash.org
Thu Aug 13 20:29:53 EDT 2009


Author: plongstaff
Date: 2009-08-13 20:29:52 -0400 (Thu, 13 Aug 2009)
New Revision: 18247
Trac: http://svn.gnucash.org/trac/changeset/18247

Modified:
   gnucash/trunk/src/backend/dbi/gnc-backend-dbi.c
   gnucash/trunk/src/backend/sql/gnc-account-sql.c
   gnucash/trunk/src/backend/sql/gnc-backend-sql.c
Log:
1) Use 'date' type on pgsql/mysql to save date values.
2) When loading from db, don't make template root account child of main root account

NOTE: This change will invalidate any db files stored in sqlite3/mysql/pgsql.  Save your file to
XML, rebuild, load from XML and save in new format.


Modified: gnucash/trunk/src/backend/dbi/gnc-backend-dbi.c
===================================================================
--- gnucash/trunk/src/backend/dbi/gnc-backend-dbi.c	2009-08-13 00:05:37 UTC (rev 18246)
+++ gnucash/trunk/src/backend/dbi/gnc-backend-dbi.c	2009-08-14 00:29:52 UTC (rev 18247)
@@ -1387,26 +1387,19 @@
 		if( col_num != 0 ) {
 			(void)g_string_append( ddl, ", " );
 		}
-		switch( info->type ) {
-			case G_TYPE_INT:
-				type_name = "integer";
-				break;
-
-			case G_TYPE_INT64:
-				type_name = "bigint";
-				break;
-
-			case G_TYPE_DOUBLE:
-				type_name = "real";
-				break;
-
-			case G_TYPE_STRING:
-				type_name = "text";
-				break;
-
-			default:
-				PERR( "Unknown GType: %s\n", g_type_name( info->type ) );
-				type_name = "";
+		if( info->type == G_TYPE_INT ) {
+			type_name = "integer";
+		} else if( info->type == G_TYPE_INT64 ) {
+			type_name = "bigint";
+		} else if( info->type == G_TYPE_DOUBLE ) {
+			type_name = "real";
+		} else if( info->type == G_TYPE_STRING ) {
+			type_name = "text";
+		} else if( info->type == G_TYPE_DATE ) {
+			type_name = "text";
+		} else {
+			PERR( "Unknown GType: %s\n", g_type_name( info->type ) );
+			type_name = "";
 		}
 		g_string_append_printf( ddl, "%s %s", info->name, type_name );
     	if( info->size != 0 ) {
@@ -1449,26 +1442,20 @@
 		if( col_num != 0 ) {
 			(void)g_string_append( ddl, ", " );
 		}
-		switch( info->type ) {
-			case G_TYPE_INT:
-				type_name = "integer";
-				break;
-
-			case G_TYPE_INT64:
-				type_name = "bigint";
-				break;
-
-			case G_TYPE_DOUBLE:
-				type_name = "double";
-				break;
-
-			case G_TYPE_STRING:
-				type_name = "varchar";
-				break;
-
-			default:
-				PERR( "Unknown GType: %s\n", g_type_name( info->type ) );
-				type_name = "";
+		if( info->type == G_TYPE_INT ) {
+			type_name = "integer";
+		} else if( info->type == G_TYPE_INT64 ) {
+			type_name = "bigint";
+		} else if( info->type == G_TYPE_DOUBLE ) {
+			type_name = "double";
+		} else if( info->type == G_TYPE_STRING ) {
+			type_name = "varchar";
+		} else if( info->type == G_TYPE_DATE ) {
+			info->size = 0;
+			type_name = "date";
+		} else {
+			PERR( "Unknown GType: %s\n", g_type_name( info->type ) );
+			type_name = "";
 		}
 		g_string_append_printf( ddl, "%s %s", info->name, type_name );
     	if( info->size != 0 ) {
@@ -1515,30 +1502,24 @@
 		if( col_num != 0 ) {
 			(void)g_string_append( ddl, ", " );
 		}
-		switch( info->type ) {
-			case G_TYPE_INT:
-				if( info->is_autoinc ) {
-					type_name = "sequence";
-				} else {
-					type_name = "integer";
-				}
-				break;
-
-			case G_TYPE_INT64:
-				type_name = "int8";
-				break;
-
-			case G_TYPE_DOUBLE:
-				type_name = "double precision";
-				break;
-
-			case G_TYPE_STRING:
-				type_name = "varchar";
-				break;
-
-			default:
-				PERR( "Unknown GType: %s\n", g_type_name( info->type ) );
-				type_name = "";
+		if( info->type == G_TYPE_INT ) {
+			if( info->is_autoinc ) {
+				type_name = "serial";
+			} else {
+				type_name = "integer";
+			}
+		} else if( info->type == G_TYPE_INT64 ) {
+			type_name = "int8";
+		} else if( info->type == G_TYPE_DOUBLE ) {
+			type_name = "double precision";
+		} else if( info->type == G_TYPE_STRING ) {
+			type_name = "varchar";
+		} else if( info->type == G_TYPE_DATE ) {
+			info->size = 0;
+			type_name = "date";
+		} else {
+			PERR( "Unknown GType: %s\n", g_type_name( info->type ) );
+			type_name = "";
 		}
 		g_string_append_printf( ddl, "%s %s", info->name, type_name );
     	if( info->size != 0 ) {

Modified: gnucash/trunk/src/backend/sql/gnc-account-sql.c
===================================================================
--- gnucash/trunk/src/backend/sql/gnc-account-sql.c	2009-08-13 00:05:37 UTC (rev 18246)
+++ gnucash/trunk/src/backend/sql/gnc-account-sql.c	2009-08-14 00:29:52 UTC (rev 18247)
@@ -231,7 +231,7 @@
 		   shrink to size 0. */
 		if( l_accounts_needing_parents != NULL ) {
 			gboolean progress_made = TRUE;
-	
+            Account* root;	
 			Account* pParent;
 			GList* elem;
 				
@@ -248,15 +248,13 @@
 				}
 			}
 	
-			/* Any accounts left over must be parented by the root account */
+			/* Any non-ROOT accounts left over must be parented by the root account */
+	        root = gnc_book_get_root_account( pBook );
 			for( elem = l_accounts_needing_parents; elem != NULL; elem = g_list_next( elem ) ) {
 				account_parent_guid_struct* s = (account_parent_guid_struct*)elem->data;
-	            Account* root;
-	            root = gnc_book_get_root_account( pBook );
-            	if( root == NULL ) {
-                	root = gnc_account_create_root( pBook );
-            	}
-            	gnc_account_append_child( root, s->pAccount ); 
+				if( xaccAccountGetType( s->pAccount ) != ACCT_TYPE_ROOT ) {
+            		gnc_account_append_child( root, s->pAccount ); 
+				}
 			}
 		}
 

Modified: gnucash/trunk/src/backend/sql/gnc-backend-sql.c
===================================================================
--- gnucash/trunk/src/backend/sql/gnc-backend-sql.c	2009-08-13 00:05:37 UTC (rev 18246)
+++ gnucash/trunk/src/backend/sql/gnc-backend-sql.c	2009-08-14 00:29:52 UTC (rev 18247)
@@ -998,7 +998,7 @@
 
 static GncSqlColumnInfo*
 create_column_info( const GncSqlColumnTableEntry* table_row, GType type,
-							gint size, gboolean is_unicode, gboolean is_autoinc )
+							gint size, gboolean is_unicode )
 {
 	GncSqlColumnInfo* info;
 
@@ -1010,7 +1010,7 @@
 	info->is_primary_key = ((table_row->flags & COL_PKEY) != 0) ? TRUE : FALSE;
 	info->null_allowed = ((table_row->flags & COL_NNUL) != 0) ? FALSE : TRUE;
 	info->is_unicode = is_unicode;
-	info->is_autoinc = is_autoinc;
+	info->is_autoinc = ((table_row->flags & COL_AUTOINC) != 0) ? TRUE : FALSE;
 
 	return info;
 }
@@ -1050,7 +1050,7 @@
 	g_return_if_fail( table_row != NULL );
 	g_return_if_fail( pList != NULL );
 
-	info = create_column_info( table_row, G_TYPE_STRING, table_row->size, TRUE, FALSE );
+	info = create_column_info( table_row, G_TYPE_STRING, table_row->size, TRUE );
 
 	*pList = g_list_append( *pList, info );
 }
@@ -1136,7 +1136,7 @@
 	g_return_if_fail( table_row != NULL );
 	g_return_if_fail( pList != NULL );
 
-	info = create_column_info( table_row, G_TYPE_INT, 0, FALSE, ((table_row->flags & COL_AUTOINC) != 0) );
+	info = create_column_info( table_row, G_TYPE_INT, 0, FALSE );
 
 	*pList = g_list_append( *pList, info );
 }
@@ -1220,7 +1220,7 @@
 	g_return_if_fail( table_row != NULL );
 	g_return_if_fail( pList != NULL );
 
-	info = create_column_info( table_row, G_TYPE_INT, 0, FALSE, FALSE );
+	info = create_column_info( table_row, G_TYPE_INT, 0, FALSE );
 
 	*pList = g_list_append( *pList, info );
 }
@@ -1297,7 +1297,7 @@
 	g_return_if_fail( table_row != NULL );
 	g_return_if_fail( pList != NULL );
 
-	info = create_column_info( table_row, G_TYPE_INT64, 0, FALSE, FALSE );
+	info = create_column_info( table_row, G_TYPE_INT64, 0, FALSE );
 
 	*pList = g_list_append( *pList, info );
 }
@@ -1376,7 +1376,7 @@
 	g_return_if_fail( table_row != NULL );
 	g_return_if_fail( pList != NULL );
 
-	info = create_column_info( table_row, G_TYPE_DOUBLE, 0, FALSE, FALSE );
+	info = create_column_info( table_row, G_TYPE_DOUBLE, 0, FALSE );
 
 	*pList = g_list_append( *pList, info );
 }
@@ -1461,7 +1461,7 @@
 	g_return_if_fail( table_row != NULL );
 	g_return_if_fail( pList != NULL );
 
-	info = create_column_info( table_row, G_TYPE_STRING, GUID_ENCODING_LENGTH, FALSE, FALSE );
+	info = create_column_info( table_row, G_TYPE_STRING, GUID_ENCODING_LENGTH, FALSE );
 
 	*pList = g_list_append( *pList, info );
 }
@@ -1627,7 +1627,7 @@
 	g_return_if_fail( table_row != NULL );
 	g_return_if_fail( pList != NULL );
 
-	info = create_column_info( table_row, G_TYPE_STRING, TIMESPEC_COL_SIZE, FALSE, FALSE );
+	info = create_column_info( table_row, G_TYPE_STRING, TIMESPEC_COL_SIZE, FALSE );
 
 	*pList = g_list_append( *pList, info );
 }
@@ -1725,7 +1725,7 @@
 	g_return_if_fail( table_row != NULL );
 	g_return_if_fail( pList != NULL );
 
-	info = create_column_info( table_row, G_TYPE_STRING, DATE_COL_SIZE, FALSE, FALSE );
+	info = create_column_info( table_row, G_TYPE_DATE, DATE_COL_SIZE, FALSE );
 
 	*pList = g_list_append( *pList, info );
 }



More information about the gnucash-changes mailing list