int main (int argc, char ** argv) { gchar* filename; QofSession* session_1; qof_init(); cashobjects_register(); qof_load_backend_library ("../.libs/", GNC_LIB_NAME); // Create a session with data session_1 = create_session(); filename = tempnam( "/tmp", "test-sqlite3-" ); printf( "Using filename: %s\n", filename ); test_dbi_store_and_reload( "sqlite3", session_1, filename ); #if 0 printf( "TEST_MYSQL_URL='%s'\n", TEST_MYSQL_URL ); if ( strlen( TEST_MYSQL_URL ) > 0 ) { session_1 = create_session(); test_dbi_store_and_reload( "mysql", session_1, TEST_MYSQL_URL ); } printf( "TEST_PGSQL_URL='%s'\n", TEST_PGSQL_URL ); if ( strlen( TEST_PGSQL_URL ) > 0 ) { session_1 = create_session(); test_dbi_store_and_reload( "pgsql", session_1, TEST_PGSQL_URL ); } #endif print_test_results(); qof_close(); exit(get_rv()); }
static void gnc_engine_init_part2() { static struct { const gchar* subdir; const gchar* lib; gboolean required; } libs[] = { #if defined( HAVE_DBI_DBI_H ) { "dbi", "gncmod-backend-dbi", TRUE }, #endif { "xml", "gncmod-backend-xml", TRUE }, { NULL, NULL, FALSE } }, *lib; for (lib = libs; lib->lib ; lib++) { if (qof_load_backend_library(lib->subdir, lib->lib)) { engine_is_initialized = 1; } else { g_warning("failed to load %s from relative path %s\n", lib->lib, lib->subdir); /* If this is a required library, stop now! */ if (lib->required) { g_critical("required library %s not found.\n", lib->lib); } } } }
int main (int argc, char* argv[]) { qof_init (); /* equally initializes gobject system */ qof_log_init_filename_special ("stderr"); /* Init the log system */ g_test_init (&argc, &argv, NULL); /* initialize test program */ g_test_bug_base ("https://bugzilla.gnome.org/show_bug.cgi?id="); /* init the bugzilla URL */ cashobjects_register (); g_assert (qof_load_backend_library ("../.libs/", GNC_LIB_NAME)); g_assert (qof_load_backend_library ("../../xml/.libs", "gncmod-backend-xml")); test_suite_gnc_backend_dbi (); return g_test_run (); }
int main (int argc, char ** argv) { const char *location = g_getenv("GNC_TEST_FILES"); int files_tested = 0; GDir *xml2_dir; qof_init(); cashobjects_register(); do_test(qof_load_backend_library ("../.libs/", GNC_LIB_NAME), " loading gnc-backend-xml GModule failed"); if (!location) { location = "test-files/xml2"; } xaccLogDisable(); if ((xml2_dir = g_dir_open(location, 0, NULL)) == NULL) { failure("unable to open xml2 directory"); } else { const gchar *entry; while ((entry = g_dir_read_name(xml2_dir)) != NULL) { if (g_str_has_suffix(entry, ".gml2")) { gchar *to_open = g_build_filename(location, entry, (gchar*)NULL); if (!g_file_test(to_open, G_FILE_TEST_IS_DIR)) { test_load_file(to_open); files_tested++; } g_free(to_open); } } } g_dir_close(xml2_dir); if (files_tested == 0) { failure("handled 0 files in test-load-xml2"); } print_test_results(); qof_close(); exit(get_rv()); }
void qof_session_save (QofSession *session, QofPercentageFunc percentage_func) { GList *node; QofBackend *be; gboolean partial, change_backend; QofBackendProvider *prov; GSList *p; QofBook *book, *abook; int err; gint num; char *msg = NULL; char *book_id; if (!session) return; if (!g_atomic_int_dec_and_test(&session->lock)) goto leave; ENTER ("sess=%p book_id=%s", session, session->book_id ? session->book_id : "(null)"); /* Partial book handling. */ book = qof_session_get_book(session); partial = (gboolean)GPOINTER_TO_INT(qof_book_get_data(book, PARTIAL_QOFBOOK)); change_backend = FALSE; msg = g_strdup_printf(" "); book_id = g_strdup(session->book_id); if (partial == TRUE) { if (session->backend && session->backend->provider) { prov = session->backend->provider; if (TRUE == prov->partial_book_supported) { /* if current backend supports partial, leave alone. */ change_backend = FALSE; } else { change_backend = TRUE; } } /* If provider is undefined, assume partial not supported. */ else { change_backend = TRUE; } } if (change_backend == TRUE) { qof_session_destroy_backend(session); if (!qof_providers_initialized) { for (num = 0; backend_list[num].filename != NULL; num++) { qof_load_backend_library(backend_list[num].libdir, backend_list[num].filename); } qof_providers_initialized = TRUE; } p = provider_list; while (p != NULL) { prov = p->data; if (TRUE == prov->partial_book_supported) { /** \todo check the access_method too, not in scope here, yet. */ /* if((TRUE == prov->partial_book_supported) && (0 == g_ascii_strcasecmp (access_method, prov->access_method))) {*/ if (NULL == prov->backend_new) continue; /* Use the providers creation callback */ session->backend = (*(prov->backend_new))(); session->backend->provider = prov; if (session->backend->session_begin) { /* Call begin - backend has been changed, so make sure a file can be written, use ignore_lock and create_if_nonexistent */ g_free(session->book_id); session->book_id = NULL; (session->backend->session_begin)(session->backend, session, book_id, TRUE, TRUE); PINFO("Done running session_begin on changed backend"); err = qof_backend_get_error(session->backend); msg = qof_backend_get_message(session->backend); if (err != ERR_BACKEND_NO_ERR) { g_free(session->book_id); session->book_id = NULL; qof_session_push_error (session, err, msg); LEAVE("changed backend error %d", err); goto leave; } if (msg != NULL) { PWARN("%s", msg); g_free(msg); msg = NULL; } } /* Tell the books about the backend that they'll be using. */ for (node = session->books; node; node = node->next) { book = node->data; qof_book_set_backend (book, session->backend); } p = NULL; } if (p) { p = p->next; } } if (!session->backend) { msg = g_strdup_printf("failed to load backend"); qof_session_push_error(session, ERR_BACKEND_NO_HANDLER, msg); goto leave; } } /* If there is a backend, and the backend is reachable * (i.e. we can communicate with it), then synchronize with * the backend. If we cannot contact the backend (e.g. * because we've gone offline, the network has crashed, etc.) * then give the user the option to save to the local disk. * * hack alert -- FIXME -- XXX the code below no longer * does what the words above say. This needs fixing. */ be = session->backend; if (be) { for (node = session->books; node; node = node->next) { abook = node->data; /* if invoked as SaveAs(), then backend not yet set */ qof_book_set_backend (abook, be); be->percentage = percentage_func; if (be->sync) { (be->sync)(be, abook); if (save_error_handler(be, session)) goto leave; } } /* If we got to here, then the backend saved everything * just fine, and we are done. So return. */ /* Return the book_id to previous value. */ qof_session_clear_error (session); LEAVE("Success"); goto leave; } else { msg = g_strdup_printf("failed to load backend"); qof_session_push_error(session, ERR_BACKEND_NO_HANDLER, msg); } LEAVE("error -- No backend!"); leave: if (msg != NULL) g_free(msg); g_atomic_int_inc(&session->lock); return; }
static void qof_session_load_backend(QofSession * session, const char * access_method) { GSList *p; GList *node; QofBackendProvider *prov; QofBook *book; char *msg; gint num; gboolean prov_type; gboolean (*type_check) (const char*); gchar *libdir_from_env = NULL; ENTER (" list=%d, initted=%s", g_slist_length(provider_list), qof_providers_initialized ? "true" : "false"); prov_type = FALSE; if (!qof_providers_initialized) { libdir_from_env = g_strdup(g_getenv("QOF_LIB_DIR")); for (num = 0; backend_list[num].filename != NULL; num++) { if (libdir_from_env) { if (!(qof_load_backend_library(libdir_from_env, backend_list[num].filename) || qof_load_backend_library(backend_list[num].libdir, backend_list[num].filename))) { PWARN (" failed to load %s from %s or %s", backend_list[num].filename, libdir_from_env, backend_list[num].libdir); } } else { if (!qof_load_backend_library(backend_list[num].libdir, backend_list[num].filename)) { PWARN (" failed to load %s from %s", backend_list[num].filename, backend_list[num].libdir); } } } g_free(libdir_from_env); qof_providers_initialized = TRUE; } p = provider_list; while (p != NULL) { prov = p->data; /* Does this provider handle the desired access method? */ if (0 == g_ascii_strcasecmp (access_method, prov->access_method)) { /* More than one backend could provide this access method, check file type compatibility. */ type_check = (gboolean (*)(const char*)) prov->check_data_type; if (type_check) { prov_type = (type_check)(session->book_id); if (!prov_type) { PINFO(" %s not usable", prov->provider_name); p = p->next; continue; } } PINFO (" selected %s", prov->provider_name); if (NULL == prov->backend_new) { p = p->next; continue; } /* Use the providers creation callback */ session->backend = (*(prov->backend_new))(); session->backend->provider = prov; /* Tell the books about the backend that they'll be using. */ for (node = session->books; node; node = node->next) { book = node->data; qof_book_set_backend (book, session->backend); } LEAVE (" "); return; } p = p->next; } msg = g_strdup_printf("failed to load '%s' using access_method", access_method); qof_session_push_error (session, ERR_BACKEND_NO_HANDLER, msg); LEAVE (" "); }