/* ----------------------------------------------------------------- */ static void load_tx_guid( const GncSqlBackend* be, GncSqlRow* row, /*@ null @*/ QofSetterFunc setter, gpointer pObject, const GncSqlColumnTableEntry* table_row ) { const GValue* val; GncGUID guid; Transaction* tx; const gchar* guid_str; g_return_if_fail( be != NULL ); g_return_if_fail( row != NULL ); g_return_if_fail( pObject != NULL ); g_return_if_fail( table_row != NULL ); val = gnc_sql_row_get_value_at_col_name( row, table_row->col_name ); g_assert( val != NULL ); guid_str = g_value_get_string(val); if ( guid_str != NULL ) { (void)string_to_guid( guid_str, &guid ); tx = xaccTransLookup( &guid, be->book ); // If the transaction is not found, try loading it if ( tx == NULL ) { gchar* buf; GncSqlStatement* stmt; buf = g_strdup_printf( "SELECT * FROM %s WHERE guid='%s'", TRANSACTION_TABLE, guid_str ); stmt = gnc_sql_create_statement_from_sql( (GncSqlBackend*)be, buf ); g_free( buf ); query_transactions( (GncSqlBackend*)be, stmt ); tx = xaccTransLookup( &guid, be->book ); } if ( tx != NULL ) { if ( table_row->gobj_param_name != NULL ) { qof_instance_increase_editlevel (pObject); g_object_set( pObject, table_row->gobj_param_name, tx, NULL ); qof_instance_decrease_editlevel (pObject); } else { g_return_if_fail( setter != NULL ); (*setter)( pObject, (const gpointer)tx ); } } } }
/** * Loads all transactions. This might be used during a save-as operation to ensure that * all data is in memory and ready to be saved. * * @param be SQL backend */ void gnc_sql_transaction_load_all_tx( GncSqlBackend* be ) { gchar* query_sql; GncSqlStatement* stmt; g_return_if_fail( be != NULL ); query_sql = g_strdup_printf( "SELECT * FROM %s", TRANSACTION_TABLE ); stmt = gnc_sql_create_statement_from_sql( be, query_sql ); g_free( query_sql ); if ( stmt != NULL ) { query_transactions( be, stmt ); gnc_sql_statement_dispose( stmt ); } }
G_GNUC_UNUSED static void run_split_query( GncSqlBackend* be, gpointer pQuery ) { split_query_info_t* query_info = (split_query_info_t*)pQuery; g_return_if_fail( be != NULL ); g_return_if_fail( pQuery != NULL ); if ( !query_info->has_been_run ) { query_transactions( be, query_info->stmt ); query_info->has_been_run = TRUE; gnc_sql_statement_dispose( query_info->stmt ); query_info->stmt = NULL; } }
/** * Loads all transactions for an account. * * @param be SQL backend * @param account Account */ void gnc_sql_transaction_load_tx_for_account( GncSqlBackend* be, Account* account ) { const GncGUID* guid; gchar guid_buf[GUID_ENCODING_LENGTH+1]; gchar* query_sql; GncSqlStatement* stmt; g_return_if_fail( be != NULL ); g_return_if_fail( account != NULL ); guid = qof_instance_get_guid( QOF_INSTANCE(account) ); (void)guid_to_string_buff( guid, guid_buf ); query_sql = g_strdup_printf( "SELECT DISTINCT t.* FROM %s AS t, %s AS s WHERE s.tx_guid=t.guid AND s.account_guid ='%s'", TRANSACTION_TABLE, SPLIT_TABLE, guid_buf ); stmt = gnc_sql_create_statement_from_sql( be, query_sql ); g_free( query_sql ); if ( stmt != NULL ) { query_transactions( be, stmt ); gnc_sql_statement_dispose( stmt ); } }