diff --git a/src/backend/dbi/gnc-backend-dbi.c b/src/backend/dbi/gnc-backend-dbi.c index 16e90aece5..ef8e28f763 100644 --- a/src/backend/dbi/gnc-backend-dbi.c +++ b/src/backend/dbi/gnc-backend-dbi.c @@ -1387,26 +1387,19 @@ conn_create_table_ddl_sqlite3( GncSqlConnection* conn, 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 @@ conn_create_table_ddl_mysql( GncSqlConnection* conn, const gchar* table_name, 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 @@ conn_create_table_ddl_pgsql( GncSqlConnection* conn, const gchar* table_name, 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 ) { diff --git a/src/backend/sql/gnc-account-sql.c b/src/backend/sql/gnc-account-sql.c index 58e56b125d..c64890ef5d 100644 --- a/src/backend/sql/gnc-account-sql.c +++ b/src/backend/sql/gnc-account-sql.c @@ -231,7 +231,7 @@ load_all_accounts( GncSqlBackend* be ) shrink to size 0. */ if( l_accounts_needing_parents != NULL ) { gboolean progress_made = TRUE; - + Account* root; Account* pParent; 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 ) ) { 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 ); + } } } diff --git a/src/backend/sql/gnc-backend-sql.c b/src/backend/sql/gnc-backend-sql.c index 0daec9b82f..6007a5b45f 100644 --- a/src/backend/sql/gnc-backend-sql.c +++ b/src/backend/sql/gnc-backend-sql.c @@ -998,7 +998,7 @@ gnc_sql_add_subtable_colnames_to_list( const GncSqlColumnTableEntry* table_row, 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 @@ create_column_info( const GncSqlColumnTableEntry* table_row, GType type, 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 @@ add_string_col_info_to_list( const GncSqlBackend* be, const GncSqlColumnTableEnt 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 @@ add_int_col_info_to_list( const GncSqlBackend* be, const GncSqlColumnTableEntry* 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 @@ add_boolean_col_info_to_list( const GncSqlBackend* be, const GncSqlColumnTableEn 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 @@ add_int64_col_info_to_list( const GncSqlBackend* be, const GncSqlColumnTableEntr 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 @@ add_double_col_info_to_list( const GncSqlBackend* be, const GncSqlColumnTableEnt 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 @@ add_guid_col_info_to_list( const GncSqlBackend* be, const GncSqlColumnTableEntry 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 @@ add_timespec_col_info_to_list( const GncSqlBackend* be, const GncSqlColumnTableE 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 @@ add_date_col_info_to_list( const GncSqlBackend* be, const GncSqlColumnTableEntry 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 ); }