libgda r3302 - in trunk: . libgda



Author: vivien
Date: Tue Jan 27 19:51:42 2009
New Revision: 3302
URL: http://svn.gnome.org/viewvc/libgda?rev=3302&view=rev

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

	* libgda/libgda.symbols:
	* libgda/gda-easy.[ch]: added gda_insert_row_into_table_v() and
	gda_update_row_in_table_v() to facilitate C++ bindings; fixes bug #568484
	* libgda/gda-easy.c:
	* libgda/gda-meta-store.c:
	* libgda/gda-util.c:
	* libgda/gda-config.c: fixed memory leaks
	* configure.in:
	* libgda/gda-config.c: if available, use GIO to monitor config files changes
	instead of FAM or gamin, fixes bug #486021


Modified:
   trunk/ChangeLog
   trunk/configure.in
   trunk/libgda/gda-config.c
   trunk/libgda/gda-easy.c
   trunk/libgda/gda-easy.h
   trunk/libgda/gda-meta-store.c
   trunk/libgda/gda-util.c
   trunk/libgda/libgda.symbols

Modified: trunk/configure.in
==============================================================================
--- trunk/configure.in	(original)
+++ trunk/configure.in	Tue Jan 27 19:51:42 2009
@@ -200,32 +200,10 @@
 AC_SUBST(NO_UNDEFINED)
 AC_SUBST(SOPREFIX)
 
-dnl ******************************
-dnl Checking for FAM or gamin
-dnl ******************************
-FAM_LIBS=
-FAM_CFLAGS=
-FAM_MISSING_WARNING="Libgda depends on FAM to provide notification when configuration files are changed, without FAM support any application using Libgda will have to be restarted when configuration files are changed to take into account those changes"
-PKG_CHECK_MODULES(GAMIN, gamin >= 0.1.8, have_fam=yes, have_fam=no)
-if test x"$have_fam" = "xyes"
-then
-        FAM_CFLAGS="$GAMIN_CFLAGS"
-        FAM_LIBS="$GAMIN_LIBS"
-	AC_DEFINE(HAVE_FAM, [], [Define if we have FAM])
-else
-        AC_CHECK_LIB(fam, FAMOpen,
-          [AC_CHECK_HEADERS(fam.h,
-            [AC_DEFINE(HAVE_FAM, [], [Define if we have FAM])
-             FAM_LIBS="-lfam"],
-            AC_MSG_WARN(*** FAM support will not be built (header files not found) $FAM_MISSING_WARNING ***))],
-          AC_MSG_WARN(*** FAM support will not be built (FAM library not found) $FAM_MISSING_WARNING ***))
-fi
-AC_SUBST(FAM_LIBS)
-AC_SUBST(FAM_CFLAGS)
-
-dnl ***********************************************
+dnl *******************************************************
 dnl Checks for GIO or Gnome VFS, use GIO preferably
-dnl ***********************************************
+dnl if GIO is not found, then see if FAM or gamin are found
+dnl *******************************************************
 
 GNOMEVFS_MODULES="gnome-vfs-2.0 >= 2.20"
 PKG_CHECK_MODULES(GNOMEVFS, $GNOMEVFS_MODULES, have_gnomevfs=yes, have_gnomevfs=no)
@@ -234,7 +212,7 @@
         GNOMEVFS_CFLAGS="$GNOMEVFS_CFLAGS -DHAVE_GNOMEVFS"
 fi
 
-GIO_MODULES="gio-2.0"
+GIO_MODULES="gio-2.0 >= 2.16"
 PKG_CHECK_MODULES(GIO, $GIO_MODULES, have_gio=yes, have_gio=no)
 AM_CONDITIONAL(HAVE_GIO, test x"$have_gio" = "xyes")
 if test x"$have_gio" = "xyes"
@@ -243,6 +221,26 @@
 	GNOMEVFS_CFLAGS=""
 	GNOMEVFS_LIBS=""
 	have_gnomevfs=no
+else
+	FAM_LIBS=
+	FAM_CFLAGS=
+	FAM_MISSING_WARNING="Libgda depends on FAM to provide notification when configuration files are changed, without FAM support any application using Libgda will have to be restarted when configuration files are changed to take into account those changes"
+	PKG_CHECK_MODULES(GAMIN, gamin >= 0.1.8, have_fam=yes, have_fam=no)
+	if test x"$have_fam" = "xyes"
+	then
+	        FAM_CFLAGS="$GAMIN_CFLAGS"
+	        FAM_LIBS="$GAMIN_LIBS"
+		AC_DEFINE(HAVE_FAM, [], [Define if we have FAM])
+	else
+	        AC_CHECK_LIB(fam, FAMOpen,
+	          [AC_CHECK_HEADERS(fam.h,
+	            [AC_DEFINE(HAVE_FAM, [], [Define if we have FAM])
+	             FAM_LIBS="-lfam"],
+	            AC_MSG_WARN(*** FAM support will not be built (header files not found) $FAM_MISSING_WARNING ***))],
+	          AC_MSG_WARN(*** FAM support will not be built (FAM library not found) $FAM_MISSING_WARNING ***))
+	fi
+	AC_SUBST(FAM_LIBS)
+	AC_SUBST(FAM_CFLAGS)	
 fi
 AC_SUBST(GIO_CFLAGS)
 AC_SUBST(GIO_LIBS)

