libgda r3364 - in branches/LIBGDA_4.0: . libgda libgda/sqlite providers/mysql providers/postgres providers/skel-implementation/capi tools



Author: vivien
Date: Wed Mar 25 20:57:11 2009
New Revision: 3364
URL: http://svn.gnome.org/viewvc/libgda?rev=3364&view=rev

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

	* configure.in: set version to 4.0.1
	* libgda/gda-config.c:
	  - added _gda_config_sqlite_provider,
	    a pointer to the SQLite GdaServerProvider, always available, even
	    if the SQLite provider is not installed
	  - correctly behave if no provider is found at all
	* libgda/gda-connection.c:
	* libgda/gda-connection-sqlite.h: added a private method to open a
	connection to an SQLite file directly, even if the SQLite provider is not
	installed: _gda_open_internal_sqlite_connection()
	* libgda/gda-meta-store.c: if the SQLite provider is not installed, then use
	_gda_open_internal_sqlite_connection()
	* libgda/gda-server-operation-private.h:
	* libgda/gda-server-operation.c: added a private
	_gda_server_operation_new_from_string() function
	* libgda/sqlite/Makefile.am
	* libgda/sqlite/gen_emb_string.c: tool which generates source code to embedd all
	the .xml files found in providers/sqlite.
	* libgda/sqlite/gda-sqlite-provider.c: if a .xml file normally installed along
	with the SQLite provider is not found, then use the embedded version, using
	the file generated by the new gen_emb_string tool (which means losing any
	translation but we don't care as it is for internal purposes only).
	* libgda/sqlite/gda-sqlite-provider.c:
	* providers/mysql/gda-mysql-provider.c:
	* providers/postgres/gda-postgres-provider.c:
	* providers/skel-implementation/capi/gda-capi-provider.c: minor corrections in
	warnings
	* tools/gda-sql.c: better handle when the meta store object can be created


Added:
   branches/LIBGDA_4.0/libgda/gda-connection-sqlite.h
   branches/LIBGDA_4.0/libgda/gda-server-operation-private.h
   branches/LIBGDA_4.0/libgda/sqlite/gen_emb_string.c
Modified:
   branches/LIBGDA_4.0/ChangeLog
   branches/LIBGDA_4.0/configure.in
   branches/LIBGDA_4.0/libgda/Makefile.am
   branches/LIBGDA_4.0/libgda/gda-config.c
   branches/LIBGDA_4.0/libgda/gda-connection.c
   branches/LIBGDA_4.0/libgda/gda-meta-store.c
   branches/LIBGDA_4.0/libgda/gda-server-operation.c
   branches/LIBGDA_4.0/libgda/sqlite/   (props changed)
   branches/LIBGDA_4.0/libgda/sqlite/Makefile.am
   branches/LIBGDA_4.0/libgda/sqlite/gda-sqlite-provider.c
   branches/LIBGDA_4.0/providers/mysql/gda-mysql-provider.c
   branches/LIBGDA_4.0/providers/postgres/gda-postgres-provider.c
   branches/LIBGDA_4.0/providers/skel-implementation/capi/gda-capi-provider.c
   branches/LIBGDA_4.0/tools/gda-sql.c

Modified: branches/LIBGDA_4.0/configure.in
==============================================================================
--- branches/LIBGDA_4.0/configure.in	(original)
+++ branches/LIBGDA_4.0/configure.in	Wed Mar 25 20:57:11 2009
@@ -1,6 +1,6 @@
 m4_define(major, 4)
 m4_define(minor, 0)
-m4_define(micro, 0)
+m4_define(micro, 1)
 
 AC_INIT(GNU Data Access, major.minor.micro, gnome-db-list gnome org, libgda)
 AC_PREREQ(2.59)

Modified: branches/LIBGDA_4.0/libgda/Makefile.am
==============================================================================
--- branches/LIBGDA_4.0/libgda/Makefile.am	(original)
+++ branches/LIBGDA_4.0/libgda/Makefile.am	Wed Mar 25 20:57:11 2009
@@ -90,6 +90,7 @@
 	gda-config.c \
 	gda-connection.c \
 	gda-connection-event.c \
+	gda-connection-sqlite.h \
 	gda-custom-marshal.c \
 	gda-custom-marshal.h \
 	gda-data-comparator.c \
@@ -124,6 +125,7 @@
 	gda-row.c \
 	gda-set.c \
 	gda-server-operation.c \
+	gda-server-operation-private.h \
 	gda-server-provider.c \
 	gda-server-provider-extra.c \
 	gda-statement.c \

Modified: branches/LIBGDA_4.0/libgda/gda-config.c
==============================================================================
--- branches/LIBGDA_4.0/libgda/gda-config.c	(original)
+++ branches/LIBGDA_4.0/libgda/gda-config.c	Wed Mar 25 20:57:11 2009
@@ -34,6 +34,8 @@
 #include <libgda/gda-holder.h>
 #include <libgda/gda-log.h>
 #include <libgda/gda-util.h>
+#include <libgda/sqlite/gda-sqlite-provider.h>
+
 #ifdef HAVE_GIO
   #ifdef HAVE_FAM
     #error Impossible to have GIO and FAM at the same time
@@ -64,6 +66,7 @@
 	gboolean system_config_allowed;
 	GSList *dsn_list; /* list of GdaDsnInfo structures */
 	GSList *prov_list; /* list of InternalProvider structures */
+	gboolean providers_loaded; /* TRUE if providers list has already been scanned */
 };
 
 static void gda_config_class_init (GdaConfigClass *klass);
