/* for each entry, check the tax tables. If the tax tables are * grandchildren, then fix them to point to the most senior child */ static void taxtable_scrub_entries (QofInstance * entry_p, gpointer ht_p) { GHashTable *ht = static_cast<decltype(ht)>(ht_p); GncEntry *entry = GNC_ENTRY(entry_p); GncTaxTable *table, *new_tt; gint32 count; table = gncEntryGetInvTaxTable(entry); if (table) { if (taxtable_is_grandchild(table)) { gchar guidstr[GUID_ENCODING_LENGTH+1]; guid_to_string_buff(qof_instance_get_guid(QOF_INSTANCE(entry)),guidstr); PINFO("Fixing i-taxtable on entry %s\n",guidstr); new_tt = taxtable_find_senior(table); gncEntryBeginEdit(entry); gncEntrySetInvTaxTable(entry, new_tt); gncEntryCommitEdit(entry); table = new_tt; } if (table) { count = GPOINTER_TO_INT(g_hash_table_lookup(ht, table)); count++; g_hash_table_insert(ht, table, GINT_TO_POINTER(count)); } } table = gncEntryGetBillTaxTable(entry); if (table) { if (taxtable_is_grandchild(table)) { gchar guidstr[GUID_ENCODING_LENGTH+1]; guid_to_string_buff(qof_instance_get_guid(QOF_INSTANCE(entry)),guidstr); PINFO("Fixing b-taxtable on entry %s\n",guidstr); new_tt = taxtable_find_senior(table); gncEntryBeginEdit(entry); gncEntrySetBillTaxTable(entry, new_tt); gncEntryCommitEdit(entry); table = new_tt; } if (table) { count = GPOINTER_TO_INT(g_hash_table_lookup(ht, table)); count++; g_hash_table_insert(ht, table, GINT_TO_POINTER(count)); } } }
/* for each invoice, check the bill terms. If the bill terms are * grandchildren, then fix them to point to the most senior child */ static void billterm_scrub_invoices (QofInstance * invoice_p, gpointer ht_p) { GHashTable *ht = ht_p; GncInvoice *invoice = GNC_INVOICE(invoice_p); GncBillTerm *term, *new_bt; gint32 count; term = gncInvoiceGetTerms(invoice); if (term) { if (billterm_is_grandchild(term)) { gchar guidstr[GUID_ENCODING_LENGTH+1]; guid_to_string_buff(qof_instance_get_guid(QOF_INSTANCE(invoice)),guidstr); PWARN("Fixing i-billterm on invoice %s\n", guidstr); new_bt = billterm_find_senior(term); gncInvoiceBeginEdit(invoice); gncInvoiceSetTerms(invoice, new_bt); gncInvoiceCommitEdit(invoice); term = new_bt; } if (term) { count = GPOINTER_TO_INT(g_hash_table_lookup(ht, term)); count++; g_hash_table_insert(ht, term, GINT_TO_POINTER(count)); } } }
/******************************************************************** * get_custom_report_selection * * this helper function is called to get the selection when the user * clicks on "Run" or "Delete". Includes calling a dialog when there * is no selection. * * const gchar* message -- the message to provide user if there is no * actual selection found. *********************************************************************/ static SCM get_custom_report_selection(CustomReportDialog *crd, const gchar* message) { GtkTreeSelection *sel; GtkTreeModel *model; GtkTreeIter iter; GncGUID *guid = guid_malloc (); gchar *guid_str; sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(crd->reportview)); if (gtk_tree_selection_get_selected(sel, &model, &iter)) { gtk_tree_model_get(model, &iter, COL_NUM, &guid, -1); guid_str = g_new0 (gchar, GUID_ENCODING_LENGTH+1 ); guid_to_string_buff (guid, guid_str); } else { /* no selection, notify user */ gnc_error_dialog (GTK_WINDOW (crd->dialog), "%s", message); return SCM_EOL; } return scm_from_utf8_string (guid_str); }
/************************************************************** * custom_report_list_view_row_activated_cb * * this is the double-click signal. No need to call * get_custom_report_selection as the double-click implies the * selection. **************************************************************/ void custom_report_list_view_row_activated_cb(GtkTreeView *view, GtkTreePath *path, GtkTreeViewColumn *column, gpointer data) { CustomReportDialog *crd = data; GtkTreeModel *model; GtkTreeIter iter; model = gtk_tree_view_get_model(view); if (gtk_tree_model_get_iter(model, &iter, path)) { if (column == crd->namecol) { GncGUID *guid = guid_malloc (); gchar *guid_str; gtk_tree_model_get(model, &iter, COL_NUM, &guid, -1); guid_str = g_new0 (gchar, GUID_ENCODING_LENGTH+1 ); guid_to_string_buff (guid, guid_str); custom_report_run_report(scm_from_utf8_string (guid_str), crd); } } }
static void gnc_cm_event_handler (QofInstance *entity, QofEventId event_type, gpointer user_data, gpointer event_data) { const GncGUID *guid = qof_entity_get_guid(entity); #if CM_DEBUG gchar guidstr[GUID_ENCODING_LENGTH+1]; guid_to_string_buff (guid, guidstr); fprintf (stderr, "event_handler: event %d, entity %p, guid %s\n", event_type, entity, guidstr); #endif add_event (&changes, guid, event_type, TRUE); if (QOF_CHECK_TYPE(entity, GNC_ID_SPLIT)) { /* split events are never generated by the engine, but might * be generated by a backend (viz. the postgres backend.) * Handle them like a transaction modify event. */ add_event_type (&changes, GNC_ID_TRANS, QOF_EVENT_MODIFY, TRUE); } else add_event_type (&changes, entity->e_type, event_type, TRUE); got_events = TRUE; if (suspend_counter == 0) gnc_gui_refresh_internal (FALSE); }
static void load_taxtable_entries( GncSqlBackend* be, GncTaxTable* tt ) { GncSqlResult* result; gchar guid_buf[GUID_ENCODING_LENGTH+1]; GValue value; gchar* buf; GncSqlStatement* stmt; GError* error = NULL; g_return_if_fail( be != NULL ); g_return_if_fail( tt != NULL ); guid_to_string_buff( qof_instance_get_guid( QOF_INSTANCE(tt) ), guid_buf ); memset( &value, 0, sizeof( GValue ) ); g_value_init( &value, G_TYPE_STRING ); g_value_set_string( &value, guid_buf ); buf = g_strdup_printf( "SELECT * FROM %s WHERE taxtable='%s'", TTENTRIES_TABLE_NAME, guid_buf ); stmt = gnc_sql_connection_create_statement_from_sql( be->conn, buf ); g_free( buf ); result = gnc_sql_execute_select_statement( be, stmt ); gnc_sql_statement_dispose( stmt ); if ( result != NULL ) { GncSqlRow* row; row = gnc_sql_result_get_first_row( result ); while ( row != NULL ) { load_single_ttentry( be, row, tt ); row = gnc_sql_result_get_next_row( result ); } gnc_sql_result_dispose( result ); } }
static const char* equals_node_val_vs_splits (xmlNodePtr node, const Transaction* trn) { xmlNodePtr spl_node; Split* spl_mark; int i; g_return_val_if_fail (node, FALSE); g_return_val_if_fail (node->xmlChildrenNode, FALSE); for (i = 0, spl_mark = xaccTransGetSplit ((Transaction*)trn, i); spl_mark; i++, spl_mark = xaccTransGetSplit ((Transaction*)trn, i)) { spl_node = find_appropriate_node (node, spl_mark); if (!spl_node) { gchar guidstr[GUID_ENCODING_LENGTH + 1]; guid_to_string_buff (xaccSplitGetGUID (spl_mark), guidstr); g_print ("Split GUID %s", guidstr); return "no matching split found"; } const char* msg = equals_node_val_vs_split_internal (spl_node, spl_mark); if (msg != NULL) { return msg; } } return NULL; }
static void col_ref_cb (QofInstance* ref_ent, gpointer user_data) { QofInstanceReference *ref; QofInstanceCopyData *qecd; QofInstance *ent; const GncGUID *cm_guid; char cm_sa[GUID_ENCODING_LENGTH + 1]; gchar *cm_string; g_return_if_fail(user_data); qecd = (QofInstanceCopyData*)user_data; ent = qecd->from; g_return_if_fail(ent); ref = g_new0(QofInstanceReference, 1); ref->type = ent->e_type; ref->ref_guid = g_new(GncGUID, 1); ref->ent_guid = qof_instance_get_guid(ent); ref->param = qof_class_get_parameter(ent->e_type, qecd->param->param_name); cm_guid = qof_entity_get_guid(ref_ent); guid_to_string_buff(cm_guid, cm_sa); cm_string = g_strdup(cm_sa); if (TRUE == string_to_guid(cm_string, ref->ref_guid)) { g_free(cm_string); qof_session_update_reference_list(qecd->new_session, ref); } }
void gncBillTermDestroy (GncBillTerm *term) { gchar guidstr[GUID_ENCODING_LENGTH+1]; if (!term) return; guid_to_string_buff(qof_instance_get_guid(&term->inst),guidstr); DEBUG("destroying bill term %s (%p)", guidstr, term); qof_instance_set_destroying(term, TRUE); qof_instance_set_dirty (&term->inst); gncBillTermCommitEdit (term); }
Account* gnc_sx_get_template_transaction_account(SchedXaction *sx) { Account *template_root, *sx_template_acct; char sx_guid_str[GUID_ENCODING_LENGTH+1]; template_root = gnc_book_get_template_root(gnc_get_current_book()); guid_to_string_buff(xaccSchedXactionGetGUID(sx), sx_guid_str); sx_template_acct = gnc_account_lookup_by_name(template_root, sx_guid_str); return sx_template_acct; }
void qof_instance_print_dirty (const QofInstance *inst, gpointer dummy) { QofInstancePrivate *priv; priv = GET_PRIVATE(inst); if (priv->dirty) { gchar guidstr[GUID_ENCODING_LENGTH+1]; guid_to_string_buff(&priv->guid, guidstr); printf("%s instance %s is dirty.\n", inst->e_type, guidstr); } }
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; }
/** Save all persistent program state to disk. This function finds the * name of the "new" state file associated with a specific book guid. * It saves some top level data, then iterates through the list of * open windows calling a helper function to save each window. * * @note The name of the state file is based on the name of the data * file, not the path name of the data file. If there are multiple * data files with the same name, the state files will be suffixed * with a number. E.G. test_account, test_account_2, test_account_3, * etc. * * @param session The QofSession whose state should be saved. * * @param unused */ static void gnc_save_all_state (gpointer session, gpointer unused) { QofBook *book; gchar guid_string[GUID_ENCODING_LENGTH+1]; const GncGUID *guid; GKeyFile *keyfile = NULL; keyfile = gnc_state_get_current (); if (keyfile) { /* Remove existing Window and Page groups from the keyfile * They will be regenerated. */ gsize num_groups, curr; gchar **groups = g_key_file_get_groups (keyfile, &num_groups); for (curr=0; curr < num_groups; curr++) { if (g_str_has_prefix (groups[curr], "Window ") || g_str_has_prefix (groups[curr], "Page ")) { DEBUG ("Removing state group %s", groups[curr]); g_key_file_remove_group (keyfile, groups[curr], NULL); } } g_strfreev (groups); } /* Store the book's GncGUID in the top level group */ book = qof_session_get_book(session); guid = qof_entity_get_guid(QOF_INSTANCE(book)); guid_to_string_buff(guid, guid_string); g_key_file_set_string(keyfile, STATE_FILE_TOP, STATE_FILE_BOOK_GUID, guid_string); gnc_main_window_save_all_windows(keyfile); #ifdef DEBUG /* Debugging: dump a copy to the trace log */ { gchar *file_data; gsize file_length; file_data = g_key_file_to_data(keyfile, &file_length, NULL); DEBUG("=== File Data Written===\n%s\n=== File End ===\n", file_data); g_free(file_data); } #endif LEAVE(""); }
static void billterm_scrub_cust (QofInstance * cust_p, gpointer ht_p) { GHashTable *ht = ht_p; GncCustomer *cust = GNC_CUSTOMER(cust_p); GncBillTerm *term; gint32 count; term = gncCustomerGetTerms(cust); if (term) { count = GPOINTER_TO_INT(g_hash_table_lookup(ht, term)); count++; g_hash_table_insert(ht, term, GINT_TO_POINTER(count)); if (billterm_is_grandchild(term)) { gchar custstr[GUID_ENCODING_LENGTH+1]; gchar termstr[GUID_ENCODING_LENGTH+1]; guid_to_string_buff(qof_instance_get_guid(QOF_INSTANCE(cust)),custstr); guid_to_string_buff(qof_instance_get_guid(QOF_INSTANCE(term)),termstr); PWARN("customer %s has grandchild billterm %s\n", custstr,termstr); } } }
static void billterm_scrub_vendor (QofInstance * vendor_p, gpointer ht_p) { GHashTable *ht = ht_p; GncVendor *vendor = GNC_VENDOR(vendor_p); GncBillTerm *term; gint32 count; term = gncVendorGetTerms(vendor); if (term) { count = GPOINTER_TO_INT(g_hash_table_lookup(ht, term)); count++; g_hash_table_insert(ht, term, GINT_TO_POINTER(count)); if (billterm_is_grandchild(term)) { gchar vendstr[GUID_ENCODING_LENGTH+1]; gchar termstr[GUID_ENCODING_LENGTH+1]; guid_to_string_buff(qof_instance_get_guid(QOF_INSTANCE(vendor)),vendstr); guid_to_string_buff(qof_instance_get_guid(QOF_INSTANCE(term)),termstr); PWARN("vendor %s has grandchild billterm %s\n", vendstr, termstr); } } }
static void billterm_reset_refcount (gpointer key, gpointer value, gpointer notused) { GncBillTerm *term = key; gint32 count = GPOINTER_TO_INT(value); if (count != gncBillTermGetRefcount(term) && !gncBillTermGetInvisible(term)) { gchar termstr[GUID_ENCODING_LENGTH+1]; guid_to_string_buff(qof_instance_get_guid(QOF_INSTANCE(term)),termstr); PWARN("Fixing refcount on billterm %s (%" G_GINT64_FORMAT " -> %d)\n", termstr, gncBillTermGetRefcount(term), count); gncBillTermSetRefcount(term, count); } }
static void taxtable_reset_refcount (gpointer key, gpointer value, gpointer notused) { GncTaxTable *table = static_cast<decltype(table)>(key); gint32 count = GPOINTER_TO_INT(value); if (count != gncTaxTableGetRefcount(table) && !gncTaxTableGetInvisible(table)) { gchar guidstr[GUID_ENCODING_LENGTH+1]; guid_to_string_buff(qof_instance_get_guid(QOF_INSTANCE(table)),guidstr); PWARN("Fixing refcount on taxtable %s (%" G_GINT64_FORMAT " -> %d)\n", guidstr,gncTaxTableGetRefcount(table), count); gncTaxTableSetRefcount(table, count); } }
gboolean gnc_sql_slots_delete (GncSqlBackend* sql_be, const GncGUID* guid) { gchar* buf; gchar guid_buf[GUID_ENCODING_LENGTH + 1]; slot_info_t slot_info = { NULL, NULL, TRUE, NULL, KvpValue::Type::INVALID, NULL, FRAME, NULL, "" }; g_return_val_if_fail (sql_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, KvpValue::Type::FRAME, KvpValue::Type::GLIST); auto stmt = sql_be->create_statement_from_sql(buf); g_free (buf); if (stmt != nullptr) { auto result = sql_be->execute_select_statement(stmt); for (auto row : *result) { try { const GncSqlColumnTableEntryPtr table_row = col_table[guid_val_col]; GncGUID child_guid; auto val = row.get_string_at_col (table_row->name()); (void)string_to_guid (val.c_str(), &child_guid); gnc_sql_slots_delete (sql_be, &child_guid); } catch (std::invalid_argument) { continue; } } } slot_info.be = sql_be; slot_info.guid = guid; slot_info.is_ok = TRUE; slot_info.is_ok = sql_be->do_db_operation(OP_DB_DELETE, TABLE_NAME, TABLE_NAME, &slot_info, obj_guid_col_table); return slot_info.is_ok; }
static /*@ null @*/ Split* load_single_split( GncSqlBackend* be, GncSqlRow* row ) { const GncGUID* guid; GncGUID split_guid; Split* pSplit = NULL; gboolean bad_guid = FALSE; g_return_val_if_fail( be != NULL, NULL ); g_return_val_if_fail( row != NULL, NULL ); guid = gnc_sql_load_guid( be, row ); if ( guid == NULL ) return NULL; if (guid_equal(guid, guid_null())) { PWARN("Bad GUID, creating new"); bad_guid = TRUE; split_guid = guid_new_return(); } else { split_guid = *guid; pSplit = xaccSplitLookup( &split_guid, be->book ); } if ( pSplit == NULL ) { pSplit = xaccMallocSplit( be->book ); } /* If the split is dirty, don't overwrite it */ if ( !qof_instance_is_dirty( QOF_INSTANCE(pSplit) ) ) { gnc_sql_load_object( be, row, GNC_ID_SPLIT, pSplit, split_col_table ); } /*# -ifempty */ if (pSplit != xaccSplitLookup( &split_guid, be->book )) { gchar guidstr[GUID_ENCODING_LENGTH+1]; guid_to_string_buff(qof_instance_get_guid(pSplit), guidstr); PERR("A malformed split with id %s was found in the dataset.", guidstr); qof_backend_set_error( &be->be, ERR_BACKEND_DATA_CORRUPT); pSplit = NULL; } return pSplit; }
static GncSqlResultPtr gnc_sql_set_recurrences_from_db (GncSqlBackend* sql_be, const GncGUID* guid) { gchar* buf; gchar guid_buf[GUID_ENCODING_LENGTH + 1]; g_return_val_if_fail (sql_be != NULL, NULL); g_return_val_if_fail (guid != NULL, NULL); (void)guid_to_string_buff (guid, guid_buf); buf = g_strdup_printf ("SELECT * FROM %s WHERE obj_guid='%s'", TABLE_NAME, guid_buf); auto stmt = sql_be->create_statement_from_sql (buf); g_free (buf); auto result = sql_be->execute_select_statement(stmt); return result; }
static gboolean _get_template_split_account(GncSxInstance *instance, Split *template_split, Account **split_acct, GList **creation_errors) { GncGUID *acct_guid; kvp_frame *split_kvpf; kvp_value *kvp_val; split_kvpf = xaccSplitGetSlots(template_split); /* contains the guid of the split's actual account. */ kvp_val = kvp_frame_get_slot_path(split_kvpf, GNC_SX_ID, GNC_SX_ACCOUNT, NULL); if (kvp_val == NULL) { GString *err = g_string_new(""); g_string_printf(err, "Null account kvp value for SX [%s], cancelling creation.", xaccSchedXactionGetName(instance->parent->sx)); g_critical("%s", err->str); if (creation_errors != NULL) *creation_errors = g_list_append(*creation_errors, err); else g_string_free(err, TRUE); return FALSE; } acct_guid = kvp_value_get_guid( kvp_val ); *split_acct = xaccAccountLookup(acct_guid, gnc_get_current_book()); if (*split_acct == NULL) { char guid_str[GUID_ENCODING_LENGTH+1]; GString *err; guid_to_string_buff((const GncGUID*)acct_guid, guid_str); err = g_string_new(""); g_string_printf(err, "Unknown account for guid [%s], cancelling SX [%s] creation.", guid_str, xaccSchedXactionGetName(instance->parent->sx)); g_critical("%s", err->str); if (creation_errors != NULL) *creation_errors = g_list_append(*creation_errors, err); else g_string_free(err, TRUE); return FALSE; } return TRUE; }
/** * Deletes the budget amounts for a budget. * * @param sql_be SQL backend * @param budget Budget */ static gboolean delete_budget_amounts (GncSqlBackend* sql_be, GncBudget* budget) { gchar guid_buf[GUID_ENCODING_LENGTH + 1]; g_return_val_if_fail (sql_be != NULL, FALSE); g_return_val_if_fail (budget != NULL, FALSE); (void)guid_to_string_buff (qof_instance_get_guid (QOF_INSTANCE (budget)), guid_buf); std::stringstream sql; sql << "DELETE FROM " << AMOUNTS_TABLE << " WHERE budget_guid='"<< guid_buf << "'"; auto stmt = sql_be->create_statement_from_sql(sql.str()); sql_be->execute_nonselect_statement(stmt); return true; }
static /*@ null @*/ GncSqlResult* gnc_sql_set_recurrences_from_db( GncSqlBackend* be, const GncGUID* guid ) { gchar* buf; gchar guid_buf[GUID_ENCODING_LENGTH+1]; GncSqlStatement* stmt; GncSqlResult* result; g_return_val_if_fail( be != NULL, NULL ); g_return_val_if_fail( guid != NULL, NULL ); (void)guid_to_string_buff( guid, guid_buf ); buf = g_strdup_printf( "SELECT * FROM %s WHERE obj_guid='%s'", TABLE_NAME, guid_buf ); stmt = gnc_sql_connection_create_statement_from_sql( be->conn, buf ); g_free( buf ); result = gnc_sql_execute_select_statement( be, stmt ); gnc_sql_statement_dispose( stmt ); return result; }
xmlNodePtr guid_to_dom_tree(const char *tag, const GncGUID* gid) { char guid_str[GUID_ENCODING_LENGTH + 1]; xmlNodePtr ret; ret = xmlNewNode(NULL, BAD_CAST tag); xmlSetProp(ret, BAD_CAST "type", BAD_CAST "guid"); if (!guid_to_string_buff(gid, guid_str)) { PERR("guid_to_string_buff failed\n"); return NULL; } xmlNodeAddContent(ret, BAD_CAST guid_str); return ret; }
/********************************************************************\ * gnc_split_scm_set_account * * set the account of a scheme representation of a split. * * * * Args: split_scm - the scheme split * * account - the account to set * * Returns: Nothing * \********************************************************************/ void gnc_split_scm_set_account(SCM split_scm, Account *account) { gchar guid_string[GUID_ENCODING_LENGTH+1]; SCM arg; initialize_scm_functions(); if (!gnc_is_split_scm(split_scm)) return; if (account == NULL) return; guid_to_string_buff(xaccAccountGetGUID(account), guid_string); if (strlen(guid_string) == 0) return; arg = scm_from_utf8_string(guid_string); scm_call_2(setters.split_scm_account_guid, split_scm, arg); }
static void load_taxtable_entries (GncSqlBackend* sql_be, GncTaxTable* tt) { gchar guid_buf[GUID_ENCODING_LENGTH + 1]; GValue value; gchar* buf; g_return_if_fail (sql_be != NULL); g_return_if_fail (tt != NULL); guid_to_string_buff (qof_instance_get_guid (QOF_INSTANCE (tt)), guid_buf); memset (&value, 0, sizeof (GValue)); g_value_init (&value, G_TYPE_STRING); g_value_set_string (&value, guid_buf); buf = g_strdup_printf ("SELECT * FROM %s WHERE taxtable='%s'", TTENTRIES_TABLE_NAME, guid_buf); auto stmt = sql_be->create_statement_from_sql (buf); g_free (buf); auto result = sql_be->execute_select_statement(stmt); for (auto row : *result) load_single_ttentry (sql_be, row, tt); }
static void billterm_scrub (QofBook *book) { GList *list = NULL; GList *node; GncBillTerm *parent, *term; GHashTable *ht = g_hash_table_new(g_direct_hash, g_direct_equal); DEBUG("scrubbing billterms..."); qof_object_foreach (GNC_ID_INVOICE, book, billterm_scrub_invoices, ht); qof_object_foreach (GNC_ID_CUSTOMER, book, billterm_scrub_cust, ht); qof_object_foreach (GNC_ID_VENDOR, book, billterm_scrub_vendor, ht); qof_object_foreach (GNC_ID_BILLTERM, book, billterm_scrub_cb, &list); /* destroy the list of "grandchildren" bill terms */ for (node = list; node; node = node->next) { gchar termstr[GUID_ENCODING_LENGTH+1]; term = node->data; guid_to_string_buff(qof_instance_get_guid(QOF_INSTANCE(term)), termstr); PWARN ("deleting grandchild billterm: %s\n", termstr); /* Make sure the parent has no children */ parent = gncBillTermGetParent(term); gncBillTermSetChild(parent, NULL); /* Destroy this bill term */ gncBillTermBeginEdit(term); gncBillTermDestroy(term); } /* reset the refcounts as necessary */ g_hash_table_foreach(ht, billterm_reset_refcount, NULL); g_list_free(list); g_hash_table_destroy(ht); }
/** * Loads the budget amounts for a budget. * * @param sql_be SQL backend * @param budget Budget */ static void load_budget_amounts (GncSqlBackend* sql_be, GncBudget* budget) { gchar guid_buf[GUID_ENCODING_LENGTH + 1]; g_return_if_fail (sql_be != NULL); g_return_if_fail (budget != NULL); (void)guid_to_string_buff (qof_instance_get_guid (QOF_INSTANCE (budget)), guid_buf); auto sql = g_strdup_printf ("SELECT * FROM %s WHERE budget_guid='%s'", AMOUNTS_TABLE, guid_buf); auto stmt = sql_be->create_statement_from_sql(sql); g_free (sql); if (stmt != nullptr) { auto result = sql_be->execute_select_statement(stmt); budget_amount_info_t info = { budget, NULL, 0 }; for (auto row : *result) gnc_sql_load_object (sql_be, row, NULL, &info, budget_amounts_col_table); } }
/** * 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 ); } }
static void slots_load_info (slot_info_t* pInfo) { gchar guid_buf[GUID_ENCODING_LENGTH + 1]; g_return_if_fail (pInfo != NULL); g_return_if_fail (pInfo->be != NULL); g_return_if_fail (pInfo->guid != NULL); g_return_if_fail (pInfo->pKvpFrame != NULL); (void)guid_to_string_buff (pInfo->guid, guid_buf); std::stringstream buf; buf << "SELECT * FROM " << TABLE_NAME << " WHERE obj_guid='" << guid_buf << "'"; auto stmt = pInfo->be->create_statement_from_sql (buf.str()); if (stmt != nullptr) { auto result = pInfo->be->execute_select_statement (stmt); for (auto row : *result) load_slot (pInfo, row); } }