Modified: trunk/libgda/gda-config.c
==============================================================================
--- trunk/libgda/gda-config.c	(original)
+++ trunk/libgda/gda-config.c	Tue Jan 27 19:51:42 2009
@@ -34,12 +34,19 @@
 #include <libgda/gda-holder.h>
 #include <libgda/gda-log.h>
 #include <libgda/gda-util.h>
-#ifdef HAVE_FAM
-#include <fam.h>
-#include <glib.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
+#ifdef HAVE_GIO
+  #ifdef HAVE_FAM
+    #error Impossible to have GIO and FAM at the same time
+  #endif
+  #include <gio/gio.h>
+#else
+  #ifdef HAVE_FAM
+    #include <fam.h>
+    #include <glib.h>
+    #include <sys/types.h>
+    #include <sys/stat.h>
+    #include <unistd.h>
+  #endif
 #endif
 #ifdef G_OS_WIN32 
 #include <io.h>
@@ -101,9 +108,24 @@
 
 static GObjectClass *parent_class = NULL;
 
+#ifdef HAVE_GIO
+/*
+ * GIO static variables
+ */
+static GFileMonitor *mon_conf_user = NULL;
+static GFileMonitor *mon_conf_global = NULL;
+gulong user_notify_changes = 0;
+gulong global_notify_changes = 0;
+
+static void conf_file_changed (GFileMonitor *mon, GFile *file, GFile *other_file,
+			       GFileMonitorEvent event_type, gpointer data);
+static void lock_notify_changes (void);
+static void unlock_notify_changes (void);
+#endif
+
 #ifdef HAVE_FAM
 /*
- * FAM delcarations and static variables
+ * FAM declarations and static variables
  */
 static FAMConnection *fam_connection = NULL;
 static gint           fam_watch_id = 0;
@@ -399,6 +421,9 @@
 		xmlSetProp (entry, BAD_CAST "value", BAD_CAST (info->description));
 	}
 
+#ifdef HAVE_GIO
+	lock_notify_changes ();
+#endif
 #ifdef HAVE_FAM
         fam_lock_notify ();
 #endif
@@ -411,6 +436,9 @@
                         g_warning ("Error saving config data to '%s'", unique_instance->priv->system_file);
 	}
 	fflush (NULL);
+#ifdef HAVE_GIO
+	unlock_notify_changes ();
+#endif
 #ifdef HAVE_FAM
         fam_unlock_notify ();
 #endif
@@ -533,6 +561,22 @@
 		}
 
 		/* Setup file monitoring */
+#ifdef HAVE_GIO
+		GFile *gf;
+		gf = g_file_new_for_path (unique_instance->priv->user_file);
+		mon_conf_user = g_file_monitor_file (gf, G_FILE_MONITOR_NONE, NULL, NULL);
+		if (mon_conf_user)
+			g_signal_connect (G_OBJECT (mon_conf_user), "changed",
+					  G_CALLBACK (conf_file_changed), NULL);
+
+		gf = g_file_new_for_path (unique_instance->priv->system_file);
+		mon_conf_global = g_file_monitor_file (gf, G_FILE_MONITOR_NONE, NULL, NULL);
+		if (mon_conf_user)
+			g_signal_connect (G_OBJECT (mon_conf_global), "changed",
+					  G_CALLBACK (conf_file_changed), NULL);
+		
+#endif
+
 #ifdef HAVE_FAM
 		if (!fam_connection) {
 			/* FAM init */
@@ -543,7 +587,7 @@
 			g_print ("Using FAM to monitor configuration files changes.\n");
 #endif
 			fam_connection = g_malloc0 (sizeof (FAMConnection));
-			if (FAMOpen2 (fam_connection, "libgnomedb user") != 0) {
+			if (FAMOpen2 (fam_connection, "libgda user") != 0) {
 				g_print ("FAMOpen failed, FAMErrno=%d\n", FAMErrno);
 				g_free (fam_connection);
 				fam_connection = NULL;
@@ -1485,6 +1529,7 @@
 #endif
 			}
 		}
+		g_free (path);
 		g_module_close (handle);
 	}
 
@@ -1548,6 +1593,61 @@
 /*
  * File monitoring actions
  */