@@ -145,6 +148,11 @@
 #define GDA_CONFIG_LOCK() g_static_rec_mutex_lock(&gda_mutex)
 #define GDA_CONFIG_UNLOCK() g_static_rec_mutex_unlock(&gda_mutex)
 
+/* GdaServerProvider for SQLite as a shortcut, available
+ * even if the SQLite provider is not installed
+ */
+GdaServerProvider *_gda_config_sqlite_provider = NULL;
+
 /*
  * GdaConfig class implementation
  * @klass:
@@ -249,6 +257,7 @@
 	conf->priv->system_config_allowed = FALSE;
 	conf->priv->prov_list = NULL;
 	conf->priv->dsn_list = NULL;
+	conf->priv->providers_loaded = FALSE;
 }
 
 static void
@@ -1128,7 +1137,7 @@
 	if (!unique_instance)
 		gda_config_get ();
 
-	if (!unique_instance->priv->prov_list) 
+	if (!unique_instance->priv->providers_loaded) 
 		load_all_providers ();
 
 	if (!g_ascii_strcasecmp (provider_name, "MS Access")) {
@@ -1241,7 +1250,7 @@
 	if (!unique_instance)
 		gda_config_get ();
 
-	if (!unique_instance->priv->prov_list) 
+	if (!unique_instance->priv->providers_loaded) 
 		load_all_providers ();
 
 	model = gda_data_model_array_new_with_g_types (5,
@@ -1340,6 +1349,14 @@
 		load_providers_from_dir (str, FALSE);
 		g_free (str);
 	}
+	unique_instance->priv->providers_loaded = TRUE;
+
+	/* find SQLite provider, and instanciate it if not installed */
+	_gda_config_sqlite_provider = gda_config_get_provider ("SQLite", NULL);
+	if (!_gda_config_sqlite_provider) {
+		_gda_config_sqlite_provider = (GdaServerProvider*) 
+			g_object_new (GDA_TYPE_SQLITE_PROVIDER, NULL);
+	}
 }
 
 static InternalProvider *
@@ -1616,8 +1633,8 @@
 	if (event_type != G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT)
 		return;
 
-	gboolean is_system = (mon == mon_conf_global) ? TRUE : FALSE;
 #ifdef GDA_DEBUG_NO
+	gboolean is_system = (mon == mon_conf_global) ? TRUE : FALSE;
 	g_print ("Reloading config files (%s config has changed)\n", is_system ? "global" : "user");
 	GSList *list;
 	for (list = unique_instance->priv->dsn_list; list; list = list->next) {

Added: branches/LIBGDA_4.0/libgda/gda-connection-sqlite.h
==============================================================================
--- (empty file)
+++ branches/LIBGDA_4.0/libgda/gda-connection-sqlite.h	Wed Mar 25 20:57:11 2009
@@ -0,0 +1,39 @@
+/* GDA library
+ * Copyright (C) 2009 The GNOME Foundation.
+ *
+ * AUTHORS:
+ *      Vivien Malerba <malerba gnome-db org>
+ *
+ * This Library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This Library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this Library; see the file COPYING.LIB.  If not,
+ * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __GDA_CONNECTION_SQLITE_H_
+#define __GDA_CONNECTION_SQLITE_H_
+
+#include <libgda/gda-decl.h>
+
+G_BEGIN_DECLS
+
+/*
+ * Opens a connection to an SQLite database. This function is intended to be used
+ * internally when objects require an SQLite connection, for example for the GdaMetaStore
+ * object
+ */
+GdaConnection *_gda_open_internal_sqlite_connection (const gchar *cnc_string);
+
+G_END_DECLS
+
+#endif

Modified: branches/LIBGDA_4.0/libgda/gda-connection.c
==============================================================================
--- branches/LIBGDA_4.0/libgda/gda-connection.c	(original)
+++ branches/LIBGDA_4.0/libgda/gda-connection.c	Wed Mar 25 20:57:11 2009
@@ -119,6 +119,7 @@
 };
 
 static GObjectClass *parent_class = NULL;
