/* ================================================================= */ static void create_slots_tables( GncSqlBackend* be ) { gint version; gboolean ok; g_return_if_fail( be != NULL ); version = gnc_sql_get_table_version( be, TABLE_NAME ); if ( version == 0 ) { (void)gnc_sql_create_table( be, TABLE_NAME, TABLE_VERSION, col_table ); ok = gnc_sql_create_index( be, "slots_guid_index", TABLE_NAME, obj_guid_col_table ); if ( !ok ) { PERR( "Unable to create index\n" ); } } else if ( version < TABLE_VERSION ) { /* Upgrade: 1->2: 64-bit int values to proper definition, add index 2->3: Add gdate field */ if ( version == 1 ) { gnc_sql_upgrade_table( be, TABLE_NAME, col_table ); ok = gnc_sql_create_index( be, "slots_guid_index", TABLE_NAME, obj_guid_col_table ); if ( !ok ) { PERR( "Unable to create index\n" ); } } else if ( version == 2 ) { ok = gnc_sql_add_columns_to_table( be, TABLE_NAME, gdate_col_table ); if ( !ok ) { PERR( "Unable to add gdate column\n" ); } } (void)gnc_sql_set_table_version( be, TABLE_NAME, TABLE_VERSION ); PINFO("Slots table upgraded from version %d to version %d\n", version, TABLE_VERSION); } }
/** * Creates the transaction and split tables. * * @param be SQL backend */ static void create_transaction_tables( GncSqlBackend* be ) { gint version; gboolean ok; g_return_if_fail( be != NULL ); version = gnc_sql_get_table_version( be, TRANSACTION_TABLE ); if ( version == 0 ) { (void)gnc_sql_create_table( be, TRANSACTION_TABLE, TX_TABLE_VERSION, tx_col_table ); ok = gnc_sql_create_index( be, "tx_post_date_index", TRANSACTION_TABLE, post_date_col_table ); if ( !ok ) { PERR( "Unable to create index\n" ); } } else if ( version < TX_TABLE_VERSION ) { /* Upgrade: 1->2: 64 bit int handling 2->3: allow dates to be NULL */ gnc_sql_upgrade_table( be, TRANSACTION_TABLE, tx_col_table ); (void)gnc_sql_set_table_version( be, TRANSACTION_TABLE, TX_TABLE_VERSION ); PINFO("Transactions table upgraded from version %d to version %d\n", version, TX_TABLE_VERSION); } version = gnc_sql_get_table_version( be, SPLIT_TABLE ); if ( version == 0 ) { (void)gnc_sql_create_table( be, SPLIT_TABLE, SPLIT_TABLE_VERSION, split_col_table ); ok = gnc_sql_create_index( be, "splits_tx_guid_index", SPLIT_TABLE, tx_guid_col_table ); if ( !ok ) { PERR( "Unable to create index\n" ); } ok = gnc_sql_create_index( be, "splits_account_guid_index", SPLIT_TABLE, account_guid_col_table ); if ( !ok ) { PERR( "Unable to create index\n" ); } } else if ( version < SPLIT_TABLE_VERSION ) { /* Upgrade: 1->2: 64 bit int handling 3->4: Split reconcile date can be NULL */ gnc_sql_upgrade_table( be, SPLIT_TABLE, split_col_table ); ok = gnc_sql_create_index( be, "splits_tx_guid_index", SPLIT_TABLE, tx_guid_col_table ); if ( !ok ) { PERR( "Unable to create index\n" ); } ok = gnc_sql_create_index( be, "splits_account_guid_index", SPLIT_TABLE, account_guid_col_table ); if ( !ok ) { PERR( "Unable to create index\n" ); } (void)gnc_sql_set_table_version( be, SPLIT_TABLE, SPLIT_TABLE_VERSION ); PINFO("Splits table upgraded from version %d to version %d\n", version, SPLIT_TABLE_VERSION); } }