static void test_load_file(const char *filename) { QofSession *session; QofBook *book; Account *root; gboolean ignore_lock; gchar *logdomain = "GConf"; guint loglevel = G_LOG_LEVEL_WARNING; TestErrorStruct check = { loglevel, logdomain, NULL }; g_log_set_handler (logdomain, loglevel, (GLogFunc)test_checked_handler, &check); session = qof_session_new(); remove_locks(filename); ignore_lock = (safe_strcmp(g_getenv("SRCDIR"), ".") != 0); qof_session_begin(session, filename, ignore_lock, FALSE, TRUE); qof_session_load(session, NULL); book = qof_session_get_book (session); root = gnc_book_get_root_account(book); do_test (gnc_account_get_book (root) == book, "book and root account don't match"); do_test_args(qof_session_get_error(session) == ERR_BACKEND_NO_ERR, "session load xml2", __FILE__, __LINE__, "qof error=%d for file [%s]", qof_session_get_error(session), filename); /* Uncomment the line below to generate corrected files */ qof_session_save( session, NULL ); qof_session_end(session); }
static void gnc_plugin_business_cmd_export_employee (GtkAction *action, GncMainWindowActionData *mw) { QofSession *current_session, *chart_session; QofBook *book; QofCollection *coll; gchar *filename; gboolean success; current_session = gnc_get_current_session(); book = qof_session_get_book(current_session); chart_session = qof_session_new(); success = FALSE; filename = gnc_file_dialog(_("Export Employees to XML"), NULL, NULL, GNC_FILE_DIALOG_EXPORT); if (filename) { gchar* url = g_strdup_printf( "qsf:%s", filename ); qof_session_begin(chart_session, url, TRUE, TRUE); coll = qof_book_get_collection(book, GNC_ID_EMPLOYEE); success = qof_instance_copy_coll_r(chart_session, coll); if (success) { qof_session_save(chart_session, NULL); } g_free(url); } show_session_error(qof_session_get_error(chart_session), filename, GNC_FILE_DIALOG_EXPORT); qof_session_end(chart_session); g_free(filename); gnc_set_current_session(current_session); }
/* Given a synthetic session, use the same logic as * QofSession::save_as to save it to a specified sql url, then load it * back and compare. */ void test_dbi_store_and_reload( const gchar* driver, QofSession* session_1, const gchar* url ) { QofSession* session_2; QofSession* session_3; gchar *msg = "[gnc_dbi_unlock()] There was no lock entry in the Lock table"; gchar *log_domain = "gnc.backend.dbi"; guint loglevel = G_LOG_LEVEL_WARNING, hdlr; TestErrorStruct check = { loglevel, log_domain, msg }; g_test_message ( "Testing %s\n", driver ); // Save the session data session_2 = qof_session_new(); hdlr = g_log_set_handler (log_domain, loglevel, (GLogFunc)test_checked_handler, &check); qof_session_begin( session_2, url, FALSE, TRUE, TRUE ); if (session_2 && qof_session_get_error(session_2) != ERR_BACKEND_NO_ERR) { g_warning("Session Error: %d, %s", qof_session_get_error(session_2), qof_session_get_error_message(session_2)); do_test( FALSE, "First DB Session Creation Failed"); return; } qof_session_swap_data( session_1, session_2 ); qof_session_save( session_2, NULL ); if (session_2 && qof_session_get_error(session_2) != ERR_BACKEND_NO_ERR) { g_warning("Session Error: %s", qof_session_get_error_message(session_2)); do_test( FALSE, "First DB Session Save Failed"); return; } // Reload the session data session_3 = qof_session_new(); qof_session_begin( session_3, url, TRUE, FALSE, FALSE ); if (session_3 && qof_session_get_error(session_3) != ERR_BACKEND_NO_ERR) { g_warning("Session Error: %s", qof_session_get_error_message(session_3)); do_test( FALSE, "Second DB Session Creation Failed"); return; } qof_session_load( session_3, NULL ); if (session_3 && qof_session_get_error(session_3) != ERR_BACKEND_NO_ERR) { g_warning("Session Error: %s", qof_session_get_error_message(session_3)); do_test( FALSE, "Second DBI Session Load Failed"); return; } // Compare with the original data compare_books( qof_session_get_book( session_2 ), qof_session_get_book( session_3 ) ); qof_session_end( session_1 ); qof_session_destroy( session_1 ); qof_session_end( session_2 ); qof_session_destroy( session_2 ); qof_session_end( session_3 ); qof_session_destroy( session_3 ); g_log_remove_handler (log_domain, hdlr); }
static void inner_main_add_price_quotes(void *closure, int argc, char **argv) { SCM mod, add_quotes, scm_book, scm_result = SCM_BOOL_F; QofSession *session = NULL; scm_c_eval_string("(debug-set! stack 200000)"); mod = scm_c_resolve_module("gnucash price-quotes"); scm_set_current_module(mod); load_gnucash_modules(); qof_event_suspend(); scm_c_eval_string("(gnc:price-quotes-install-sources)"); if (!gnc_quote_source_fq_installed()) { g_print("%s", _("No quotes retrieved. Finance::Quote isn't " "installed properly.\n")); goto fail; } add_quotes = scm_c_eval_string("gnc:book-add-quotes"); session = gnc_get_current_session(); if (!session) goto fail; qof_session_begin(session, add_quotes_file, FALSE, FALSE); if (qof_session_get_error(session) != ERR_BACKEND_NO_ERR) goto fail; qof_session_load(session, NULL); if (qof_session_get_error(session) != ERR_BACKEND_NO_ERR) goto fail; scm_book = gnc_book_to_scm(qof_session_get_book(session)); scm_result = scm_call_2(add_quotes, SCM_BOOL_F, scm_book); qof_session_save(session, NULL); if (qof_session_get_error(session) != ERR_BACKEND_NO_ERR) goto fail; qof_session_destroy(session); if (!scm_is_true(scm_result)) { g_warning("Failed to add quotes to %s.", add_quotes_file); goto fail; } qof_event_resume(); gnc_shutdown(0); return; fail: if (session && qof_session_get_error(session) != ERR_BACKEND_NO_ERR) g_warning("Session Error: %s", qof_session_get_error_message(session)); qof_event_resume(); gnc_shutdown(1); }
/* Given a synthetic session, use the same logic as * QofSession::save_as to save it to a specified sql url, then load it * back and compare. */ void test_dbi_store_and_reload( const gchar* driver, QofSession* session_1, const gchar* url ) { QofSession* session_2; QofSession* session_3; printf( "Testing %s\n", driver ); // Save the session data session_2 = qof_session_new(); qof_session_begin( session_2, url, FALSE, TRUE, TRUE ); if (session_2 && qof_session_get_error(session_2) != ERR_BACKEND_NO_ERR) { g_warning("Session Error: %d, %s", qof_session_get_error(session_2), qof_session_get_error_message(session_2)); do_test( FALSE, "First DB Session Creation Failed"); return; } qof_session_swap_data( session_1, session_2 ); qof_session_save( session_2, NULL ); if (session_2 && qof_session_get_error(session_2) != ERR_BACKEND_NO_ERR) { g_warning("Session Error: %s", qof_session_get_error_message(session_2)); do_test( FALSE, "First DB Session Save Failed"); return; } // Reload the session data session_3 = qof_session_new(); qof_session_begin( session_3, url, TRUE, FALSE, FALSE ); if (session_3 && qof_session_get_error(session_3) != ERR_BACKEND_NO_ERR) { g_warning("Session Error: %s", qof_session_get_error_message(session_3)); do_test( FALSE, "Second DB Session Creation Failed"); return; } qof_session_load( session_3, NULL ); if (session_3 && qof_session_get_error(session_3) != ERR_BACKEND_NO_ERR) { g_warning("Session Error: %s", qof_session_get_error_message(session_3)); do_test( FALSE, "Second DBI Session Load Failed"); return; } // Compare with the original data compare_books( qof_session_get_book( session_2 ), qof_session_get_book( session_3 ) ); qof_session_end( session_1 ); qof_session_destroy( session_1 ); qof_session_end( session_2 ); qof_session_destroy( session_2 ); g_print(" You may ignore the warning about the lock file having no entries: We had to ignore locking to run two sessions on the same database\n"); qof_session_end( session_3 ); qof_session_destroy( session_3 ); }
int main() { qof_log_init(); qof_init(); gnc_module_system_init(); char * no_args[1] = { NULL }; gnc_engine_init(0, no_args); QofSession * s = qof_session_new(); qof_session_begin(s, "sqlite3:///tmp/blah.gnucash", 0, 1, 0); qof_session_load(s, NULL); qof_session_save(s, NULL); qof_session_end(s); return 0; }
int main() { const char* testurl = "sqlite3://" TESTFILE; qof_log_init(); qof_init(); gnc_module_system_init(); char * no_args[1] = { NULL }; gnc_engine_init(0, no_args); QofSession * s = qof_session_new(); qof_session_begin(s, testurl, 0, 1, 0); qof_session_load(s, NULL); qof_session_save(s, NULL); qof_session_end(s); unlink(TESTFILE); return 0; }
static gboolean gxi_save_file (GncXmlImportData *data) { QofBackendError io_err; g_return_val_if_fail (data && data->session, FALSE); gxi_update_progress_bar (_("Writing file..."), 0.0); qof_session_save (data->session, gxi_update_progress_bar); gxi_update_progress_bar (NULL, -1.0); io_err = qof_session_get_error (data->session); if (io_err == ERR_BACKEND_NO_ERR) { return TRUE; } else { gxi_session_destroy (data); return FALSE; } }
void test_dbi_business_store_and_reload( const gchar* driver, QofSession* session_1, const gchar* url ) { QofSession* session_2; QofSession* session_3; gchar *msg = "[gnc_dbi_unlock()] There was no lock entry in the Lock table"; gchar *log_domain = "gnc.backend.dbi"; guint loglevel = G_LOG_LEVEL_WARNING, hdlr; TestErrorStruct check = { loglevel, log_domain, msg }; g_test_message ( "Testing %s\n", driver ); // Save the session data session_2 = qof_session_new(); qof_session_begin( session_2, url, FALSE, TRUE, TRUE ); qof_session_swap_data( session_1, session_2 ); qof_session_save( session_2, NULL ); // Reload the session data session_3 = qof_session_new(); qof_session_begin( session_3, url, TRUE, FALSE, FALSE ); qof_session_load( session_3, NULL ); // Compare with the original data compare_books( qof_session_get_book( session_2 ), qof_session_get_book( session_3 ) ); qof_session_end( session_1 ); qof_session_destroy( session_1 ); qof_session_end( session_2 ); qof_session_destroy( session_2 ); hdlr = g_log_set_handler (log_domain, loglevel, (GLogFunc)test_checked_handler, &check); qof_session_end( session_3 ); g_log_remove_handler (log_domain, hdlr); qof_session_destroy( session_3 ); }
void save (QofPercentageFunc percentage_func) { qof_session_save(gobj(), percentage_func); }