+extern GdaServerProvider *_gda_config_sqlite_provider; /* defined in gda-config.c */
 
 /*
  * GdaConnection class implementation
@@ -801,6 +802,50 @@
 	return cnc;
 }
 
+/*
+ * Uses _gda_config_sqlite_provider to open a connection
+ */
+GdaConnection *
+_gda_open_internal_sqlite_connection (const gchar *cnc_string)
+{
+	GdaConnection *cnc;
+	GdaServerProvider *prov = _gda_config_sqlite_provider;
+	gchar *user, *pass, *real_cnc, *real_provider;
+
+	g_print ("%s(%s)\n", __FUNCTION__, cnc_string);
+	gda_connection_string_split (cnc_string, &real_cnc, &real_provider, &user, &pass);
+        if (!real_cnc) {
+                g_free (user);
+                g_free (pass);
+                g_free (real_provider);
+                return NULL;
+        }
+	if (PROV_CLASS (prov)->create_connection) {
+		cnc = PROV_CLASS (prov)->create_connection (prov);
+		if (cnc)
+			g_object_set (G_OBJECT (cnc),
+				      "provider", prov,
+				      "cnc-string", real_cnc,
+				      NULL);
+	}
+	else
+		cnc = (GdaConnection *) g_object_new (GDA_TYPE_CONNECTION,
+						      "provider", prov,
+						      "cnc-string", real_cnc,
+						      NULL);
+	
+	g_free (real_cnc);
+        g_free (user);
+        g_free (pass);
+        g_free (real_provider);
+
+	/* open the connection */
+	if (!gda_connection_open (cnc, NULL)) {
+		g_object_unref (cnc);
+		cnc = NULL;
+	}
+	return cnc;
+}
 
 /**
  * gda_connection_open

Modified: branches/LIBGDA_4.0/libgda/gda-meta-store.c
==============================================================================
--- branches/LIBGDA_4.0/libgda/gda-meta-store.c	(original)
+++ branches/LIBGDA_4.0/libgda/gda-meta-store.c	Wed Mar 25 20:57:11 2009
@@ -39,6 +39,7 @@
 #include <libgda/gda-util.h>
 #include <libgda/gda-meta-struct.h>
 #include <libgda/gda-connection.h>
+#include <libgda/gda-connection-sqlite.h>
 #include "gda-types.h"
 
 /*
@@ -699,6 +700,13 @@
 				if (cnc_string) {
 					GdaConnection *cnc;
 					cnc = gda_connection_open_from_string (NULL, cnc_string, NULL, 0, NULL);
+					if (!cnc) {
+						if (g_ascii_strcasecmp (cnc_string, "sqlite")) {
+							/* use _gda_config_sqlite_provider */
+							
+							cnc = _gda_open_internal_sqlite_connection (cnc_string);
+						}
+					}
 					store->priv->cnc = cnc;
 				}
 			}

Added: branches/LIBGDA_4.0/libgda/gda-server-operation-private.h
==============================================================================
--- (empty file)
+++ branches/LIBGDA_4.0/libgda/gda-server-operation-private.h	Wed Mar 25 20:57:11 2009
@@ -0,0 +1,35 @@
+/* GDA library
+ * Copyright (C) 2009 The GNOME Foundation.
+ *
+ * AUTHORS:
+ *      Vivien Malerba <malerba gnome-db org>
+ *
+ * This Library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This Library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this Library; see the file COPYING.LIB.  If not,
+ * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __GDA_SERVER_OPERATION_PRIVATE_H__
+#define __GDA_SERVER_OPERATION_PRIVATE_H__
+
+#include <libgda/gda-decl.h>
+
+G_BEGIN_DECLS
+
+GdaServerOperation *_gda_server_operation_new_from_string (GdaServerOperationType op_type, 
+							   const gchar *xml_spec);
+
+G_END_DECLS
+
+#endif

Modified: branches/LIBGDA_4.0/libgda/gda-server-operation.c
==============================================================================
--- branches/LIBGDA_4.0/libgda/gda-server-operation.c	(original)
+++ branches/LIBGDA_4.0/libgda/gda-server-operation.c	Wed Mar 25 20:57:11 2009
@@ -519,6 +519,7 @@
 }
 
 static void xml_validity_error_func (void *ctx, const char *msg, ...);
+static gboolean use_xml_spec (GdaServerOperation *op, xmlDocPtr doc, const gchar *xmlfile);
 
 static void
 gda_server_operation_set_property (GObject *object,
@@ -567,7 +568,6 @@
 			const gchar *xmlfile;
 			static GHashTable *doc_hash = NULL; /* key = file name, value = xmlDocPtr */
 