+#ifdef HAVE_GIO
+static void
+conf_file_changed (GFileMonitor *mon, GFile *file, GFile *other_file,
+		   GFileMonitorEvent event_type, gpointer data)
+{
+	g_assert (unique_instance);
+
+	if (event_type != G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT)
+		return;
+
+	gboolean is_system = (mon == mon_conf_global) ? TRUE : FALSE;
+#ifdef GDA_DEBUG_NO
+	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) {
+		GdaDsnInfo *info = (GdaDsnInfo *) list->data;
+		g_print ("[info %p]: %s/%s\n", info, info->provider, info->name);
+	}
+#endif
+	while (unique_instance->priv->dsn_list) {
+		GdaDsnInfo *info = (GdaDsnInfo *) unique_instance->priv->dsn_list->data;
+		g_signal_emit (unique_instance, gda_config_signals[DSN_TO_BE_REMOVED], 0, info);
+		unique_instance->priv->dsn_list = g_slist_remove (unique_instance->priv->dsn_list, info);
+		g_signal_emit (unique_instance, gda_config_signals[DSN_REMOVED], 0, info);
+		data_source_info_free (info);
+	}
+	
+	lock_notify_changes ();
+	if (unique_instance->priv->system_file)
+		load_config_file (unique_instance->priv->system_file, TRUE);
+	if (unique_instance->priv->user_file)
+		load_config_file (unique_instance->priv->user_file, FALSE);
+	unlock_notify_changes ();
+}
+
+static void
+lock_notify_changes (void)
+{
+	if (user_notify_changes != 0)
+		g_signal_handler_block (mon_conf_user, user_notify_changes);
+	if (global_notify_changes != 0)
+		g_signal_handler_block (mon_conf_global, global_notify_changes);
+}
+
+static void
+unlock_notify_changes (void)
+{
+	if (user_notify_changes != 0)
+		g_signal_handler_unblock (mon_conf_user, user_notify_changes);
+	if (global_notify_changes != 0)
+		g_signal_handler_unblock (mon_conf_global, global_notify_changes);
+}
+
+#endif
+
 #ifdef HAVE_FAM
 static gboolean
 fam_callback (GIOChannel *source, GIOCondition condition, gpointer data)

Modified: trunk/libgda/gda-easy.c
==============================================================================
--- trunk/libgda/gda-easy.c	(original)
+++ trunk/libgda/gda-easy.c	Tue Jan 27 19:51:42 2009
@@ -556,7 +556,8 @@
  * @table: table's name to insert into
  * @error: a place to store errors, or %NULL
  * @...: a list of string/GValue pairs with the name of the column to use and the
- * GValue pointer containing the value to insert for the column (value can be %NULL), finished by a %NULL
+ * GValue pointer containing the value to insert for the column (value can be %NULL), finished by a %NULL. There must be
+ * at least one column name and value
  * 
  * This is a convenience function, which creates an INSERT statement and executes it using the values
  * provided. It internally relies on variables which makes it immune to SQL injection problems.
