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.


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18247 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Phil Longstaff 2009-08-14 00:29:52 +00:00
parent e1318e0c1e
commit ae4199adfc
3 changed files with 61 additions and 82 deletions

View File

@ -1387,26 +1387,19 @@ conn_create_table_ddl_sqlite3( GncSqlConnection* conn,
if( col_num != 0 ) { if( col_num != 0 ) {
(void)g_string_append( ddl, ", " ); (void)g_string_append( ddl, ", " );
} }
switch( info->type ) { if( info->type == G_TYPE_INT ) {
case G_TYPE_INT: type_name = "integer";
type_name = "integer"; } else if( info->type == G_TYPE_INT64 ) {
break; type_name = "bigint";
} else if( info->type == G_TYPE_DOUBLE ) {
case G_TYPE_INT64: type_name = "real";
type_name = "bigint"; } else if( info->type == G_TYPE_STRING ) {
break; type_name = "text";
} else if( info->type == G_TYPE_DATE ) {
case G_TYPE_DOUBLE: type_name = "text";
type_name = "real"; } else {
break; PERR( "Unknown GType: %s\n", g_type_name( info->type ) );
type_name = "";
case G_TYPE_STRING:
type_name = "text";
break;
default:
PERR( "Unknown GType: %s\n", g_type_name( info->type ) );
type_name = "";
} }
g_string_append_printf( ddl, "%s %s", info->name, type_name ); g_string_append_printf( ddl, "%s %s", info->name, type_name );
if( info->size != 0 ) { if( info->size != 0 ) {
@ -1449,26 +1442,20 @@ conn_create_table_ddl_mysql( GncSqlConnection* conn, const gchar* table_name,
if( col_num != 0 ) { if( col_num != 0 ) {
(void)g_string_append( ddl, ", " ); (void)g_string_append( ddl, ", " );
} }
switch( info->type ) { if( info->type == G_TYPE_INT ) {
case G_TYPE_INT: type_name = "integer";
type_name = "integer"; } else if( info->type == G_TYPE_INT64 ) {
break; type_name = "bigint";
} else if( info->type == G_TYPE_DOUBLE ) {
case G_TYPE_INT64: type_name = "double";
type_name = "bigint"; } else if( info->type == G_TYPE_STRING ) {
break; type_name = "varchar";
} else if( info->type == G_TYPE_DATE ) {
case G_TYPE_DOUBLE: info->size = 0;
type_name = "double"; type_name = "date";
break; } else {
PERR( "Unknown GType: %s\n", g_type_name( info->type ) );
case G_TYPE_STRING: type_name = "";
type_name = "varchar";
break;
default:
PERR( "Unknown GType: %s\n", g_type_name( info->type ) );
type_name = "";
} }
g_string_append_printf( ddl, "%s %s", info->name, type_name ); g_string_append_printf( ddl, "%s %s", info->name, type_name );
if( info->size != 0 ) { if( info->size != 0 ) {
@ -1515,30 +1502,24 @@ conn_create_table_ddl_pgsql( GncSqlConnection* conn, const gchar* table_name,
if( col_num != 0 ) { if( col_num != 0 ) {
(void)g_string_append( ddl, ", " ); (void)g_string_append( ddl, ", " );
} }
switch( info->type ) { if( info->type == G_TYPE_INT ) {
case G_TYPE_INT: if( info->is_autoinc ) {
if( info->is_autoinc ) { type_name = "serial";
type_name = "sequence"; } else {
} else { type_name = "integer";
type_name = "integer"; }
} } else if( info->type == G_TYPE_INT64 ) {
break; type_name = "int8";
} else if( info->type == G_TYPE_DOUBLE ) {
case G_TYPE_INT64: type_name = "double precision";
type_name = "int8"; } else if( info->type == G_TYPE_STRING ) {
break; type_name = "varchar";
} else if( info->type == G_TYPE_DATE ) {
case G_TYPE_DOUBLE: info->size = 0;
type_name = "double precision"; type_name = "date";
break; } else {
PERR( "Unknown GType: %s\n", g_type_name( info->type ) );
case G_TYPE_STRING: type_name = "";
type_name = "varchar";
break;
default:
PERR( "Unknown GType: %s\n", g_type_name( info->type ) );
type_name = "";
} }
g_string_append_printf( ddl, "%s %s", info->name, type_name ); g_string_append_printf( ddl, "%s %s", info->name, type_name );
if( info->size != 0 ) { if( info->size != 0 ) {

View File

@ -231,7 +231,7 @@ load_all_accounts( GncSqlBackend* be )
shrink to size 0. */ shrink to size 0. */
if( l_accounts_needing_parents != NULL ) { if( l_accounts_needing_parents != NULL ) {
gboolean progress_made = TRUE; gboolean progress_made = TRUE;
Account* root;
Account* pParent; Account* pParent;
GList* elem; GList* elem;
@ -248,15 +248,13 @@ load_all_accounts( GncSqlBackend* be )
} }
} }
/* 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 ) ) { 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_parent_guid_struct* s = (account_parent_guid_struct*)elem->data;
Account* root; if( xaccAccountGetType( s->pAccount ) != ACCT_TYPE_ROOT ) {
root = gnc_book_get_root_account( pBook ); gnc_account_append_child( root, s->pAccount );
if( root == NULL ) { }
root = gnc_account_create_root( pBook );
}
gnc_account_append_child( root, s->pAccount );
} }
} }

View File

@ -998,7 +998,7 @@ gnc_sql_add_subtable_colnames_to_list( const GncSqlColumnTableEntry* table_row,
static GncSqlColumnInfo* static GncSqlColumnInfo*
create_column_info( const GncSqlColumnTableEntry* table_row, GType type, create_column_info( const GncSqlColumnTableEntry* table_row, GType type,
gint size, gboolean is_unicode, gboolean is_autoinc ) gint size, gboolean is_unicode )
{ {
GncSqlColumnInfo* info; GncSqlColumnInfo* info;
@ -1010,7 +1010,7 @@ create_column_info( const GncSqlColumnTableEntry* table_row, GType type,
info->is_primary_key = ((table_row->flags & COL_PKEY) != 0) ? TRUE : FALSE; info->is_primary_key = ((table_row->flags & COL_PKEY) != 0) ? TRUE : FALSE;
info->null_allowed = ((table_row->flags & COL_NNUL) != 0) ? FALSE : TRUE; info->null_allowed = ((table_row->flags & COL_NNUL) != 0) ? FALSE : TRUE;
info->is_unicode = is_unicode; info->is_unicode = is_unicode;
info->is_autoinc = is_autoinc; info->is_autoinc = ((table_row->flags & COL_AUTOINC) != 0) ? TRUE : FALSE;
return info; return info;
} }
@ -1050,7 +1050,7 @@ add_string_col_info_to_list( const GncSqlBackend* be, const GncSqlColumnTableEnt
g_return_if_fail( table_row != NULL ); g_return_if_fail( table_row != NULL );
g_return_if_fail( pList != 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 ); *pList = g_list_append( *pList, info );
} }
@ -1136,7 +1136,7 @@ add_int_col_info_to_list( const GncSqlBackend* be, const GncSqlColumnTableEntry*
g_return_if_fail( table_row != NULL ); g_return_if_fail( table_row != NULL );
g_return_if_fail( pList != 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 ); *pList = g_list_append( *pList, info );
} }
@ -1220,7 +1220,7 @@ add_boolean_col_info_to_list( const GncSqlBackend* be, const GncSqlColumnTableEn
g_return_if_fail( table_row != NULL ); g_return_if_fail( table_row != NULL );
g_return_if_fail( pList != 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 ); *pList = g_list_append( *pList, info );
} }
@ -1297,7 +1297,7 @@ add_int64_col_info_to_list( const GncSqlBackend* be, const GncSqlColumnTableEntr
g_return_if_fail( table_row != NULL ); g_return_if_fail( table_row != NULL );
g_return_if_fail( pList != 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 ); *pList = g_list_append( *pList, info );
} }
@ -1376,7 +1376,7 @@ add_double_col_info_to_list( const GncSqlBackend* be, const GncSqlColumnTableEnt
g_return_if_fail( table_row != NULL ); g_return_if_fail( table_row != NULL );
g_return_if_fail( pList != 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 ); *pList = g_list_append( *pList, info );
} }
@ -1461,7 +1461,7 @@ add_guid_col_info_to_list( const GncSqlBackend* be, const GncSqlColumnTableEntry
g_return_if_fail( table_row != NULL ); g_return_if_fail( table_row != NULL );
g_return_if_fail( pList != 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 ); *pList = g_list_append( *pList, info );
} }
@ -1627,7 +1627,7 @@ add_timespec_col_info_to_list( const GncSqlBackend* be, const GncSqlColumnTableE
g_return_if_fail( table_row != NULL ); g_return_if_fail( table_row != NULL );
g_return_if_fail( pList != 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 ); *pList = g_list_append( *pList, info );
} }
@ -1725,7 +1725,7 @@ add_date_col_info_to_list( const GncSqlBackend* be, const GncSqlColumnTableEntry
g_return_if_fail( table_row != NULL ); g_return_if_fail( table_row != NULL );
g_return_if_fail( pList != 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 ); *pList = g_list_append( *pList, info );
} }