-			xmlDtdPtr old_dtd = NULL;
 			xmlfile = g_value_get_string (value);
 			if (!xmlfile)
 				return;
@@ -590,52 +590,8 @@
 			
 			doc = xmlParseFile (xmlfile);
 			if (doc) {
-				/* doc validation */
-				xmlValidCtxtPtr validc;
-				int xmlcheck;
-				
-				validc = g_new0 (xmlValidCtxt, 1);
-				validc->userData = op;
-				validc->error = xml_validity_error_func;
-				validc->warning = NULL;
-				
-				xmlcheck = xmlDoValidityCheckingDefaultValue;
-				xmlDoValidityCheckingDefaultValue = 1;
-				
-				/* replace the DTD with ours */
-				if (gda_server_op_dtd) {
-					old_dtd = doc->intSubset;
-					doc->intSubset = gda_server_op_dtd;
-				}
-#ifndef G_OS_WIN32
-				if (doc->intSubset && !xmlValidateDocument (validc, doc)) {
-					gchar *str;
-					
-					if (gda_server_op_dtd)
-						doc->intSubset = old_dtd;
-					xmlFreeDoc (doc);
-					g_free (validc);
-					str = g_object_get_data (G_OBJECT (op), "xmlerror");
-					if (str) {
-						g_warning (_("GdaServerOperation: file '%s' does not conform to DTD:\n%s"),
-							   xmlfile, str);
-						g_free (str);
-						g_object_set_data (G_OBJECT (op), "xmlerror", NULL);
-					}
-					else
-						g_warning (_("GdaServerOperation: file '%s' does not conform to DTD"),
-							   xmlfile);
-					
-					xmlDoValidityCheckingDefaultValue = xmlcheck;
+				if (!use_xml_spec (op, doc, xmlfile))
 					return;
-				}
-#endif
-				
-				xmlDoValidityCheckingDefaultValue = xmlcheck;
-				g_free (validc);
-				if (gda_server_op_dtd)
-					doc->intSubset = old_dtd;
-				op->priv->xml_spec_doc = doc;
 				g_hash_table_insert (doc_hash, g_strdup (xmlfile), doc);
 			}
 			else {
@@ -661,7 +617,7 @@
 		}
 	}
 }
-
+	
 static void
 gda_server_operation_get_property (GObject *object,
 				   guint param_id,
@@ -687,6 +643,73 @@
 }
 
 /*
+ * Steals @doc (it is freed if necessary)
+ */
+static gboolean
+use_xml_spec (GdaServerOperation *op, xmlDocPtr doc, const gchar *xmlfile)
+{
+	/* doc validation */
+	xmlValidCtxtPtr validc;
+	int xmlcheck;
+	xmlDtdPtr old_dtd = NULL;
+	
+	validc = g_new0 (xmlValidCtxt, 1);
+	validc->userData = op;
+	validc->error = xml_validity_error_func;
+	validc->warning = NULL;
+	
+	xmlcheck = xmlDoValidityCheckingDefaultValue;
+	xmlDoValidityCheckingDefaultValue = 1;
+	
+	/* replace the DTD with ours */
+	if (gda_server_op_dtd) {
+		old_dtd = doc->intSubset;
+		doc->intSubset = gda_server_op_dtd;
+	}
+#ifndef G_OS_WIN32
+	if (doc->intSubset && !xmlValidateDocument (validc, doc)) {
+		gchar *str;
+		
+		if (gda_server_op_dtd)
+			doc->intSubset = old_dtd;
+		xmlFreeDoc (doc);
+		g_free (validc);
+		str = g_object_get_data (G_OBJECT (op), "xmlerror");
+		if (str) {
+			if (xmlfile)
+				g_warning (_("GdaServerOperation: file '%s' does not conform to DTD:\n%s"),
+					   xmlfile, str);
+			else
+				g_warning (_("GdaServerOperation specification does not conform to DTD:\n%s"),
+					   str);
+			g_free (str);
+			g_object_set_data (G_OBJECT (op), "xmlerror", NULL);
+		}
+		else {
+			if (xmlfile)
+				g_warning (_("GdaServerOperation: file '%s' does not conform to DTD"),
+					   xmlfile);
+			else
+				g_warning (_("GdaServerOperation specification does not conform to DTD\n"));
+		}
+		
+		xmlDoValidityCheckingDefaultValue = xmlcheck;
+		xmlFreeDoc (doc);
+		return FALSE;
+	}
+#endif
+	
+	xmlDoValidityCheckingDefaultValue = xmlcheck;
+	g_free (validc);
+	if (gda_server_op_dtd)
+		doc->intSubset = old_dtd;
+	op->priv->xml_spec_doc = doc;
+
+	return TRUE;
+}
+
+
+/*
  * function called when an error occurred during the document validation
  */
 static void