@@ -568,26 +569,82 @@
 gboolean
 gda_insert_row_into_table (GdaConnection *cnc, const gchar *table, GError **error, ...)
 {
+	GSList *clist = NULL;
+	GSList *vlist = NULL;
 	gboolean retval;
 	va_list  args;
 	gchar *col_name;
+	
+	g_return_val_if_fail (GDA_IS_CONNECTION (cnc), FALSE);
+	g_return_val_if_fail (table && *table, FALSE);
+	
+	va_start (args, error);	
+	while ((col_name = va_arg (args, gchar*))) {
+		clist = g_slist_prepend (clist, col_name);
+		GValue *value;
+		value = va_arg (args, GValue *);
+		vlist = g_slist_prepend (vlist, value);
+	}
+	
+	va_end (args);
+
+	if (!clist) {
+		g_warning ("No specified column or value");
+		return FALSE;
+	}
+
+	clist = g_slist_reverse (clist);
+	vlist = g_slist_reverse (vlist);
+	retval = gda_insert_row_into_table_v (cnc, table, clist, vlist, error);
+	g_slist_free (clist);
+	g_slist_free (vlist);
+
+	return retval;
+}
+
+/**
+ * gda_insert_row_into_table_v
+ * @cnc: an opened connection
+ * @table: table's name to insert into
+ * @col_names: a list of column names (as const gchar *)
+ * @values: a list of values (as #GValue)
+ * @error: a place to store errors, or %NULL
+ *
+ * @col_names and @values must have length (&gt;= 1).
+ *
+ * This is a convenience function, which creates an INSERT statement and executes it using the values
+ * provided. It internally relies on variables which makes it immune to SQL injection problems.
+ *
+ * The equivalent SQL command is: INSERT INTO &lt;table&gt; (&lt;column_name&gt; [,...]) VALUES (&lt;column_name&gt; = &lt;new_value&gt; [,...]).
+ * 
+ * Returns: TRUE if no error occurred
+ */
+gboolean
+gda_insert_row_into_table_v (GdaConnection *cnc, const gchar *table,
+			     GSList *col_names, GSList *values,
+			     GError **error)
+{
+	gboolean retval;
 	GSList *fields = NULL;
-	GSList *values = NULL;
+	GSList *expr_values = NULL;
 	GdaSqlStatement *sql_stm;
 	GdaSqlStatementInsert *ssi;
 	GdaStatement *insert;
 	gint i;
 
 	GSList *holders = NULL;
+	GSList *l1, *l2;
 	
 	g_return_val_if_fail (GDA_IS_CONNECTION (cnc), FALSE);
 	g_return_val_if_fail (table && *table, FALSE);
+	g_return_val_if_fail (col_names, FALSE);
+	g_return_val_if_fail (g_slist_length (col_names) == g_slist_length (values), FALSE);
 	
 	/* Construct insert query and list of GdaHolders */
-	va_start (args, error);
-	
-	ssi = g_new0 (GdaSqlStatementInsert, 1);
-	GDA_SQL_ANY_PART (ssi)->type = GDA_SQL_ANY_STMT_INSERT;
+	sql_stm = gda_sql_statement_new (GDA_SQL_STATEMENT_INSERT);
+	ssi = (GdaSqlStatementInsert*) sql_stm->contents;
+	g_assert (GDA_SQL_ANY_PART (ssi)->type == GDA_SQL_ANY_STMT_INSERT);
+
 	ssi->table = gda_sql_table_new (GDA_SQL_ANY_PART (ssi));
 	if (gda_sql_identifier_needs_quotes (table))
 		ssi->table->table_name = gda_sql_identifier_add_quotes (table);
@@ -595,10 +652,13 @@
 		ssi->table->table_name = g_strdup (table);
 
 	i = 0;
-	while ((col_name = va_arg (args, gchar*))) {
+	for (l1 = col_names, l2 = values;
+	     l1;
+	     l1 = l1->next, l2 = l2->next) {
 		GdaSqlField *field;
 		GdaSqlExpr *expr;
-		GValue *value;
+		GValue *value = (GValue *) l2->data;
+		const gchar *col_name = (const gchar*) l1->data; 
 		
 		/* field */
 		field = gda_sql_field_new (GDA_SQL_ANY_PART (ssi));
@@ -609,7 +669,6 @@
 		fields = g_slist_prepend (fields, field);
 
 		/* value */
-		value = va_arg (args, GValue *);
 		expr = gda_sql_expr_new (GDA_SQL_ANY_PART (ssi));
 		if (value && (G_VALUE_TYPE (value) != GDA_TYPE_NULL)) {
 			/* create a GdaSqlExpr with a parameter */
@@ -629,18 +688,13 @@
 		else {
 			/* create a NULL GdaSqlExpr => nothing to do */
 		}
-		values = g_slist_prepend (values, expr);
+		expr_values = g_slist_prepend (expr_values, expr);
 		
 		i++;
 	}
 	
-	va_end (args);
-
 	ssi->fields_list = g_slist_reverse (fields);
-	ssi->values_list = g_slist_prepend (NULL, g_slist_reverse (values));
-	
-	sql_stm = gda_sql_statement_new (GDA_SQL_STATEMENT_INSERT);
-	sql_stm->contents = ssi;
+	ssi->values_list = g_slist_prepend (NULL, g_slist_reverse (expr_values));
 	
 	insert = gda_statement_new ();
 	g_object_set (G_OBJECT (insert), "structure", sql_stm, NULL);
@@ -660,11 +714,10 @@
 		g_object_unref (set);
 	g_object_unref (insert);
 
-	return retval;
+	return retval;	
 }
 
 
-
 /**
  * gda_update_row_in_table
  * @cnc: an opened connection
@@ -673,7 +726,8 @@
  * @condition_value: the @condition_column_type's GType
  * @error: a place to store errors, or %NULL
  * ...: a list of string/GValue pairs with the name of the column to use and the
- * GValue pointer containing the value to update the column to (value can be %NULL), finished by a %NULL
+ * GValue pointer containing the value to update the column to (value can be %NULL), finished by a %NULL. There must be
+ * at least one column name and value
  * 
  * This is a convenience function, which creates an UPDATE statement and executes it using the values
  * provided. It internally relies on variables which makes it immune to SQL injection problems.
@@ -687,24 +741,86 @@
 			 const gchar *condition_column_name, 
 			 GValue *condition_value, GError **error, ...)
 {
+	GSList *clist = NULL;
+	GSList *vlist = NULL;
 	gboolean retval;
 	va_list  args;
 	gchar *col_name;
+	
+	g_return_val_if_fail (GDA_IS_CONNECTION (cnc), FALSE);
+	g_return_val_if_fail (table && *table, FALSE);
+	
+	va_start (args, error);	
+	while ((col_name = va_arg (args, gchar*))) {
+		clist = g_slist_prepend (clist, col_name);
+		GValue *value;
+		value = va_arg (args, GValue *);
+		vlist = g_slist_prepend (vlist, value);
+	}
+	
+	va_end (args);
+
+	if (!clist) {
+		g_warning ("No specified column or value");
+		return FALSE;
+	}
+
+	clist = g_slist_reverse (clist);
+	vlist = g_slist_reverse (vlist);
+	retval = gda_update_row_in_table_v (cnc, table, condition_column_name, condition_value, clist, vlist, error);
+	g_slist_free (clist);
+	g_slist_free (vlist);
+
+	return retval;
+}
+
+/**
+ * gda_update_row_in_table_v
+ * @cnc: an opened connection
+ * @table: the table's name with the row's values to be updated
+ * @condition_column_name: the name of the column to used in the WHERE condition clause
+ * @condition_value: the @condition_column_type's GType
+ * @col_names: a list of column names (as const gchar *)
+ * @values: a list of values (as #GValue)
+ * @error: a place to store errors, or %NULL
+ *
+ * @col_names and @values must have length (&gt;= 1).
+ * 
+ * This is a convenience function, which creates an UPDATE statement and executes it using the values
+ * provided. It internally relies on variables which makes it immune to SQL injection problems.
+ *
+ * The equivalent SQL command is: UPDATE &lt;table&gt; SET &lt;column_name&gt; = &lt;new_value&gt; [,...] WHERE &lt;condition_column_name&gt; = &lt;condition_value&gt;.
+ *
+ * Returns: TRUE if no error occurred
+ */
+gboolean
+gda_update_row_in_table_v (GdaConnection *cnc, const gchar *table, 
+			   const gchar *condition_column_name, 
+			   GValue *condition_value, 
+			   GSList *col_names, GSList *values,
+			   GError **error)
+{
+	gboolean retval;
 	GSList *fields = NULL;
-	GSList *values = NULL;
+	GSList *expr_values = NULL;
 	GdaSqlStatement *sql_stm;
 	GdaSqlStatementUpdate *ssu;
 	GdaStatement *update;
 	gint i;
 
 	GSList *holders = NULL;
-	
+	GSList *l1, *l2;
+
 	g_return_val_if_fail (GDA_IS_CONNECTION (cnc), FALSE);
 	g_return_val_if_fail (table && *table, FALSE);
+	g_return_val_if_fail (col_names, FALSE);
+	g_return_val_if_fail (g_slist_length (col_names) == g_slist_length (values), FALSE);
 	
-	/* Construct insert query and list of GdaHolders */
-	ssu = g_new0 (GdaSqlStatementUpdate, 1);
-	GDA_SQL_ANY_PART (ssu)->type = GDA_SQL_ANY_STMT_UPDATE;
+	/* Construct update query and list of GdaHolders */
+	sql_stm = gda_sql_statement_new (GDA_SQL_STATEMENT_UPDATE);
+	ssu = (GdaSqlStatementUpdate*) sql_stm->contents;
+	g_assert (GDA_SQL_ANY_PART (ssu)->type == GDA_SQL_ANY_STMT_UPDATE);
+
 	ssu->table = gda_sql_table_new (GDA_SQL_ANY_PART (ssu));
 	if (gda_sql_identifier_needs_quotes (table))
 		ssu->table->table_name = gda_sql_identifier_add_quotes (table);
@@ -748,12 +864,14 @@
 		}
 	}
 
-	va_start (args, error);
 	i = 0;
-	while ((col_name = va_arg (args, gchar*))) {
+	for (l1 = col_names, l2 = values;
+	     l1;
+	     l1 = l1->next, l2 = l2->next) {
+		GValue *value = (GValue *) l2->data;
+		const gchar *col_name = (const gchar*) l1->data;
 		GdaSqlField *field;
 		GdaSqlExpr *expr;
-		GValue *value;
 		
 		/* field */
 		field = gda_sql_field_new (GDA_SQL_ANY_PART (ssu));
@@ -764,7 +882,6 @@
 		fields = g_slist_prepend (fields, field);
 
 		/* value */
-		value = va_arg (args, GValue *);
 		expr = gda_sql_expr_new (GDA_SQL_ANY_PART (ssu));
 		if (value && (G_VALUE_TYPE (value) != GDA_TYPE_NULL)) {
 			/* create a GdaSqlExpr with a parameter */
@@ -784,18 +901,13 @@
 		else {
 			/* create a NULL GdaSqlExpr => nothing to do */
 		}
-		values = g_slist_prepend (values, expr);
+		expr_values = g_slist_prepend (expr_values, expr);
 		
 		i++;
 	}
-	
-	va_end (args);
 
 	ssu->fields_list = g_slist_reverse (fields);
-	ssu->expr_list = g_slist_reverse (values);
-	
-	sql_stm = gda_sql_statement_new (GDA_SQL_STATEMENT_UPDATE);
-	sql_stm->contents = ssu;
+	ssu->expr_list = g_slist_reverse (expr_values);
 	
 	update = gda_statement_new ();
 	g_object_set (G_OBJECT (update), "structure", sql_stm, NULL);
@@ -849,9 +961,11 @@
 	g_return_val_if_fail (GDA_IS_CONNECTION (cnc), FALSE);
 	g_return_val_if_fail (table && *table, FALSE);
 	
-	/* Construct insert query and list of GdaHolders */
-	ssd = g_new0 (GdaSqlStatementDelete, 1);
-	GDA_SQL_ANY_PART (ssd)->type = GDA_SQL_ANY_STMT_DELETE;
+	/* Construct delete query and list of GdaHolders */
+	sql_stm = gda_sql_statement_new (GDA_SQL_STATEMENT_DELETE);
+	ssd = (GdaSqlStatementDelete*) sql_stm->contents;
+	g_assert (GDA_SQL_ANY_PART (ssd)->type == GDA_SQL_ANY_STMT_DELETE);
+
 	ssd->table = gda_sql_table_new (GDA_SQL_ANY_PART (ssd));
 	if (gda_sql_identifier_needs_quotes (table))
 		ssd->table->table_name = gda_sql_identifier_add_quotes (table);
@@ -895,9 +1009,6 @@
 		}
 	}
 
-	sql_stm = gda_sql_statement_new (GDA_SQL_STATEMENT_DELETE);
-	sql_stm->contents = ssd;
-	
 	delete = gda_statement_new ();
 	g_object_set (G_OBJECT (delete), "structure", sql_stm, NULL);
 	gda_sql_statement_free (sql_stm);

Modified: trunk/libgda/gda-easy.h
==============================================================================
--- trunk/libgda/gda-easy.h	(original)
+++ trunk/libgda/gda-easy.h	Tue Jan 27 19:51:42 2009
@@ -88,9 +88,18 @@
  * Data in tables manipulation
  */
 gboolean            gda_insert_row_into_table        (GdaConnection *cnc, const gchar *table, GError **error, ...);
+gboolean            gda_insert_row_into_table_v      (GdaConnection *cnc, const gchar *table,
+						      GSList *col_names, GSList *values,
+						      GError **error);
+
 gboolean            gda_update_row_in_table          (GdaConnection *cnc, const gchar *table, 
 						      const gchar *condition_column_name, 
 						      GValue *condition_value, GError **error, ...);
+gboolean            gda_update_row_in_table_v        (GdaConnection *cnc, const gchar *table, 
+						      const gchar *condition_column_name, 
+						      GValue *condition_value, 
+						      GSList *col_names, GSList *values,
+						      GError **error);
 gboolean            gda_delete_row_from_table        (GdaConnection *cnc, const gchar *table, 
 						      const gchar *condition_column_name, 
 						      GValue *condition_value, GError **error);

Modified: trunk/libgda/gda-meta-store.c
==============================================================================
--- trunk/libgda/gda-meta-store.c	(original)
+++ trunk/libgda/gda-meta-store.c	Tue Jan 27 19:51:42 2009
@@ -1266,15 +1266,24 @@
 	}
 
 	/* INSERT, UPDATE and DELETE statements */
