Exemple #1
0
void
gnc_sql_slots_load_for_list( GncSqlBackend* be, GList* list )
{
    QofCollection* coll;
    GncSqlStatement* stmt;
    GString* sql;
    GncSqlResult* result;
    gboolean single_item;

    g_return_if_fail( be != NULL );

    // Ignore empty list
    if ( list == NULL ) return;

    coll = qof_instance_get_collection( QOF_INSTANCE(list->data) );

    // Create the query for all slots for all items on the list
    sql = g_string_sized_new( 40 + (GUID_ENCODING_LENGTH + 3) * g_list_length( list ) );
    g_string_append_printf( sql, "SELECT * FROM %s WHERE %s ", TABLE_NAME, obj_guid_col_table[0].col_name );
    if ( g_list_length( list ) != 1 )
    {
        (void)g_string_append( sql, "IN (" );
        single_item = FALSE;
    }
    else
    {
        (void)g_string_append( sql, "= " );
        single_item = TRUE;
    }
    (void)gnc_sql_append_guid_list_to_sql( sql, list, G_MAXUINT );
    if ( !single_item )
    {
        (void)g_string_append( sql, ")" );
    }

    // Execute the query and load the slots
    stmt = gnc_sql_create_statement_from_sql( be, sql->str );
    if ( stmt == NULL )
    {
        PERR( "stmt == NULL, SQL = '%s'\n", sql->str );
        (void)g_string_free( sql, TRUE );
        return;
    }
    (void)g_string_free( sql, TRUE );
    result = gnc_sql_execute_select_statement( be, stmt );
    gnc_sql_statement_dispose( stmt );
    if ( result != NULL )
    {
        GncSqlRow* row = gnc_sql_result_get_first_row( result );

        while ( row != NULL )
        {
            load_slot_for_list_item( be, row, coll );
            row = gnc_sql_result_get_next_row( result );
        }
        gnc_sql_result_dispose( result );
    }
}
static void
load_splits_for_tx_list (GncSqlBackend* be, GList* list)
{
    GString* sql;
    GncSqlResult* result;

    g_return_if_fail (be != NULL);

    if (list == NULL) return;

    sql = g_string_sized_new (40 + (GUID_ENCODING_LENGTH + 3) * g_list_length (
                                  list));
    g_string_append_printf (sql, "SELECT * FROM %s WHERE %s IN (", SPLIT_TABLE,
                            tx_guid_col_table[0].col_name);
    (void)gnc_sql_append_guid_list_to_sql (sql, list, G_MAXUINT);
    (void)g_string_append (sql, ")");

    // Execute the query and load the splits
    result = gnc_sql_execute_select_sql (be, sql->str);
    if (result != NULL)
    {
        GList* split_list = NULL;
        GncSqlRow* row;

        row = gnc_sql_result_get_first_row (result);
        while (row != NULL)
        {
            Split* s;
            s = load_single_split (be, row);
            if (s != NULL)
            {
                split_list = g_list_prepend (split_list, s);
            }
            row = gnc_sql_result_get_next_row (result);
        }

        if (split_list != NULL)
        {
            gnc_sql_slots_load_for_list (be, split_list);
            g_list_free (split_list);
        }

        gnc_sql_result_dispose (result);
    }
    (void)g_string_free (sql, TRUE);
}