@@ -953,6 +976,41 @@
 	return retlist;
 }
 
+/*
+ * @xml_spec: the specifications for the GdaServerOperation object to create as a string
+ * Internal function
+ */
+GdaServerOperation *
+_gda_server_operation_new_from_string (GdaServerOperationType op_type, 
+				       const gchar *xml_spec)
+{
+	GObject *obj;
+	xmlDocPtr doc;
+	GdaServerOperation *op;
+
+	doc = xmlParseMemory (xml_spec, strlen (xml_spec) + 1);
+	if (!doc)
+		return NULL;
+	obj = g_object_new (GDA_TYPE_SERVER_OPERATION, "op-type", op_type, NULL);
+	op = GDA_SERVER_OPERATION (obj);
+	use_xml_spec (op, doc, NULL);
+
+	if (!op->priv->topnodes && op->priv->xml_spec_doc && op->priv->cnc_set && op->priv->prov_set) {
+		/* load XML file */
+		GError *lerror = NULL;
+		op->priv->topnodes = load_xml_spec (op, xmlDocGetRootElement (op->priv->xml_spec_doc), NULL, &lerror);
+		if (!op->priv->topnodes) {
+			g_warning (_("Could not load XML specifications: %s"),
+				   lerror && lerror->message ? lerror->message : _("No detail"));
+			if (lerror)
+				g_error_free (lerror);
+		}
+	}
+
+	return op;
+}
+
+
 /**
  * gda_server_operation_new
  * @op_type: type of operation
@@ -974,7 +1032,8 @@
 {
 	GObject *obj;
 
-	obj = g_object_new (GDA_TYPE_SERVER_OPERATION, "op-type", op_type, "spec-filename", xml_file, NULL);
+	obj = g_object_new (GDA_TYPE_SERVER_OPERATION, "op-type", op_type, 
+			    "spec-filename", xml_file, NULL);
 #ifdef GDA_DEBUG_NO
 	{
 		g_print ("New GdaServerOperation:\n");

Modified: branches/LIBGDA_4.0/libgda/sqlite/Makefile.am
==============================================================================
--- branches/LIBGDA_4.0/libgda/sqlite/Makefile.am	(original)
+++ branches/LIBGDA_4.0/libgda/sqlite/Makefile.am	Wed Mar 25 20:57:11 2009
@@ -20,6 +20,11 @@
 	$(SQLITE_CFLAGS) \
 	$(sqliteinc) 
 
+gen_emb_string$(EXEEXT_FOR_BUILD): gen_emb_string.c
+	$(CC_FOR_BUILD) -o gen_emb_string$(EXEEXT_FOR_BUILD) $<
+
+xml_embedded.h: gen_emb_string$(EXEEXT_FOR_BUILD) $(top_srcdir)/providers/sqlite/*.xml.in
+	./gen_emb_string$(EXEEXT_FOR_BUILD) $(top_srcdir)/providers/sqlite/*.xml.in > xml_embedded.h
 
 sqliteheaders = gda-sqlite-provider.h
 libgda_sqlite_la_SOURCES = \
@@ -38,7 +43,8 @@
 	gda-sqlite-recordset.c \
 	gda-sqlite-recordset.h \
 	gda-sqlite.h \
-	utils.c 
+	utils.c \
+	xml_embedded.h
 
 libgda_sqlite_la_LDFLAGS = -export-dynamic -module -avoid-version $(NO_UNDEFINED)
 libgda_sqlite_la_LIBADD = \
@@ -49,3 +55,6 @@
 gdaincludedir=$(includedir)/libgda-$(GDA_ABI_MAJOR_VERSION).$(GDA_ABI_MINOR_VERSION)/libgda/sqlite
 gdainclude_HEADERS=$(sqliteheaders)
 
+EXTRA_DIST = gen_emb_string.c
+
+CLEANFILES = gen_emb_string$(EXEEXT_FOR_BUILD) xml_embedded.h
\ No newline at end of file

Modified: branches/LIBGDA_4.0/libgda/sqlite/gda-sqlite-provider.c
==============================================================================
--- branches/LIBGDA_4.0/libgda/sqlite/gda-sqlite-provider.c	(original)
+++ branches/LIBGDA_4.0/libgda/sqlite/gda-sqlite-provider.c	Wed Mar 25 20:57:11 2009
@@ -31,6 +31,7 @@
 #include <libgda/gda-data-model-private.h>
 #include <libgda/gda-util.h>
 #include <libgda/gda-server-provider-extra.h>
+#include <libgda/gda-server-operation-private.h>
 #include "gda-sqlite.h"
 #include "gda-sqlite-provider.h"
 #include "gda-sqlite-recordset.h"
@@ -44,6 +45,7 @@
 #include <libgda/gda-statement-extra.h>
 #include <sql-parser/gda-sql-parser.h>
 #include <stdio.h>
+#include "xml_embedded.h" /* this one is dynamically generated */
 #ifndef G_OS_WIN32
 #define __USE_GNU
 #include <dlfcn.h>