+	GdaSqlStatement *sql_ist;
 	GdaSqlStatementInsert *ist;
+	GdaSqlStatement *sql_ust;
 	GdaSqlStatementUpdate *ust;
+	GdaSqlStatement *sql_dst;
 	GdaSqlStatementDelete *dst;
-	ist = g_new0 (GdaSqlStatementInsert, 1);
-	GDA_SQL_ANY_PART (ist)->type = GDA_SQL_ANY_STMT_INSERT;
-	ust = g_new0 (GdaSqlStatementUpdate, 1);
-	GDA_SQL_ANY_PART (ust)->type = GDA_SQL_ANY_STMT_UPDATE;
-	dst = g_new0 (GdaSqlStatementDelete, 1);
-	GDA_SQL_ANY_PART (dst)->type = GDA_SQL_ANY_STMT_DELETE;
+	
+	sql_ist = gda_sql_statement_new (GDA_SQL_STATEMENT_INSERT);
+	ist = (GdaSqlStatementInsert*) sql_ist->contents;
+	g_assert (GDA_SQL_ANY_PART (ist)->type == GDA_SQL_ANY_STMT_INSERT);
+
+	sql_ust = gda_sql_statement_new (GDA_SQL_STATEMENT_UPDATE);
+	ust = (GdaSqlStatementUpdate*) sql_ust->contents;
+	g_assert (GDA_SQL_ANY_PART (ust)->type == GDA_SQL_ANY_STMT_UPDATE);
+
+	sql_dst = gda_sql_statement_new (GDA_SQL_STATEMENT_DELETE);
+	dst = (GdaSqlStatementDelete*) sql_dst->contents;
+	g_assert (GDA_SQL_ANY_PART (dst)->type == GDA_SQL_ANY_STMT_DELETE);
 	
 	ist->table = gda_sql_table_new (GDA_SQL_ANY_PART (ist));
 	ist->table->table_name = g_strdup ((gchar *) complete_obj_name);
