Exemplo n.º 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 );
    }
}
Exemplo n.º 2
0
void
gnc_sql_slots_load_for_instancevec (GncSqlBackend* sql_be, InstanceVec& instances)
{
    QofCollection* coll;
    std::stringstream sql;

    g_return_if_fail (sql_be != NULL);

    // Ignore empty list
    if (instances.empty()) return;

    coll = qof_instance_get_collection (instances[0]);

    // Create the query for all slots for all items on the list

    sql << "SELECT * FROM " << TABLE_NAME << " WHERE " <<
                            obj_guid_col_table[0]->name();
    if (instances.size() != 1)
        sql << " IN (";
    else
        sql << " = ";

    gnc_sql_append_guids_to_sql (sql, instances);
    if (instances.size() > 1)
        sql << ")";

    // Execute the query and load the slots
    auto stmt = sql_be->create_statement_from_sql(sql.str());
    if (stmt == nullptr)
    {
        PERR ("stmt == NULL, SQL = '%s'\n", sql.str().c_str());
        return;
    }
    auto result = sql_be->execute_select_statement (stmt);
    for (auto row : *result)
        load_slot_for_list_item (sql_be, row, coll);
}