@@ -955,13 +957,23 @@
 	dir = gda_gbr_get_file_path (GDA_DATA_DIR, LIBGDA_ABI_NAME, NULL);
         file = gda_server_provider_find_file (provider, dir, str);
 	g_free (dir);
-        g_free (str);
 
         if (! file) {
-                g_set_error (error, 0, 0, _("Missing spec. file '%s'"), file);
-                return NULL;
+		const gchar *contents;
+		contents = emb_get_file (str);
+		if (contents) {
+			op = _gda_server_operation_new_from_string (type, contents);
+			return op;
+		}
+		else {
+			g_set_error (error, 0, 0, _("Missing spec. file '%s'"), str);
+			g_free (str);
+			return NULL;
+		}
         }
 
+        g_free (str);
+
         op = gda_server_operation_new (type, file);
         g_free (file);
 
@@ -988,17 +1000,25 @@
 	dir = gda_gbr_get_file_path (GDA_DATA_DIR, LIBGDA_ABI_NAME, NULL);
         file = gda_server_provider_find_file (provider, dir, str);
 	g_free (dir);
-        g_free (str);
 
         if (! file) {
-                g_set_error (error, 0, 0, _("Missing spec. file '%s'"), file);
-                return NULL;
-        }
-        if (!gda_server_operation_is_valid (op, file, error)) {
-                g_free (file);
-                return NULL;
+		const gchar *contents;
+		contents = emb_get_file (str);
+		if (!contents) {
+			g_set_error (error, 0, 0, _("Missing spec. file '%s'"), str);
+			g_free (str);
+			return NULL;
+		}
+		/* else: TO_IMPLEMENT */
         }