@@ -1535,22 +1544,15 @@
 	}
 
 	/* finish the statements */
-	GdaSqlStatement *st;
 	ist->values_list = g_slist_append (NULL, insert_values_list);
-	st = gda_sql_statement_new (GDA_SQL_STATEMENT_INSERT);
-	st->contents = ist;
-	TABLE_INFO (dbobj)->insert = g_object_new (GDA_TYPE_STATEMENT, "structure", st, NULL);
-	gda_sql_statement_free (st);
-	
-	st = gda_sql_statement_new (GDA_SQL_STATEMENT_UPDATE);
-	st->contents = ust;
-	TABLE_INFO (dbobj)->update = g_object_new (GDA_TYPE_STATEMENT, "structure", st, NULL);
-	gda_sql_statement_free (st);
-	
-	st = gda_sql_statement_new (GDA_SQL_STATEMENT_DELETE);
-	st->contents = dst;
-	TABLE_INFO (dbobj)->delete = g_object_new (GDA_TYPE_STATEMENT, "structure", st, NULL);
-	gda_sql_statement_free (st);
+	TABLE_INFO (dbobj)->insert = g_object_new (GDA_TYPE_STATEMENT, "structure", sql_ist, NULL);
+	gda_sql_statement_free (sql_ist);
+	
+	TABLE_INFO (dbobj)->update = g_object_new (GDA_TYPE_STATEMENT, "structure", sql_ust, NULL);
+	gda_sql_statement_free (sql_ust);
+	
+	TABLE_INFO (dbobj)->delete = g_object_new (GDA_TYPE_STATEMENT, "structure", sql_dst, NULL);
+	gda_sql_statement_free (sql_dst);
 	
 	if (TABLE_INFO (dbobj)->pk_cols_nb == 0)
 		g_error ("Missing key fields identification (table=%s)", complete_obj_name);

