Ejemplo n.º 1
0
/* ================================================================= */
static void
create_taxtable_tables( GncSqlBackend* be )
{
    gint version;

    g_return_if_fail( be != NULL );

    version = gnc_sql_get_table_version( be, TT_TABLE_NAME );
    if ( version == 0 )
    {
        gnc_sql_create_table( be, TT_TABLE_NAME, TT_TABLE_VERSION, tt_col_table );
    }
    else if ( version == 1 )
    {
        /* Upgrade 64 bit int handling */
        gnc_sql_upgrade_table( be, TT_TABLE_NAME, tt_col_table );
        gnc_sql_set_table_version( be, TT_TABLE_NAME, TT_TABLE_VERSION );
    }

    version = gnc_sql_get_table_version( be, TTENTRIES_TABLE_NAME );
    if ( version == 0 )
    {
        gnc_sql_create_table( be, TTENTRIES_TABLE_NAME, TTENTRIES_TABLE_VERSION, ttentries_col_table );
    }
    else if ( version == 1 )
    {
        /* Upgrade 64 bit int handling */
        gnc_sql_upgrade_table( be, TTENTRIES_TABLE_NAME, ttentries_col_table );
        gnc_sql_set_table_version( be, TTENTRIES_TABLE_NAME, TTENTRIES_TABLE_VERSION );
    }
}
Ejemplo n.º 2
0
/* ================================================================= */
static void
upgrade_recurrence_table_1_2 ( GncSqlBackend* be )
{
    /* Step 1: add field, but allow it to be null */
    gboolean ok = gnc_sql_add_columns_to_table( be, TABLE_NAME, weekend_adjust_col_table );
    if ( !ok )
    {
        PERR( "Unable to add recurrence_weekend_adjust column\n" );
        return;
    }

    /* Step 2: insert a default value in the newly created column */
    {
        gchar *weekend_adj_str = recurrenceWeekendAdjustToString(WEEKEND_ADJ_NONE);
        gchar *update_query = g_strdup_printf ("UPDATE %s SET %s = '%s';",
                                               TABLE_NAME,
                                               weekend_adjust_col_table[0].col_name,
                                               weekend_adj_str);
        (void)gnc_sql_execute_nonselect_sql (be, update_query);
        g_free (weekend_adj_str);
        g_free (update_query);
    }

    /* Step 3: rewrite the table, requiring the weekend_adj column to be non-null */
    gnc_sql_upgrade_table( be, TABLE_NAME, col_table );

}
Ejemplo n.º 3
0
/* ================================================================= */
static void
create_lots_tables( GncSqlBackend* be )
{
    gint version;

    g_return_if_fail( be != NULL );

    version = gnc_sql_get_table_version( be, TABLE_NAME );
    if ( version == 0 )
    {
        /* The table doesn't exist, so create it */
        (void)gnc_sql_create_table( be, TABLE_NAME, TABLE_VERSION, col_table );
    }
    else if ( version == 1 )
    {
        /* Version 1 -> 2 removes the 'NOT NULL' constraint on the account_guid
        field.

        Create a temporary table, copy the data from the old table, delete the
        old table, then rename the new one. */

        gnc_sql_upgrade_table( be, TABLE_NAME, col_table );
        (void)gnc_sql_set_table_version( be, TABLE_NAME, TABLE_VERSION );

        PINFO("Lots table upgraded from version 1 to version %d\n", TABLE_VERSION);
    }
}
Ejemplo n.º 4
0
/* ================================================================= */
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);
    }
}
Ejemplo n.º 5
0
/* ================================================================= */
static void
create_prices_tables( GncSqlBackend* be )
{
    gint version;

    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 );
    }
    else if ( version == 1 )
    {
        /* Upgrade 64 bit int handling */
        gnc_sql_upgrade_table( be, TABLE_NAME, col_table );
        (void)gnc_sql_set_table_version( be, TABLE_NAME, TABLE_VERSION );
    }
}
Ejemplo n.º 6
0
/* ================================================================= */
static void
create_customer_tables( GncSqlBackend* be )
{
    gint version;

    g_return_if_fail( be != NULL );

    version = gnc_sql_get_table_version( be, TABLE_NAME );
    if ( version == 0 )
    {
        gnc_sql_create_table( be, TABLE_NAME, TABLE_VERSION, col_table );
    }
    else if ( version == 1 )
    {
        /* Upgrade 64 bit int handling */
        gnc_sql_upgrade_table( be, TABLE_NAME, col_table );
        gnc_sql_set_table_version( be, TABLE_NAME, TABLE_VERSION );

        PINFO("Customers table upgraded from version 1 to version %d\n", TABLE_VERSION);
    }
}
Ejemplo n.º 7
0
/* ================================================================= */
static void
create_invoice_tables( GncSqlBackend* be )
{
    gint version;

    g_return_if_fail( be != NULL );

    version = gnc_sql_get_table_version( be, TABLE_NAME );
    if ( version == 0 )
    {
        gnc_sql_create_table( be, TABLE_NAME, TABLE_VERSION, col_table );
    }
    else if ( version < TABLE_VERSION )
    {
        /* Upgrade:
             1->2: 64 bit int handling
        	 2->3: invoice open date can be NULL
        */
        gnc_sql_upgrade_table( be, TABLE_NAME, col_table );
        gnc_sql_set_table_version( be, TABLE_NAME, TABLE_VERSION );

        PINFO("Invoices table upgraded from version %d to version %d\n", version, TABLE_VERSION);
    }
}
Ejemplo n.º 8
0
/**
 * 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);
    }
}