-        g_free (file);
+	else {
+		g_free (str);
+		if (!gda_server_operation_is_valid (op, file, error)) {
+			g_free (file);
+			return NULL;
+		}
+		g_free (file);
+	}
 
 	/* actual rendering */
         switch (gda_server_operation_get_op_type (op)) {

Added: branches/LIBGDA_4.0/libgda/sqlite/gen_emb_string.c
==============================================================================
--- (empty file)
+++ branches/LIBGDA_4.0/libgda/sqlite/gen_emb_string.c	Wed Mar 25 20:57:11 2009
@@ -0,0 +1,195 @@
+/* 
+ * Copyright (C) 2009 Vivien Malerba
+ *
+ * This Library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This Library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this Library; see the file COPYING.LIB.  If not,
+ * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+/*
+ * This program generates a string array using *.xml.in files passed as argument
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <errno.h>
+
+#define MAXSIZE 65536
+#define MAXFILES 128
+
+typedef struct {
+	char *fname;
+	int start;
+} EmbFile;
+
+EmbFile emb_files[MAXFILES];
+
+int 
+main (int argc,char** argv)
+{
+	char buffer[MAXSIZE];
+	int maxlen = MAXSIZE-1;
+	int arg_index;
+	int buffer_index = 0, real_index = 0;
+	int file_index;
+
+	if (argc < 2) {
+		fprintf (stderr, "Usage: %s <file1.xml.in> [...]\n", argv[0]);
+		return 1;
+	}
+	if (argc - 1> MAXFILES) {
+		fprintf (stderr, "Max number of files (%d) reached: %d files to embedd\nIncrease MAXFILES constant and re-run\n", 
+			MAXFILES, argc - 1);
+		return 1;
+	}
+
+	for (file_index = 0, arg_index = 1; 
+	     arg_index < argc;
+	     arg_index++) {
+
+		const char *cfile = argv[arg_index];
+		
+		/* ignore files which do not end in ".xml.in" */
+		int i, len;
+		len = strlen (cfile);
+		if ((len < 8) || strcmp (cfile + len - 7, ".xml.in")) {
+			/* ignore that file */
+			continue;
+		}
+
+		/* prepare file name to embedd: remove directory and the ".in" */
+		EmbFile *efile;		
+		efile = &(emb_files [file_index]);
+		fprintf (stderr, "Embedding %s\n", cfile);
+		for (i = len - 8; i >= 0; i--) {
+			if ((cfile[i] == '/') || (cfile[i] == '\\'))
+				break;
+		}
+		efile->fname = malloc (sizeof (char) * len - i);
+		memcpy (efile->fname, cfile + i + 1, len - i);
+		efile->fname[len - i - 4] = 0;
+		efile->start = real_index;
+		/*fprintf (stderr, "FNAME: %s\n", efile->fname);*/
+
+		/* load file in buffer */
+		FILE *file;
+		long fsize;
+		size_t n_read;
+		
+		file = fopen (cfile, "r");
+		if (!file) {
+			fprintf (stderr, "Can't read '%s'", cfile);
+			return 1;
+		}
+		
+		/* file size */
+		fseek (file , 0 , SEEK_END);
+		fsize = ftell (file);
+		rewind (file);
+		if (fsize + buffer_index >= maxlen) {
+			fprintf (stderr, "Max buffer size reached\nIncrease MAXSIZE constant and re-run\n");
+			return 1;
+		}
+		
+		/* copy the file into the buffer: */
+		n_read = fread (buffer + buffer_index, 1, fsize, file);
+		if (n_read != fsize) {
+			fprintf (stderr, "Reading error");
+			return 1;
+		}
+
+		/* alter buffer */
+		int added = 0;
+		int real_added = 0;
+		for (i = buffer_index; i < buffer_index + n_read + added; i++) {
+			if (buffer_index + n_read + added + 2 >= maxlen) {
+				fprintf (stderr, "Max buffer size reached\nIncrease MAXSIZE constant and re-run\n");
+				return 1;
+			}
+			if (buffer[i] == '"') {
+				added ++;
+				memmove (buffer + i + 1, buffer + i, buffer_index + n_read + added - i);
+				buffer[i] = '\\';
+				i++;
+			}
+			else if (buffer[i] == '\n') {
+				/*
+				added += 1;
+				memmove (buffer + i + 1, buffer + i, buffer_index + n_read + added - i);
+				buffer[i] = '\\';
+				buffer[i+1] = 'n';
+				i += 1;
+				*/
+				added += 4;
+				memmove (buffer + i + 4, buffer + i, buffer_index + n_read + added - i);
+				buffer[i] = '\\';
+				buffer[i+1] = 'n';
+				buffer[i+2] = '"';
+				buffer[i+3] = '\n';
+				buffer[i+4] = '"';
+				i += 4;
+			}
+			else if ((buffer[i] == '_') && (i > buffer_index) && (buffer[i-1] == ' ')) {
+				added --;
+				real_added --;
+				buffer[i] = ' ';
+				memmove (buffer + i - 1, buffer + i, buffer_index + n_read + added - i);
+				i --;
+			}
+		}
+
+		real_index += n_read + real_added;
+		buffer_index += n_read + added -1;
+		buffer [buffer_index] = '\\';
+		buffer_index ++;
+		buffer [buffer_index] = '0';
+		buffer_index ++;
+		file_index ++;
+		
+		fclose (file);
+	}
+	buffer [buffer_index] = 0;
+
+	/* Output */
+	int i;
+	
+	printf ("typedef struct {\n\tgchar *fname;\n\tint start;\n} EmbFile;\n\nEmbFile emb_index[%d] = {\n",
+		file_index);
+	for (i = 0; i < file_index; i++) {
+		EmbFile *efile;		
+		efile = &(emb_files [i]);
+
+		printf ("\t{\"%s\", %d}", efile->fname, efile->start);
+		if (i < file_index - 1)
+			printf (",\n");
+		else
+			printf ("\n");
+	}
+	printf ("};\n\n");
+	printf ("gchar *emb_string=\"%s\";\n\n", buffer);
+
+	printf ("static const gchar *\nemb_get_file (const gchar *fname)\n"
+		"{\n\tgint i;\n\tfor (i = 0; i < %d; i++) {\n"
+		"\t\tEmbFile *efile = &(emb_index[i]);\n"
+		"\t\tif (!strcmp (efile->fname, fname))\n"
+		"\t\t\treturn (emb_string + efile->start);\n"
+		"\t}\n"
+		"\treturn NULL;\n}\n\n",
+		file_index);
+
+
+	return 0;
+}

Modified: branches/LIBGDA_4.0/providers/mysql/gda-mysql-provider.c
==============================================================================
--- branches/LIBGDA_4.0/providers/mysql/gda-mysql-provider.c	(original)
+++ branches/LIBGDA_4.0/providers/mysql/gda-mysql-provider.c	Wed Mar 25 20:57:11 2009
@@ -753,12 +753,13 @@
 	dir = gda_gbr_get_file_path (GDA_DATA_DIR, LIBGDA_ABI_NAME, NULL);
         file = gda_server_provider_find_file (provider, dir, str);
 	g_free (dir);
-        g_free (str);
 
         if (! file) {
-                g_set_error (error, 0, 0, _("Missing spec. file '%s'"), file);
+                g_set_error (error, 0, 0, _("Missing spec. file '%s'"), str);
+		g_free (str);
                 return NULL;
         }
+        g_free (str);
 
         op = gda_server_operation_new (type, file);
         g_free (file);
