libgda r3341 - in trunk: . libgda providers/bdb



Author: vivien
Date: Tue Mar  3 19:37:55 2009
New Revision: 3341
URL: http://svn.gnome.org/viewvc/libgda?rev=3341&view=rev

Log:
2009-03-03  Vivien Malerba <malerba gnome-db org>

        * configure.in:
        * libgda/Makefile.am:
        * libgda/gda-data-model-bdb.c:
        * providers/bdb/Makefile.am: the berkeley db livrary is now loaded only
        when needed: the libgda library is not linked directly with it anymore


Modified:
   trunk/ChangeLog
   trunk/configure.in
   trunk/libgda/Makefile.am
   trunk/libgda/gda-data-model-bdb.c
   trunk/providers/bdb/Makefile.am

Modified: trunk/configure.in
==============================================================================
--- trunk/configure.in	(original)
+++ trunk/configure.in	Tue Mar  3 19:37:55 2009
@@ -316,7 +316,8 @@
 		AC_CHECK_HEADER(db.h, bdb_ok=yes, bdb_ok=no, [])
 		if test $bdb_ok = yes ; then
 		        bdbdir=yes
-		   	BDB_LIBS="-ldb"
+		   	BDB_LIB="libdb$linklibext"
+			BDB_LIBS="-ldb"
 		fi
 	else
 		AC_MSG_CHECKING(for Berkeley DB files)
@@ -328,6 +329,7 @@
 				AC_DEFINE(HAVE_BDB, 1, [Have Berkeley DB])
 				bdbdir=$d
 				BDB_CFLAGS="-I${bdbdir}/include"
+				BDB_LIB="$d/bin/libdb47.dll"
 				BDB_LIBS="-L${bdbdir}/bin -ldb47"
 				break
 			fi
@@ -338,6 +340,7 @@
 				AC_DEFINE(HAVE_BDB, 1, [Have Berkeley DB])
 				bdbdir=$d
 				BDB_CFLAGS="-I${bdbdir}/include"
+				BDB_LIB="$d/$lib/libdb$linklibext"
 				BDB_LIBS="-L${bdbdir}/${lib} -ldb"
 				break
 			fi
@@ -347,6 +350,7 @@
 				AC_DEFINE(HAVE_BDB, 1, [Have Berkeley DB])
 				bdbdir=$d
 				BDB_CFLAGS="-I${bdbdir}/include"
+				BDB_LIB="$d/lib/libdb$linklibext"
 				BDB_LIBS="-L${bdbdir}/lib -ldb"
 				break
 			fi
@@ -361,7 +365,6 @@
 
 AM_CONDITIONAL(BDB, test x$bdbdir != x)
 if test x$bdbdir != x; then
-	LIBGDA_CFLAGS="$LIBGDA_CFLAGS $BDB_CFLAGS"
 	LIBGDA_BDB_INC="#include <libgda/gda-data-model-bdb.h>"
 	LIBGDA_BDB_TYPE="gda_data_model_bdb_get_type"
 fi
@@ -1383,6 +1386,7 @@
 dnl ******************************
 dnl Variables
 dnl ******************************
+AC_SUBST(BDB_LIB)
 AC_SUBST(BDB_LIBS)
 AC_SUBST(BDB_CFLAGS)
 AC_SUBST(ODBC_LIBS)

Modified: trunk/libgda/Makefile.am
==============================================================================
--- trunk/libgda/Makefile.am	(original)
+++ trunk/libgda/Makefile.am	Tue Mar  3 19:37:55 2009
@@ -17,6 +17,7 @@
 	$(LIBGDA_CFLAGS) \
 	$(FAM_CFLAGS) \
 	$(BDB_CFLAGS) \
+	-DBDB_LIB=\""$(BDB_LIB)"\" \
 	$(GIO_CFLAGS) $(GNOMEVFS_CFLAGS)
 
 _gda_marshal_built_files = gda-marshal.h gda-marshal.c
@@ -188,7 +189,7 @@
 	binreloc/libgda_binreloc-4.0.la \
 	sqlite/libgda-sqlite.la \
 	$(LIBGDA_LIBS) $(FAM_LIBS) \
