QOF  0.8.7
Macros | Functions | Variables
qof-gda.c File Reference

Public interface of qof-backend-gda. More...

#include "config.h"
#include <glib.h>
#include <glib/gstdio.h>
#include <libintl.h>
#include <libgda/libgda.h>
#include "qof.h"
#include "qof-gda.h"
#include "qofsql-p.h"

Go to the source code of this file.

Macros

#define _(String)   dgettext (GETTEXT_PACKAGE, String)
 
#define ACCESS_METHOD   "gda"
 
#define LIBGDA_DIR   ".qofgda"
 
#define GDA_DBNAME   "gda-database-name"
 
#define GDA_USERNAME   "gda-username"
 
#define GDA_PASSWORD   "gda-password"
 
#define GDA_DATASOURCE   "qof-gda-source"
 
#define ONLY_DEBUG   1
 

Functions

static gboolean qgda_determine_file_type (const gchar *path)
 
static void qgda_modify (QofBackend *be, QofInstance *inst)
 
static void create_tables (QofObject *obj, gpointer user_data)
 
static gboolean create_data_source (QGdaBackend *qgda_be)
 
static void qgda_session_begin (QofBackend *be, QofSession *session, const gchar *book_path, gboolean ignore_lock, gboolean create_if_nonexistent)
 
static void load_entities (gpointer value, gpointer user_data)
 
static void qgda_class_foreach (QofObject *obj, gpointer data)
 
static void qgda_db_load (QofBackend *be, QofBook *book)
 
static void qgda_check_entity (QofEntity *ent, gpointer data)
 
static void qgda_write_foreach (QofObject *obj, gpointer data)
 
static void qgda_write_db (QofBackend *be, QofBook *book)
 
static void qgda_session_end (QofBackend *be)
 
static void qgda_destroy_backend (QofBackend *be)
 
static void option_cb (QofBackendOption *option, gpointer data)
 
static void load_config (QofBackend *be, KvpFrame *config)
 
static KvpFrameget_config (QofBackend *be)
 
static QofBackendqgda_backend_new (void)
 
static void qgda_provider_free (QofBackendProvider *prov)
 
void qof_gda_provider_init (void)
 Initialises the libgda2 QOF backend. More...
 

Variables

static QofLogModule log_module = QOF_MOD_GDA
 

Detailed Description

Public interface of qof-backend-gda.

Author
Copyright 2006-2008 Neil Williams linux.nosp@m.@cod.nosp@m.ehelp.nosp@m..co..nosp@m.uk

Definition in file qof-gda.c.

Macro Definition Documentation

#define ONLY_DEBUG   1

enable for debug

Definition at line 42 of file qof-gda.c.

Function Documentation

static void qgda_session_begin ( QofBackend be,
QofSession session,
const gchar *  book_path,
gboolean  ignore_lock,
gboolean  create_if_nonexistent 
)
static
Bug:
we probably don't want to remove once out of debug. :-)

Definition at line 265 of file qof-gda.c.

268 {
269  QGdaBackend *qgda_be;
270  GdaDataSourceInfo * source;
271  gboolean created;
272 
273  /* cannot use ignore_lock */
274  PINFO (" gda session start");
275  qgda_be = (QGdaBackend*)be;
276  be->fullpath = g_strdup (book_path);
277  qgda_be->gda_err = NULL;
278  if(book_path == NULL)
279  {
280  qof_error_set_be (be, qof_error_register
281  (_("GDA: No data source path specified."), FALSE));
282  qgda_be->error = TRUE;
283  LEAVE (" bad URL");
284  return;
285  }
286  /* check/create the ~/.libgda location. */
287  {
288  struct stat lg;
289  gint ret;
290 
291  ret = g_stat (g_get_home_dir(), &lg);
292  if (ret)
293  {
294  qof_error_set_be (be, qof_error_register
295  (_("GDA: Unable to locate your home directory."),
296  FALSE));
297  qgda_be->error = TRUE;
298  LEAVE (" unable to use stat on home_dir.");
299  return;
300  }
301  qgda_be->gdahome = g_strconcat (g_get_home_dir(), "/", LIBGDA_DIR, NULL);
302  if (!S_ISDIR (lg.st_mode) || lg.st_size == 0)
303  ret = g_mkdir_with_parents (qgda_be->gdahome, 0700);
304  if (ret)
305  {
306  qof_error_set_be (be, qof_error_register
307  (_("GDA: Unable to create a .libgda directory "
308  "within your home directory."), FALSE));
309  qgda_be->error = TRUE;
310  LEAVE (" unable to create '%s' 0700", qgda_be->gdahome);
311  return;
312  }
313  }
314  if (qgda_be->data_source_name)
315  {
316  /* check data source */
317  qgda_be->book = qof_session_get_book (session);
318  PINFO ("name=%s", qgda_be->data_source_name);
319  PINFO ("provider=%s", qgda_be->provider_name);
320  created = FALSE;
321  source = gda_config_find_data_source
322  (qgda_be->data_source_name);
323  if (!source && create_if_nonexistent)
324  {
325  DEBUG (" no source, creating . . .");
326  created = create_data_source (qgda_be);
327  }
328  if (!source && !created)
329  {
330  qof_error_set_be (be, qof_error_register
331  (_("GDA: No data source found at '%s' - Try loading data "
332  "from another file and write to gda: again to create the "
333  "GDA data source."), TRUE));
334  DEBUG (" no source but set not to create.");
335  qgda_be->error = TRUE;
336  return;
337  }
338  }
339  PINFO (" trying for a connection");
340  /* use the username and password that created the source */
341  qgda_be->connection = gda_client_open_connection
342  (qgda_be->client_pool, qgda_be->data_source_name,
343  NULL, NULL, GDA_CONNECTION_OPTIONS_DONT_SHARE, &qgda_be->gda_err);
344  if (qgda_be->connection)
345  {
346  PINFO (" appear to be connected.");
347  /* create tables per QofObject */
348  qof_object_foreach_type (create_tables, qgda_be);
349  }
350  else
351  {
352  gchar * msg;
353 
354  msg = g_strdup_printf (
355  _("GDA encountered an error '%s' using data source '%s'."),
356  qgda_be->gda_err->message, qgda_be->data_source_name);
357  qof_error_set_be (be, qof_error_register (msg, FALSE));
358  PERR (" failed to connect to GDA: '%s'", msg);
359  qgda_be->error = TRUE;
360  g_message (msg);
361  g_free (msg);
362  g_error_free (qgda_be->gda_err);
363 #ifdef ONLY_DEBUG
364  PERR ("connect request failed, removing %s", qgda_be->data_source_name);
366  g_message ("connect request failed, removing %s", qgda_be->data_source_name);
367  gda_config_remove_data_source (qgda_be->data_source_name);
368 #endif
369  }
370 }
QofErrorId qof_error_register(const gchar *err_message, gboolean use_file)
Generate and register a new error.
Definition: qoferror.c:73
gchar * fullpath
Definition: qofbackend-p.h:332
#define PERR(format, args...)
Definition: qoflog.h:183
#define PINFO(format, args...)
Definition: qoflog.h:199
#define LEAVE(format, args...)
Definition: qoflog.h:227
#define DEBUG(format, args...)
Definition: qoflog.h:208
void qof_object_foreach_type(QofForeachTypeCB cb, gpointer user_data)
Definition: qofobject.c:140