/* ----------------------------------------------------------------- */ 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 ); } } } }
gboolean gnc_sql_slots_delete( GncSqlBackend* be, const GncGUID* guid ) { gchar* buf; GncSqlResult* result; gchar guid_buf[GUID_ENCODING_LENGTH + 1]; GncSqlStatement* stmt; slot_info_t slot_info = { NULL, NULL, TRUE, NULL, 0, NULL, FRAME, NULL, g_string_new('\0') }; g_return_val_if_fail( be != NULL, FALSE ); g_return_val_if_fail( guid != NULL, FALSE ); (void)guid_to_string_buff( guid, guid_buf ); buf = g_strdup_printf( "SELECT * FROM %s WHERE obj_guid='%s' and slot_type in ('%d', '%d') and not guid_val is null", TABLE_NAME, guid_buf, KVP_TYPE_FRAME, KVP_TYPE_GLIST ); stmt = gnc_sql_create_statement_from_sql( be, buf ); g_free( buf ); if ( stmt != NULL ) { 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 ) { GncSqlColumnTableEntry table_row = col_table[guid_val_col]; GncGUID child_guid; const GValue* val = gnc_sql_row_get_value_at_col_name( row, table_row.col_name); if ( val == NULL ) continue; (void)string_to_guid( g_value_get_string( val ), &child_guid ); gnc_sql_slots_delete( be, &child_guid ); row = gnc_sql_result_get_next_row( result ); } gnc_sql_result_dispose( result ); } } slot_info.be = be; slot_info.guid = guid; slot_info.is_ok = TRUE; slot_info.is_ok = gnc_sql_do_db_operation( be, OP_DB_DELETE, TABLE_NAME, TABLE_NAME, &slot_info, obj_guid_col_table ); return slot_info.is_ok; }
/* ================================================================= */ static void load_account_guid (const GncSqlBackend* be, GncSqlRow* row, QofSetterFunc setter, gpointer pObject, const GncSqlColumnTableEntry* table_row) { const GValue* val; GncGUID guid; Account* account = NULL; 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); if (val != NULL && G_VALUE_HOLDS_STRING (val) && g_value_get_string (val) != NULL) { (void)string_to_guid (g_value_get_string (val), &guid); account = xaccAccountLookup (&guid, be->book); if (account != NULL) { if (table_row->gobj_param_name != NULL) { qof_instance_increase_editlevel (pObject); g_object_set (pObject, table_row->gobj_param_name, account, NULL); qof_instance_decrease_editlevel (pObject); } else { g_return_if_fail (setter != NULL); (*setter) (pObject, (const gpointer)account); } } else { PWARN ("Account ref '%s' not found", g_value_get_string (val)); } } }
/* ================================================================= */ static void load_billterm_guid (const GncSqlBackend* be, GncSqlRow* row, QofSetterFunc setter, gpointer pObject, const GncSqlColumnTableEntry* table_row) { const GValue* val; GncGUID guid; GncBillTerm* term = NULL; 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); if (val != NULL && G_VALUE_HOLDS_STRING (val) && g_value_get_string (val) != NULL) { string_to_guid (g_value_get_string (val), &guid); term = gncBillTermLookup (be->book, &guid); if (term != NULL) { if (table_row->gobj_param_name != NULL) { qof_instance_increase_editlevel (pObject); g_object_set (pObject, table_row->gobj_param_name, term, NULL); qof_instance_decrease_editlevel (pObject); } else { (*setter) (pObject, (const gpointer)term); } } else { PWARN ("Billterm ref '%s' not found", g_value_get_string (val)); } } }
static void load_commodity_guid( const GncSqlBackend* be, GncSqlRow* row, /*@ null @*/ QofSetterFunc setter, gpointer pObject, const GncSqlColumnTableEntry* table_row ) { const GValue* val; GncGUID guid; gnc_commodity* commodity = NULL; 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 ); if ( val != NULL && G_VALUE_HOLDS_STRING( val ) && g_value_get_string( val ) != NULL ) { (void)string_to_guid( g_value_get_string( val ), &guid ); commodity = gnc_commodity_find_commodity_by_guid( &guid, be->book ); if ( commodity != NULL ) { if ( table_row->gobj_param_name != NULL ) { qof_instance_increase_editlevel (pObject); g_object_set( pObject, table_row->gobj_param_name, commodity, NULL ); qof_instance_decrease_editlevel (pObject); } else if ( setter != NULL ) { (*setter)( pObject, (const gpointer)commodity ); } } else { PWARN( "Commodity ref '%s' not found", g_value_get_string( val ) ); } } }
/* ================================================================= */ static void load_lot_guid( const GncSqlBackend* be, GncSqlRow* row, /*@ null @*/ QofSetterFunc setter, gpointer pObject, const GncSqlColumnTableEntry* table_row ) { const GValue* val; GncGUID guid; GNCLot* lot; 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 ); if ( val != NULL && G_VALUE_HOLDS_STRING( val ) && g_value_get_string( val ) != NULL ) { (void)string_to_guid( g_value_get_string( val ), &guid ); lot = gnc_lot_lookup( &guid, be->book ); if ( lot != NULL ) { if ( table_row->gobj_param_name != NULL ) { g_object_set( pObject, table_row->gobj_param_name, lot, NULL ); } else { g_return_if_fail( setter != NULL ); (*setter)( pObject, (const gpointer)lot ); } } else { PWARN( "Lot ref '%s' not found", g_value_get_string( val ) ); } } }
/* ================================================================= */ static void load_taxtable_guid( const GncSqlBackend* be, GncSqlRow* row, QofSetterFunc setter, gpointer pObject, const GncSqlColumnTableEntry* table_row ) { const GValue* val; GncGUID guid; GncTaxTable* taxtable = NULL; 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 ); if ( val != NULL && G_VALUE_HOLDS_STRING( val ) && g_value_get_string( val ) != NULL ) { string_to_guid( g_value_get_string( val ), &guid ); taxtable = gncTaxTableLookup( be->primary_book, &guid ); if ( taxtable != NULL ) { if ( table_row->gobj_param_name != NULL ) { g_object_set( pObject, table_row->gobj_param_name, taxtable, NULL ); } else { (*setter)( pObject, (const gpointer)taxtable ); } } else { PWARN( "Taxtable ref '%s' not found", g_value_get_string( val ) ); } } }
static void load_owner( const GncSqlBackend* be, GncSqlRow* row, QofSetterFunc setter, gpointer pObject, const GncSqlColumnTableEntry* table_row ) { const GValue* val; gchar* buf; GncOwnerType type; GncGUID guid; QofBook* book; GncOwner owner; GncGUID* pGuid = NULL; 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 ); book = be->primary_book; buf = g_strdup_printf( "%s_type", table_row->col_name ); val = gnc_sql_row_get_value_at_col_name( row, buf ); type = (GncOwnerType)gnc_sql_get_integer_value( val ); g_free( buf ); buf = g_strdup_printf( "%s_guid", table_row->col_name ); val = gnc_sql_row_get_value_at_col_name( row, buf ); g_free( buf ); if ( val != NULL && G_VALUE_HOLDS_STRING( val ) && g_value_get_string( val ) != NULL ) { string_to_guid( g_value_get_string( val ), &guid ); pGuid = &guid; } switch ( type ) { case GNC_OWNER_CUSTOMER: { GncCustomer *cust = NULL; if ( pGuid != NULL ) { cust = gncCustomerLookup( book, pGuid ); if ( cust == NULL ) { cust = gncCustomerCreate( book ); gncCustomerSetGUID( cust, &guid ); } } gncOwnerInitCustomer( &owner, cust ); break; } case GNC_OWNER_JOB: { GncJob *job = NULL; if ( pGuid != NULL ) { job = gncJobLookup( book, pGuid ); if ( job == NULL ) { job = gncJobCreate( book ); gncJobSetGUID( job, &guid ); } } gncOwnerInitJob( &owner, job ); break; } case GNC_OWNER_VENDOR: { GncVendor *vendor = NULL; if ( pGuid != NULL ) { vendor = gncVendorLookup( book, pGuid ); if ( vendor == NULL ) { vendor = gncVendorCreate( book ); gncVendorSetGUID( vendor, &guid ); } } gncOwnerInitVendor( &owner, vendor ); break; } case GNC_OWNER_EMPLOYEE: { GncEmployee *employee = NULL; if ( pGuid != NULL ) { employee = gncEmployeeLookup( book, pGuid ); if ( employee == NULL ) { employee = gncEmployeeCreate( book ); gncEmployeeSetGUID( employee, &guid ); } } gncOwnerInitEmployee( &owner, employee ); break; } default: PWARN("Invalid owner type: %d\n", type ); } if ( table_row->gobj_param_name != NULL ) { g_object_set( pObject, table_row->gobj_param_name, &owner, NULL ); } else { (*setter)( pObject, &owner ); } }