-	$(BDB_LIBS) $(GIO_LIBS) $(GNOMEVFS_LIBS) 
+	$(GIO_LIBS) $(GNOMEVFS_LIBS) 
 
 if PLATFORM_WIN32
 libgda_4_0_la_LDFLAGS += -export-symbols $(srcdir)/libgda.def

Modified: trunk/libgda/gda-data-model-bdb.c
==============================================================================
--- trunk/libgda/gda-data-model-bdb.c	(original)
+++ trunk/libgda/gda-data-model-bdb.c	Tue Mar  3 19:37:55 2009
@@ -29,9 +29,14 @@
 #include <libgda/gda-data-model.h>
 #include <libgda/gda-data-model-bdb.h>
 #include <db.h>
+#include <gmodule.h>
 
 #define BDB_VERSION  (10000*DB_VERSION_MAJOR+100*DB_VERSION_MINOR+DB_VERSION_PATCH)
 
+static int (*libdb_db_create) (DB **, DB_ENV *, u_int32_t) = NULL;
+static char *(*libdb_db_strerror) (int) = NULL;
+static char *_db_strerror (int i);
+
 struct _GdaDataModelBdbPrivate {
 	gchar    *filename;
 	gchar    *db_name;
@@ -249,12 +254,46 @@
 		if (type == 0) {
 			type = g_type_register_static (G_TYPE_OBJECT, "GdaDataModelBdb", &info, 0);
 			g_type_add_interface_static (type, GDA_TYPE_DATA_MODEL, &data_model_info);
+
+			GModule *module;
+			gchar *err = NULL;
+
+			module = g_module_open (BDB_LIB, G_MODULE_BIND_LAZY);
+			if (!module)
+				err = g_strdup_printf (_("Could not load the Berkeley DB library: %s"),
+					   g_module_error ());
+			else {
+				if (!g_module_symbol (module, "db_create", (gpointer *) &libdb_db_create))
+					err = g_strdup_printf (_("Could not load the '%s' symbol from the "
+								 "Berkeley DB library"),
+							       "db_create");
+				else if (!g_module_symbol (module, "db_strerror", (gpointer *) &libdb_db_strerror))
+					err = g_strdup_printf (_("Could not load the '%s' symbol from the "
+								 "Berkeley DB library"),
+							       "db_strerror");
+			}
+			if (err) {
+				g_warning (err);
+				g_free (err);
+				libdb_db_create = NULL;
+				libdb_db_strerror = NULL;
+			}
+			else
+				g_module_make_resident (module);
 		}
 		g_static_mutex_unlock (&registering);
 	}
 	return type;
 }
 
+static char *_db_strerror (int i)
+{
+	if (libdb_db_strerror)
+		return libdb_db_strerror (i);
+	else
+		return _("Berkeley DB library not loaded");
+}
+
 static void
 update_number_of_rows (GdaDataModelBdb *model)
 {
@@ -272,7 +311,7 @@
 #endif
 			 0);
 	if (ret) {
-		add_error (model, db_strerror (ret));
+		add_error (model, _db_strerror (ret));
 		model->priv->n_rows = 0;
 	}
 	else {
@@ -322,9 +361,13 @@
 		DB *dbp;
 
 		/* open database */
-		ret = db_create (&dbp, NULL, 0);
+		if (!libdb_db_create) {
+			add_error (model, _("Berkeley DB library not loaded"));
+			goto out;
+		}
+		ret = libdb_db_create (&dbp, NULL, 0);
 		if (ret) {
-			add_error (model, db_strerror (ret));
+			add_error (model, _db_strerror (ret));
 			goto out;
 		}
 		
@@ -338,14 +381,14 @@
 				 DB_UNKNOWN, /* autodetect DBTYPE */
 				 0, 0);
 		if (ret) {
-			add_error (model, db_strerror (ret));
+			add_error (model, _db_strerror (ret));
 			goto out;
 		}
 
 		/* get cursor */
 		ret = dbp->cursor (dbp, NULL, &dbpc, 0);
 		if (ret) {
-			add_error (model, db_strerror (ret));
+			add_error (model, _db_strerror (ret));
 			goto out;
 		}
 		model->priv->dbpc = dbpc;
@@ -556,7 +599,7 @@
 		memset (&data, 0, sizeof data);
 		ret = dbpc->c_get (dbpc, &key, &data, DB_FIRST);
 		if (ret) {
-			add_error (model, db_strerror (ret));
+			add_error (model, _db_strerror (ret));
 			return FALSE;
 		}
 		model->priv->cursor_pos = 0;