@@ -793,12 +794,13 @@
 	dir = gda_gbr_get_file_path (GDA_DATA_DIR, LIBGDA_ABI_NAME, NULL);
         file = gda_server_provider_find_file (provider, dir, str);
 	g_free (dir);
-        g_free (str);
 
         if (! file) {
-                g_set_error (error, 0, 0, _("Missing spec. file '%s'"), file);
+                g_set_error (error, 0, 0, _("Missing spec. file '%s'"), str);
+		g_free (str);
                 return NULL;
         }
+        g_free (str);
         if (!gda_server_operation_is_valid (op, file, error)) {
                 g_free (file);
                 return NULL;

Modified: branches/LIBGDA_4.0/providers/postgres/gda-postgres-provider.c
==============================================================================
--- branches/LIBGDA_4.0/providers/postgres/gda-postgres-provider.c	(original)
+++ branches/LIBGDA_4.0/providers/postgres/gda-postgres-provider.c	Wed Mar 25 20:57:11 2009
@@ -908,12 +908,13 @@
 	dir = gda_gbr_get_file_path (GDA_DATA_DIR, LIBGDA_ABI_NAME, NULL);
         file = gda_server_provider_find_file (provider, dir, str);
 	g_free (dir);
-        g_free (str);
 
         if (! file) {
-                g_set_error (error, 0, 0, _("Missing spec. file '%s'"), file);
+                g_set_error (error, 0, 0, _("Missing spec. file '%s'"), str);
+		g_free (str);
                 return NULL;
         }
+        g_free (str);
 
         op = gda_server_operation_new (type, file);
         g_free (file);
@@ -946,12 +947,13 @@
 	dir = gda_gbr_get_file_path (GDA_DATA_DIR, LIBGDA_ABI_NAME, NULL);
         file = gda_server_provider_find_file (provider, dir, str);
 	g_free (dir);
-        g_free (str);
 
         if (! file) {
-                g_set_error (error, 0, 0, _("Missing spec. file '%s'"), file);
+                g_set_error (error, 0, 0, _("Missing spec. file '%s'"), str);
+		g_free (str);
                 return NULL;
         }
+        g_free (str);
         if (!gda_server_operation_is_valid (op, file, error)) {
                 g_free (file);
                 return NULL;

Modified: branches/LIBGDA_4.0/providers/skel-implementation/capi/gda-capi-provider.c
==============================================================================
--- branches/LIBGDA_4.0/providers/skel-implementation/capi/gda-capi-provider.c	(original)
+++ branches/LIBGDA_4.0/providers/skel-implementation/capi/gda-capi-provider.c	Wed Mar 25 20:57:11 2009
@@ -504,12 +504,13 @@
 	dir = gda_gbr_get_file_path (GDA_DATA_DIR, LIBGDA_ABI_NAME, NULL);
         file = gda_server_provider_find_file (provider, dir, str);
 	g_free (dir);
-        g_free (str);
 
         if (! file) {
-                g_set_error (error, 0, 0, _("Missing spec. file '%s'"), file);
+                g_set_error (error, 0, 0, _("Missing spec. file '%s'"), str);
+		g_free (str);
                 return NULL;
         }
+        g_free (str);
 
         op = gda_server_operation_new (type, file);
         g_free (file);
@@ -542,12 +543,13 @@
 	dir = gda_gbr_get_file_path (GDA_DATA_DIR, LIBGDA_ABI_NAME, NULL);
         file = gda_server_provider_find_file (provider, dir, str);
 	g_free (dir);
-        g_free (str);
 
         if (! file) {
-                g_set_error (error, 0, 0, _("Missing spec. file '%s'"), file);
+                g_set_error (error, 0, 0, _("Missing spec. file '%s'"), str);
+		g_free (str);
                 return NULL;
         }
+        g_free (str);
         if (!gda_server_operation_is_valid (op, file, error)) {
                 g_free (file);
                 return NULL;

Modified: branches/LIBGDA_4.0/tools/gda-sql.c
==============================================================================
--- branches/LIBGDA_4.0/tools/gda-sql.c	(original)
+++ branches/LIBGDA_4.0/tools/gda-sql.c	Wed Mar 25 20:57:11 2009
@@ -1404,7 +1404,8 @@
 		}
 		else {
 			store = gda_meta_store_new (NULL);
-			update_store = TRUE;
+			if (store)
+				update_store = TRUE;
 		}
 
 		g_object_set (G_OBJECT (cs->cnc), "meta-store", store, NULL);
@@ -1450,7 +1451,8 @@
 						g_print (_("Done.\n"));
 			}
 		}
-		g_object_unref (store);
+		if (store)
+			g_object_unref (store);
 	}
 
 	return cs;



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