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,24 +1387,17 @@ conn_create_table_ddl_sqlite3( GncSqlConnection* conn,
if( col_num != 0 ) {
(void)g_string_append( ddl, ", " );
}
switch( info->type ) {
case G_TYPE_INT:
if( info->type == G_TYPE_INT ) {
type_name = "integer";
break;
case G_TYPE_INT64:
} else if( info->type == G_TYPE_INT64 ) {
type_name = "bigint";
break;
case G_TYPE_DOUBLE:
} else if( info->type == G_TYPE_DOUBLE ) {
type_name = "real";
break;
case G_TYPE_STRING:
} else if( info->type == G_TYPE_STRING ) {
type_name = "text";
break;
default:
} else if( info->type == G_TYPE_DATE ) {
type_name = "text";
} else {
PERR( "Unknown GType: %s\n", g_type_name( info->type ) );
type_name = "";
}
@ -1449,24 +1442,18 @@ 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:
if( info->type == G_TYPE_INT ) {
type_name = "integer";
break;
case G_TYPE_INT64:
} else if( info->type == G_TYPE_INT64 ) {
type_name = "bigint";
break;
case G_TYPE_DOUBLE:
} else if( info->type == G_TYPE_DOUBLE ) {
type_name = "double";
break;
case G_TYPE_STRING:
} else if( info->type == G_TYPE_STRING ) {
type_name = "varchar";
break;
default:
} 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 = "";
}
@ -1515,28 +1502,22 @@ 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->type == G_TYPE_INT ) {
if( info->is_autoinc ) {
type_name = "sequence";
type_name = "serial";
} else {
type_name = "integer";
}
break;
case G_TYPE_INT64:
} else if( info->type == G_TYPE_INT64 ) {
type_name = "int8";
break;
case G_TYPE_DOUBLE:
} else if( info->type == G_TYPE_DOUBLE ) {
type_name = "double precision";
break;
case G_TYPE_STRING:
} else if( info->type == G_TYPE_STRING ) {
type_name = "varchar";
break;
default:
} 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 = "";
}

View File

@ -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,17 +248,15 @@ 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 );
}
if( xaccAccountGetType( s->pAccount ) != ACCT_TYPE_ROOT ) {
gnc_account_append_child( root, s->pAccount );
}
}
}
/* Load starting balances */
bal_slist = gnc_sql_get_account_balances_slist( be );

View File

@ -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 );
}