@@ -569,7 +612,7 @@
 			memset (&data, 0, sizeof data);
 			ret = dbpc->c_get (dbpc, &key, &data, DB_NEXT);
 			if (ret) {
-				add_error (model, db_strerror (ret));
+				add_error (model, _db_strerror (ret));
 				return FALSE;
 			}
 			model->priv->cursor_pos ++;
@@ -581,7 +624,7 @@
 			memset (&data, 0, sizeof data);
 			ret = dbpc->c_get (dbpc, &key, &data, DB_PREV);
 			if (ret) {
-				add_error (model, db_strerror (ret));
+				add_error (model, _db_strerror (ret));
 				return FALSE;
 			}
 			model->priv->cursor_pos --;
@@ -621,9 +664,9 @@
         memset (&data, 0, sizeof data);
 	ret = imodel->priv->dbpc->c_get (imodel->priv->dbpc, &key, &data, DB_CURRENT);
 	if (ret) {
-		add_error (imodel, db_strerror (ret));
+		add_error (imodel, _db_strerror (ret));
 		g_set_error (error, GDA_DATA_MODEL_ERROR, GDA_DATA_MODEL_ACCESS_ERROR,
-			      "%s", db_strerror (ret));
+			      "%s", _db_strerror (ret));
 		return NULL;
 	}
 
@@ -842,9 +885,9 @@
         memset (&data, 0, sizeof data);
 	ret = imodel->priv->dbpc->c_get (imodel->priv->dbpc, &key, &data, DB_CURRENT);
 	if (ret) {
-		add_error (imodel, db_strerror (ret));
+		add_error (imodel, _db_strerror (ret));
 		g_set_error (error, GDA_DATA_MODEL_ERROR, GDA_DATA_MODEL_ACCESS_ERROR,
-			      "%s", db_strerror (ret));
+			      "%s", _db_strerror (ret));
 		return FALSE;
 	}
 
@@ -905,9 +948,9 @@
 	if (!key_modified) {
 		ret = imodel->priv->dbpc->c_put (imodel->priv->dbpc, &key, &data, DB_CURRENT);
 		if (ret) {
-			add_error (imodel, db_strerror (ret));
+			add_error (imodel, _db_strerror (ret));
 			g_set_error (error, GDA_DATA_MODEL_ERROR, GDA_DATA_MODEL_ACCESS_ERROR,
-				      "%s", db_strerror (ret));
+				      "%s", _db_strerror (ret));
 			return FALSE;
 		}
 	}
@@ -948,9 +991,9 @@
 
 	ret = imodel->priv->dbp->put (imodel->priv->dbp, NULL, &key, &data, 0);
 	if (ret) {
-		add_error (imodel, db_strerror (ret));
+		add_error (imodel, _db_strerror (ret));
 		g_set_error (error, GDA_DATA_MODEL_ERROR, GDA_DATA_MODEL_ACCESS_ERROR,
-			      "%s", db_strerror (ret));
+			      "%s", _db_strerror (ret));
 		return -1;
 	}
 
@@ -975,9 +1018,9 @@
 
 	ret = imodel->priv->dbpc->c_del (imodel->priv->dbpc, 0);
 	if (ret) {
-		add_error (imodel, db_strerror (ret));
+		add_error (imodel, _db_strerror (ret));
 		g_set_error (error, GDA_DATA_MODEL_ERROR, GDA_DATA_MODEL_ACCESS_ERROR,
-			      "%s", db_strerror (ret));
+			      "%s", _db_strerror (ret));
 		return FALSE;
 	}
 

Modified: trunk/providers/bdb/Makefile.am
==============================================================================
--- trunk/providers/bdb/Makefile.am	(original)
+++ trunk/providers/bdb/Makefile.am	Tue Mar  3 19:37:55 2009
@@ -25,6 +25,7 @@
 gda_bdb_test_SOURCES = gda-bdb-test.c
 gda_bdb_test_LDADD = \
 	$(LIBGDA_LIBS) \
+	$(BDB_LIBS) \
 	$(top_builddir)/libgda/libgda-4.0.la 
 
 xmldir   = $(datadir)/libgda-4.0



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]