Merge 'misc-backend' -r 14160:14184 into trunk.

This includes the now semi-functional postgres backend.


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@14198 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Chris Shoemaker
2006-05-26 00:10:35 +00:00
parent a98cfaf58d
commit 97062a3b81
39 changed files with 306 additions and 229 deletions
+1
View File
@@ -14,6 +14,7 @@ libgncqof_backend_qsf_la_SOURCES = \
qsf-xml-map.c \
qsf-xml.c
libgncqof_backend_qsf_la_LDFLAGS = -module
libgncqof_backend_qsf_la_LIBADD = \
${QOF_LIBS} \
${GLIB_LIBS} \
+3 -1
View File
@@ -139,6 +139,7 @@ Check the QofBackendError - don't assume the file is OK.
#ifndef _QOF_BACKEND_QSF_H
#define _QOF_BACKEND_QSF_H
#include <gmodule.h>
#include "qoflog.h"
#include "qofbackend.h"
@@ -162,7 +163,8 @@ default values for the QofBackendOption KvpFrame.
Calls gettext because QofBackendOption
strings are translatable.
*/
void qsf_provider_init(void);
G_MODULE_EXPORT const gchar *
g_module_check_init(GModule *module);
/** \name Supported backend configurations
@{
+4 -8
View File
@@ -24,6 +24,7 @@
#include "config.h"
#include <glib.h>
#include "qof.h"
#include "qofbackend-p.h"
#include "qof-backend-qsf.h"
#include <libxml/xmlmemory.h>
#include <libxml/tree.h>
@@ -1269,17 +1270,11 @@ qsf_provider_free (QofBackendProvider *prov)
g_free (prov);
}
void
qsf_provider_init(void)
G_MODULE_EXPORT const gchar *
g_module_check_init(GModule *module)
{
QofBackendProvider *prov;
/* #ifdef ENABLE_NLS
setlocale (LC_ALL, "");
bindtextdomain (GETTEXT_PACKAGE, LOCALE_DIR);
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
textdomain (GETTEXT_PACKAGE);
#endif*/
prov = g_new0 (QofBackendProvider, 1);
prov->provider_name = "QSF Backend Version 0.2";
prov->access_method = "file";
@@ -1288,4 +1283,5 @@ qsf_provider_init(void)
prov->check_data_type = qsf_determine_file_type;
prov->provider_free = qsf_provider_free;
qof_backend_register_provider (prov);
return NULL;
}
+5 -8
View File
@@ -122,16 +122,13 @@ guid_null(void)
static int null_inited = 0;
static GUID null_guid;
if (!null_inited)
{
int i;
char *tmp = "NULLGUID.EMPTY.";
if (!null_inited) {
int i;
/* 16th space for '\O' */
for (i = 0; i < GUID_DATA_SIZE; i++)
null_guid.data[i] = tmp[i];
for (i = 0; i < GUID_DATA_SIZE; i++)
null_guid.data[i] = '\0';
null_inited = 1;
null_inited = 1;
}
return &null_guid;
+1 -3
View File
@@ -106,8 +106,6 @@
/** allow easy logging of QSF debug messages */
#define QOF_MOD_QSF "gncqof-backend-qsf"
/** allow easy loading of the QSF backend */
#define QSF_BACKEND_LIB "libgncqof-backend-qsf"
/** allow easy loading of the QSF backend */
#define QSF_MODULE_INIT "qsf_provider_init"
#define QSF_BACKEND_LIB "gncqof-backend-qsf"
#endif /* QOF_H_ */
+1 -10
View File
@@ -182,7 +182,7 @@
* pointer to the second book, where the results of the query
* should go.
*
* Cann the book commit() to complete the book partitioning.
* Call the book commit() to complete the book partitioning.
*
* After the begin(), there will be a call to run_query(), followed
* probably by a string of object calls, and completed by commit().
@@ -367,15 +367,6 @@ struct QofBackend_s
*/
void qof_backend_register_provider (QofBackendProvider *);
/** The qof_backend_set_error() routine pushes an error code onto the error
* stack. (FIXME: the stack is 1 deep in current implementation).
*/
void qof_backend_set_error (QofBackend *be, QofBackendError err);
/** The qof_backend_get_error() routine pops an error code off the error stack.
*/
QofBackendError qof_backend_get_error (QofBackend *be);
/** The qof_backend_set_message() assigns a string to the backend error message.
*/
void qof_backend_set_message(QofBackend *be, const char *format, ...);
+9 -20
View File
@@ -128,7 +128,7 @@ qof_backend_init(QofBackend *be)
be->run_query = NULL;
be->sync = NULL;
be->load_config = NULL;
be->load_config = NULL;
be->events_pending = NULL;
be->process_events = NULL;
@@ -137,11 +137,11 @@ qof_backend_init(QofBackend *be)
if (be->error_msg) g_free (be->error_msg);
be->error_msg = NULL;
be->percentage = NULL;
be->backend_configuration = kvp_frame_new();
/* to be removed */
be->price_lookup = NULL;
be->export = NULL;
be->backend_configuration = kvp_frame_new();
/* to be removed */
be->price_lookup = NULL;
be->export = NULL;
}
void
@@ -384,30 +384,19 @@ qof_backend_commit_exists(QofBackend *be)
}
gboolean
qof_load_backend_library (const char *directory,
const char* filename, const char* init_fcn)
qof_load_backend_library (const char *directory, const char* module_name)
{
gchar *fullpath;
typedef void (* backend_init) (void);
GModule *backend;
backend_init gmod_init;
gpointer g;
g_return_val_if_fail(g_module_supported(), FALSE);
fullpath = g_module_build_path(directory, filename);
fullpath = g_module_build_path(directory, module_name);
backend = g_module_open(fullpath, G_MODULE_BIND_LAZY);
if(!backend) {
g_message ("%s: %s\n", PACKAGE, g_module_error ());
return FALSE;
}
g = &gmod_init;
if (!g_module_symbol (backend, init_fcn, g))
{
if (!backend) {
g_message ("%s: %s\n", PACKAGE, g_module_error ());
return FALSE;
}
g_module_make_resident(backend);
gmod_init();
return TRUE;
}
+11 -4
View File
@@ -177,6 +177,15 @@ void qof_backend_run_commit(QofBackend *be, QofInstance *inst);
gboolean qof_backend_commit_exists(QofBackend *be);
//@}
/** The qof_backend_set_error() routine pushes an error code onto the error
* stack. (FIXME: the stack is 1 deep in current implementation).
*/
void qof_backend_set_error (QofBackend *be, QofBackendError err);
/** The qof_backend_get_error() routine pops an error code off the error stack.
*/
QofBackendError qof_backend_get_error (QofBackend *be);
/** @name Backend Configuration using KVP
The backend uses qof_backend_get_config to pass back a KvpFrame of QofBackendOption
@@ -254,16 +263,14 @@ KvpFrame* qof_backend_get_config(QofBackend *be);
/** \brief Load a QOF-compatible backend shared library.
\param directory Can be NULL if filename is a complete path.
\param filename Name of the .la file that describes the
\param module_name Name of the .la file that describes the
shared library. This provides platform independence,
courtesy of libtool.
\param init_fcn The QofBackendProvider init function.
\return FALSE in case or error, otherwise TRUE.
*/
gboolean
qof_load_backend_library (const gchar *directory,
const gchar* filename, const gchar* init_fcn);
qof_load_backend_library(const gchar *directory, const gchar* module_name);
/** \brief Retrieve the backend used by this book */
QofBackend* qof_book_get_backend (QofBook *book);
+1 -1
View File
@@ -139,7 +139,7 @@ qof_book_equal (QofBook *book_1, QofBook *book_2)
{
if (book_1 == book_2) return TRUE;
if (!book_1 || !book_2) return FALSE;
return TRUE;
return FALSE;
}
/* ====================================================================== */
-3
View File
@@ -70,7 +70,4 @@ QofBackend * qof_session_get_backend (QofSession *session);
void qof_session_push_error (QofSession *session, QofBackendError err,
const char *message);
QofBackend* gncBackendInit_file(const char *book_id, void *data);
#endif
+59 -17
View File
@@ -843,7 +843,6 @@ struct backend_providers
{
const char *libdir;
const char *filename;
const char *init_fcn;
};
/* All available QOF backends need to be described here
@@ -851,11 +850,11 @@ and the last entry must be three NULL's.
Remember: Use the libdir from the current build environment
and use JUST the module name without .so - .so is not portable! */
struct backend_providers backend_list[] = {
{ QOF_LIB_DIR, QSF_BACKEND_LIB, QSF_MODULE_INIT },
{ QOF_LIB_DIR, QSF_BACKEND_LIB },
#ifdef HAVE_DWI
{ QOF_LIB_DIR, "libqof_backend_dwi", "dwiend_provider_init" },
{ QOF_LIB_DIR, "libqof_backend_dwi"},
#endif
{ NULL, NULL, NULL }
{ NULL, NULL }
};
static void
@@ -876,11 +875,10 @@ qof_session_load_backend(QofSession * session, char * access_method)
{
for (num = 0; backend_list[num].filename != NULL; num++) {
if(!qof_load_backend_library(backend_list[num].libdir,
backend_list[num].filename, backend_list[num].init_fcn))
backend_list[num].filename))
{
PWARN (" failed to load %s from %s using %s",
backend_list[num].filename, backend_list[num].libdir,
backend_list[num].init_fcn);
PWARN (" failed to load %s from %s",
backend_list[num].filename, backend_list[num].libdir);
}
}
}
@@ -894,13 +892,14 @@ qof_session_load_backend(QofSession * session, char * access_method)
/* More than one backend could provide this
access method, check file type compatibility. */
type_check = (gboolean (*)(const char*)) prov->check_data_type;
prov_type = (type_check)(session->book_id);
if(!prov_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)
{
@@ -985,12 +984,12 @@ qof_session_begin (QofSession *session, const char * book_id,
return;
}
/* Store the session URL */
session->book_id = g_strdup (book_id);
/* destroy the old backend */
qof_session_destroy_backend(session);
/* Store the session URL */
session->book_id = g_strdup (book_id);
/* Look for something of the form of "file:/", "http://" or
* "postgres://". Everything before the colon is the access
* method. Load the first backend found for that access method.
@@ -1000,7 +999,7 @@ qof_session_begin (QofSession *session, const char * book_id,
{
access_method = g_strdup (book_id);
p = strchr (access_method, ':');
*p = 0;
*p = '\0';
qof_session_load_backend(session, access_method);
g_free (access_method);
}
@@ -1013,6 +1012,8 @@ qof_session_begin (QofSession *session, const char * book_id,
/* No backend was found. That's bad. */
if (NULL == session->backend)
{
g_free(session->book_id);
session->book_id = NULL;
qof_session_push_error (session, ERR_BACKEND_BAD_URL, NULL);
LEAVE (" BAD: no backend: sess=%p book-id=%s",
session, book_id ? book_id : "(null)");
@@ -1207,7 +1208,7 @@ qof_session_save (QofSession *session,
{
for (num = 0; backend_list[num].filename != NULL; num++) {
qof_load_backend_library(backend_list[num].libdir,
backend_list[num].filename, backend_list[num].init_fcn);
backend_list[num].filename);
}
}
p = g_slist_copy(provider_list);
@@ -1418,4 +1419,45 @@ qof_session_process_events (QofSession *session)
return session->backend->process_events (session->backend);
}
/* XXX This exports the list of accounts to a file. It does not
* export any transactions. It's a place-holder until full
* book-closing is implemented.
*/
gboolean
qof_session_export (QofSession *tmp_session,
QofSession *real_session,
QofPercentageFunc percentage_func)
{
QofBook *book, *book2;
QofBackend *be;
if ((!tmp_session) || (!real_session)) return FALSE;
book = qof_session_get_book (real_session);
ENTER ("tmp_session=%p real_session=%p book=%p book_id=%s",
tmp_session, real_session, book,
qof_session_get_url(tmp_session)
? qof_session_get_url(tmp_session) : "(null)");
/* There must be a backend or else. (It should always be the file
* backend too.)
*/
book2 = qof_session_get_book(tmp_session);
be = qof_book_get_backend(book2);
if (!be)
return FALSE;
be->percentage = percentage_func;
if (be->export) {
int err;
(be->export)(be, book);
err = qof_backend_get_error(be);
if (ERR_BACKEND_NO_ERR != err) { return FALSE; }
}
return TRUE;
}
/* =================== END OF FILE ====================================== */
+4
View File
@@ -431,5 +431,9 @@ void qof_session_add_close_hook (GFunc fn, gpointer data);
* @param session A pointer to the session being closed. */
void qof_session_call_close_hooks (QofSession *session);
gboolean qof_session_export (QofSession *tmp_session,
QofSession *real_session,
QofPercentageFunc percentage_func);
#endif /* QOF_SESSION_H */
/** @} */
+1
View File
@@ -32,6 +32,7 @@
#include <stdlib.h>
#include <string.h>
#include "qof.h"
#include "qofbackend-p.h"
static QofLogModule log_module = QOF_MOD_UTIL;
+2 -1
View File
@@ -36,7 +36,8 @@
#include "qof.h"
#include "qoflog.h"
#include "qofutil.h"
#include "qofbackend-p.h"
#include "qofbackend.h"
#include "qofclass.h"
#include "qofbook.h"
#include "qofinstance.h"