Modified: trunk/libgda/gda-util.c
==============================================================================
--- trunk/libgda/gda-util.c	(original)
+++ trunk/libgda/gda-util.c	Tue Jan 27 19:51:42 2009
@@ -890,9 +890,12 @@
 	gboolean retval = TRUE;
 	GdaSqlSelectTarget *target;
 
-	GdaSqlStatementInsert *ist = NULL;
-	GdaSqlStatementUpdate *ust = NULL;
-	GdaSqlStatementDelete *dst = NULL;	
+	GdaSqlStatement *sql_ist = NULL;
+        GdaSqlStatementInsert *ist = NULL;
+        GdaSqlStatement *sql_ust = NULL;
+        GdaSqlStatementUpdate *ust = NULL;
+        GdaSqlStatement *sql_dst = NULL;
+        GdaSqlStatementDelete *dst = NULL;
 
 	g_return_val_if_fail (GDA_IS_CONNECTION (cnc), FALSE);
 	g_return_val_if_fail (GDA_IS_STATEMENT (select_stmt), FALSE);
@@ -921,15 +924,19 @@
 	
 	/* actual statement structure's computation */        
 	if (insert_stmt) {
-		ist = g_new0 (GdaSqlStatementInsert, 1);
-		GDA_SQL_ANY_PART (ist)->type = GDA_SQL_ANY_STMT_INSERT;
+		sql_ist = gda_sql_statement_new (GDA_SQL_STATEMENT_INSERT);
+		ist = (GdaSqlStatementInsert*) sql_ist->contents;
+		g_assert (GDA_SQL_ANY_PART (ist)->type == GDA_SQL_ANY_STMT_INSERT);
+
 		ist->table = gda_sql_table_new (GDA_SQL_ANY_PART (ist));
 		ist->table->table_name = g_strdup ((gchar *) target->table_name);
 	}
 	
 	if (update_stmt) {
-		ust = g_new0 (GdaSqlStatementUpdate, 1);
-		GDA_SQL_ANY_PART (ust)->type = GDA_SQL_ANY_STMT_UPDATE;
+		sql_ust = gda_sql_statement_new (GDA_SQL_STATEMENT_UPDATE);
+		ust = (GdaSqlStatementUpdate*) sql_ust->contents;
+		g_assert (GDA_SQL_ANY_PART (ust)->type == GDA_SQL_ANY_STMT_UPDATE);
+
 		ust->table = gda_sql_table_new (GDA_SQL_ANY_PART (ust));
 		ust->table->table_name = g_strdup ((gchar *) target->table_name);
 		ust->cond = gda_compute_unique_table_row_condition (stsel, 
@@ -943,8 +950,10 @@
 	}
         
 	if (delete_stmt) {
-		dst = g_new0 (GdaSqlStatementDelete, 1);
-		GDA_SQL_ANY_PART (dst)->type = GDA_SQL_ANY_STMT_DELETE;
+		sql_dst = gda_sql_statement_new (GDA_SQL_STATEMENT_DELETE);
+		dst = (GdaSqlStatementDelete*) sql_dst->contents;
+		g_assert (GDA_SQL_ANY_PART (dst)->type == GDA_SQL_ANY_STMT_DELETE);
+
 		dst->table = gda_sql_table_new (GDA_SQL_ANY_PART (dst));
 		dst->table->table_name = g_strdup ((gchar *) target->table_name);
 		dst->cond = gda_compute_unique_table_row_condition (stsel, 
@@ -1015,8 +1024,6 @@
 
 	/* finish the statements */
 	if (insert_stmt) {
-		GdaSqlStatement *st;
-
 		if (!ist->fields_list) {
 			/* nothing to insert => don't create statement */
 			/* To translators: this error message occurs when no "INSERT INTO <table> (field1, ...)..." 
@@ -1027,46 +1034,21 @@
 			goto cleanup;
 		}
 		ist->values_list = g_slist_append (NULL, insert_values_list);
-		st = gda_sql_statement_new (GDA_SQL_STATEMENT_INSERT);
-		st->contents = ist;
-		ist = NULL;
-		ret_insert = g_object_new (GDA_TYPE_STATEMENT, "structure", st, NULL);
-		gda_sql_statement_free (st);
-	}
-	if (update_stmt) {
-		GdaSqlStatement *st;
-		st = gda_sql_statement_new (GDA_SQL_STATEMENT_UPDATE);
-		st->contents = ust;
-		ust = NULL;
-		ret_update = g_object_new (GDA_TYPE_STATEMENT, "structure", st, NULL);
-		gda_sql_statement_free (st);
-	}
-  	if (delete_stmt) {
-		GdaSqlStatement *st;
-		st = gda_sql_statement_new (GDA_SQL_STATEMENT_DELETE);
-		st->contents = dst;
-		dst = NULL;
-		ret_delete = g_object_new (GDA_TYPE_STATEMENT, "structure", st, NULL);
-		gda_sql_statement_free (st);
+		ret_insert = g_object_new (GDA_TYPE_STATEMENT, "structure", sql_ist, NULL);
 	}
+	if (update_stmt)
+		ret_update = g_object_new (GDA_TYPE_STATEMENT, "structure", sql_ust, NULL);
+  	if (delete_stmt)
+		ret_delete = g_object_new (GDA_TYPE_STATEMENT, "structure", sql_dst, NULL);
 	
  cleanup:
 	gda_sql_statement_free (sel_struct);
-	if (ist) {
-		GdaSqlStatementContentsInfo *cinfo;
-		cinfo = gda_sql_statement_get_contents_infos (GDA_SQL_STATEMENT_INSERT);
-		cinfo->free (ist);
-	}
-	if (ust) {
-		GdaSqlStatementContentsInfo *cinfo;
-		cinfo = gda_sql_statement_get_contents_infos (GDA_SQL_STATEMENT_UPDATE);
-		cinfo->free (ust);
-	}
-	if (dst) {
-		GdaSqlStatementContentsInfo *cinfo;
-		cinfo = gda_sql_statement_get_contents_infos (GDA_SQL_STATEMENT_DELETE);
-		cinfo->free (dst);
-	}
+	if (sql_ist)
+		gda_sql_statement_free (sql_ist);
+	if (sql_ust)
+		gda_sql_statement_free (sql_ust);
+	if (sql_dst)
+		gda_sql_statement_free (sql_dst);
 		
 	if (insert_stmt)
 		*insert_stmt = ret_insert;
@@ -1102,8 +1084,10 @@
 	g_return_val_if_fail (upd_stmt->stmt_type == GDA_SQL_STATEMENT_UPDATE, NULL);
 	
 	ust = (GdaSqlStatementUpdate*) upd_stmt->contents;
-	sst = g_new0 (GdaSqlStatementSelect, 1);
-	GDA_SQL_ANY_PART (sst)->type = GDA_SQL_ANY_STMT_SELECT;
+
+	sel_stmt = gda_sql_statement_new (GDA_SQL_STATEMENT_SELECT);
+	sst = (GdaSqlStatementSelect*) sel_stmt->contents;
+	g_assert (GDA_SQL_ANY_PART (sst)->type == GDA_SQL_ANY_STMT_SELECT);
 
 	if (!ust->table || !ust->table->table_name) {
 		g_set_error (error, GDA_SQL_ERROR, GDA_SQL_STRUCTURE_CONTENTS_ERROR,
@@ -1125,9 +1109,6 @@
 
 	gda_sql_statement_free (upd_stmt);
 
-	sel_stmt = gda_sql_statement_new (GDA_SQL_STATEMENT_SELECT);
-	sel_stmt->contents = sst;
-
 	return sel_stmt;
 }
 

Modified: trunk/libgda/libgda.symbols
==============================================================================
--- trunk/libgda/libgda.symbols	(original)
+++ trunk/libgda/libgda.symbols	Tue Jan 27 19:51:42 2009
@@ -380,6 +380,7 @@
 	gda_identifier_hash
 	gda_init
 	gda_insert_row_into_table
+	gda_insert_row_into_table_v
 	gda_lang_locale
 	gda_lockable_get_type
 	gda_lockable_lock
@@ -763,6 +764,7 @@
 	gda_transaction_status_new
 	gda_transaction_status_state_get_type
 	gda_update_row_in_table
+	gda_update_row_in_table_v
 	gda_ushort_get_type
 	gda_utility_check_data_model
 	gda_utility_data_model_dump_data_to_xml



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