#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.
Defines | |
#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 KvpFrame * | get_config (QofBackend *be) |
static QofBackend * | qgda_backend_new (void) |
static void | qgda_provider_free (QofBackendProvider *prov) |
void | qof_gda_provider_init (void) |
Initialises the libgda2 QOF backend. | |
Variables | |
static QofLogModule | log_module = QOF_MOD_GDA |
Definition in file qof-gda.c.
static void qgda_session_begin | ( | QofBackend * | be, | |
QofSession * | session, | |||
const gchar * | book_path, | |||
gboolean | ignore_lock, | |||
gboolean | create_if_nonexistent | |||
) | [static] |
Definition at line 265 of file qof-gda.c.
00268 { 00269 QGdaBackend *qgda_be; 00270 GdaDataSourceInfo * source; 00271 gboolean created; 00272 00273 /* cannot use ignore_lock */ 00274 PINFO (" gda session start"); 00275 qgda_be = (QGdaBackend*)be; 00276 be->fullpath = g_strdup (book_path); 00277 qgda_be->gda_err = NULL; 00278 if(book_path == NULL) 00279 { 00280 qof_error_set_be (be, qof_error_register 00281 (_("GDA: No data source path specified."), FALSE)); 00282 qgda_be->error = TRUE; 00283 LEAVE (" bad URL"); 00284 return; 00285 } 00286 /* check/create the ~/.libgda location. */ 00287 { 00288 struct stat lg; 00289 gint ret; 00290 00291 ret = g_stat (g_get_home_dir(), &lg); 00292 if (ret) 00293 { 00294 qof_error_set_be (be, qof_error_register 00295 (_("GDA: Unable to locate your home directory."), 00296 FALSE)); 00297 qgda_be->error = TRUE; 00298 LEAVE (" unable to use stat on home_dir."); 00299 return; 00300 } 00301 qgda_be->gdahome = g_strconcat (g_get_home_dir(), "/", LIBGDA_DIR, NULL); 00302 if (!S_ISDIR (lg.st_mode) || lg.st_size == 0) 00303 ret = g_mkdir_with_parents (qgda_be->gdahome, 0700); 00304 if (ret) 00305 { 00306 qof_error_set_be (be, qof_error_register 00307 (_("GDA: Unable to create a .libgda directory " 00308 "within your home directory."), FALSE)); 00309 qgda_be->error = TRUE; 00310 LEAVE (" unable to create '%s' 0700", qgda_be->gdahome); 00311 return; 00312 } 00313 } 00314 if (qgda_be->data_source_name) 00315 { 00316 /* check data source */ 00317 qgda_be->book = qof_session_get_book (session); 00318 PINFO ("name=%s", qgda_be->data_source_name); 00319 PINFO ("provider=%s", qgda_be->provider_name); 00320 created = FALSE; 00321 source = gda_config_find_data_source 00322 (qgda_be->data_source_name); 00323 if (!source && create_if_nonexistent) 00324 { 00325 DEBUG (" no source, creating . . ."); 00326 created = create_data_source (qgda_be); 00327 } 00328 if (!source && !created) 00329 { 00330 qof_error_set_be (be, qof_error_register 00331 (_("GDA: No data source found at '%s' - Try loading data " 00332 "from another file and write to gda: again to create the " 00333 "GDA data source."), TRUE)); 00334 DEBUG (" no source but set not to create."); 00335 qgda_be->error = TRUE; 00336 return; 00337 } 00338 } 00339 PINFO (" trying for a connection"); 00340 /* use the username and password that created the source */ 00341 qgda_be->connection = gda_client_open_connection 00342 (qgda_be->client_pool, qgda_be->data_source_name, 00343 NULL, NULL, GDA_CONNECTION_OPTIONS_DONT_SHARE, &qgda_be->gda_err); 00344 if (qgda_be->connection) 00345 { 00346 PINFO (" appear to be connected."); 00347 /* create tables per QofObject */ 00348 qof_object_foreach_type (create_tables, qgda_be); 00349 } 00350 else 00351 { 00352 gchar * msg; 00353 00354 msg = g_strdup_printf ( 00355 _("GDA encountered an error '%s' using data source '%s'."), 00356 qgda_be->gda_err->message, qgda_be->data_source_name); 00357 qof_error_set_be (be, qof_error_register (msg, FALSE)); 00358 PERR (" failed to connect to GDA: '%s'", msg); 00359 qgda_be->error = TRUE; 00360 g_message (msg); 00361 g_free (msg); 00362 g_error_free (qgda_be->gda_err); 00363 #ifdef ONLY_DEBUG 00365 PERR ("connect request failed, removing %s", qgda_be->data_source_name); 00366 g_message ("connect request failed, removing %s", qgda_be->data_source_name); 00367 gda_config_remove_data_source (qgda_be->data_source_name); 00368 #endif 00369 } 00370 }