libgda r3219 - in trunk: . doc/C doc/C/tmpl libgda libgda/sql-parser libgda/sqlite libgda/sqlite/virtual samples/TableCopy



Author: vivien
Date: Tue Sep 30 18:33:41 2008
New Revision: 3219
URL: http://svn.gnome.org/viewvc/libgda?rev=3219&view=rev

Log:
2008-09-30  Vivien Malerba <malerba gnome-db org>

        * configure.in:
        * libgda/Makefile.am: make sure only the correct symbols are exported:
          - by requiring gmodule-no-export-2.0 instead of gmodule-2.0
          - by excluding csv and sqlite3 symbols
        * libgda/sql-parser/gda-statement-struct-util.c: fixed comment so documentation
        can be built
        * libgda/sql-parser/parser.y: indentation correction
        * libgda/gda-data-model-array.c: added an assertion
        * libgda/gda-data-proxy.c: when the proxied data model is reset, make sure the column types
        are synced
        * libgda/gda-data-select.c: double free memory error corrected,a nd other minor corrections
        * libgda/sqlite/gda-sqlite-meta.c: removed useless debug code
        * libgda/sqlite/virtual/gda-vconnection-data-model-private.h:
        * libgda/sqlite/virtual/gda-vconnection-data-model.c:
        * libgda/sqlite/virtual/gda-vconnection-hub.c:
        * libgda/sqlite/virtual/gda-vprovider-data-model.c:
          - don't compute several times the columns of each virtual table
          - corrected case when the connection does not have any associated GdaMetaStore object
        * samples/TableCopy/common.c:
        * samples/TableCopy/table-copy.c: make this example work again
        * doc/C: doc updates


Modified:
   trunk/ChangeLog
   trunk/configure.in
   trunk/doc/C/migration2.xml
   trunk/doc/C/tmpl/gda-sql-parser.sgml
   trunk/libgda/Makefile.am
   trunk/libgda/gda-data-model-array.c
   trunk/libgda/gda-data-proxy.c
   trunk/libgda/gda-data-select.c
   trunk/libgda/sql-parser/gda-statement-struct-util.c
   trunk/libgda/sql-parser/parser.y
   trunk/libgda/sqlite/gda-sqlite-meta.c
   trunk/libgda/sqlite/virtual/gda-vconnection-data-model-private.h
   trunk/libgda/sqlite/virtual/gda-vconnection-data-model.c
   trunk/libgda/sqlite/virtual/gda-vconnection-hub.c
   trunk/libgda/sqlite/virtual/gda-vprovider-data-model.c
   trunk/samples/TableCopy/common.c
   trunk/samples/TableCopy/table-copy.c

Modified: trunk/configure.in
==============================================================================
--- trunk/configure.in	(original)
+++ trunk/configure.in	Tue Sep 30 18:33:41 2008
@@ -125,7 +125,7 @@
 	glib-2.0	>= req_ver_glib
 	gobject-2.0	>= req_ver_glib
 	gthread-2.0	>= req_ver_glib
-	gmodule-2.0	>= req_ver_glib
+	gmodule-no-export-2.0	>= req_ver_glib
 	libxml-2.0
 ])
 TST_CFLAGS="$LIBGDA_CFLAGS"
@@ -136,6 +136,7 @@
 dnl ******************************
 dnl linklibext is the shared link library extension, which varies by platform
 
+EXPORT_SYM_REGEX='-export-symbols-regex "^[[^(_|sqlite3|pcache|csv|MD5)]].*"'
 AC_MSG_CHECKING([for platform])
 platform_win32=no
 platform_carbon=no
@@ -145,7 +146,7 @@
     AC_MSG_RESULT([Win32 - cygwin])
     NO_UNDEFINED='-no-undefined'
     SOPREFIX='cyg'
-    LIBTOOL_EXPORT_OPTIONS='-export-symbols-regex "^[[^_]].*"'
+    LIBTOOL_EXPORT_OPTIONS=$EXPORT_SYM_REGEX
     linklibext=".dll.a"
     AC_MSG_RESULT([Win32])
     ;;
@@ -165,7 +166,7 @@
     platform_carbon=yes
     SOPREFIX='lib'
     AM_BINRELOC
-    LIBTOOL_EXPORT_OPTIONS='-export-symbols-regex "^[[^_]].*"'
+    LIBTOOL_EXPORT_OPTIONS=$EXPORT_SYM_REGEX
     AC_DEFINE(HAVE_CARBON)
     dnl SO_SUFFIX=dylib
   ;;
@@ -174,7 +175,7 @@
     NO_UNDEFINED=''
     SOPREFIX='lib'
     AM_BINRELOC
-    LIBTOOL_EXPORT_OPTIONS='-export-symbols-regex "^[[^_]].*"'
+    LIBTOOL_EXPORT_OPTIONS=$EXPORT_SYM_REGEX
     ;;
 esac
 

Modified: trunk/doc/C/migration2.xml
==============================================================================
--- trunk/doc/C/migration2.xml	(original)
+++ trunk/doc/C/migration2.xml	Tue Sep 30 18:33:41 2008
@@ -5,8 +5,8 @@
       <itemizedlist>
 	<listitem><para>easier to understand and to use API, with less strange path usage (which were inherited
 	from modifications above modifications where no global coherence was adressed)</para></listitem>
-	<listitem><para>reduce the size of the library (now 1.1M compared to 1.7M once stripped) and the number of symbols 
-	    (880 compared to 1420) and have less complicated and thus more maintanable code (180 files compared to 250).
+	<listitem><para>reduce the size of the library (now 1.3M compared to 1.7M once stripped) and the number of symbols 
+	    (860 compared to 1420) and have less complicated and thus more maintanable code (190 files compared to 250).
 	</para></listitem>
 	<listitem><para>removal of the GdaClient object from which connections were created: this object did not offer
 	    any significant features and made the API more difficult to use</para></listitem>

Modified: trunk/doc/C/tmpl/gda-sql-parser.sgml
==============================================================================
--- trunk/doc/C/tmpl/gda-sql-parser.sgml	(original)
+++ trunk/doc/C/tmpl/gda-sql-parser.sgml	Tue Sep 30 18:33:41 2008
@@ -54,9 +54,20 @@
   <listitem><para><![CDATA[## /* name:NAME [type:TYPE] [nullok:[TRUE|FALSE]] [descr:DESCR] */]]>
       for a variable named NAME with the optional type TYPE (which can be a GType
       name or a custom database type name), with the optional "nullok" attribute and an optional
-      description DESCR.
+      description DESCR. Note that the NAME, TYPE and DESCR literals here must be quoted (simple or double quotes) if
+      they include non alphanumeric characters, and that there must always be at least a space between the 
+      <![CDATA[##]]> and the <![CDATA[/* ... */]]>.
   </para></listitem>
 </itemizedlist>
+Examples of correct place holders definitions are:
+<programlisting>
+## /* name:"+0" type:gchararray */
+## /* name:'-5' type:string */
+## /*name:myvar type:gint descr:ToBeDefined nullok:FALSE*/
+## /*name:myvar type:gint descr:"A long description"*/
+##+0::gcharaccar
+##-5::string
+</programlisting>
 </para>
 
 <para>
@@ -171,3 +182,12 @@
 @Returns: 
 
 
+<!-- ##### FUNCTION gda_sql_identifier_remove_quotes ##### -->
+<para>
+
+</para>
+
+ str: 
+ Returns: 
+
+

Modified: trunk/libgda/Makefile.am
==============================================================================
--- trunk/libgda/Makefile.am	(original)
+++ trunk/libgda/Makefile.am	Tue Sep 30 18:33:41 2008
@@ -174,8 +174,7 @@
 
 libgda_4_0_la_LDFLAGS = \
 	-version-info $(GDA_CURRENT):$(GDA_REVISION):$(GDA_AGE) \
-	$(NO_UNDEFINED) \
-	-export-dynamic $(no_undefined) $(LIBTOOL_EXPORT_OPTIONS)
+	-export-dynamic $(NO_UNDEFINED) $(LIBTOOL_EXPORT_OPTIONS)
 
 libgda_4_0_la_LIBADD = \
 	sql-parser/libgda_sql_parser-4.0.la \

Modified: trunk/libgda/gda-data-model-array.c
==============================================================================
--- trunk/libgda/gda-data-model-array.c	(original)
+++ trunk/libgda/gda-data-model-array.c	Tue Sep 30 18:33:41 2008
@@ -696,7 +696,7 @@
 		dest = gda_row_get_value (row, i);
 		if (list->data) {
 			gda_value_reset_with_type (dest, G_VALUE_TYPE ((GValue *) list->data));
-			gda_value_set_from_value (dest, (GValue *) list->data);
+			g_assert (gda_value_set_from_value (dest, (GValue *) list->data));
 		}
 		else
 			gda_value_set_null (dest);

Modified: trunk/libgda/gda-data-proxy.c
==============================================================================
--- trunk/libgda/gda-data-proxy.c	(original)
+++ trunk/libgda/gda-data-proxy.c	Tue Sep 30 18:33:41 2008
@@ -1064,6 +1064,22 @@
 	gda_data_proxy_init (proxy);
 	g_object_set (G_OBJECT (proxy), "model", model, "prepend-null-entry", add_null_entry, NULL);
 	g_object_unref (G_OBJECT (model));
+
+	if (proxy->priv->columns) {
+		/* adjust column's types */
+		gint i;
+		GdaColumn *orig;
+		for (i = 0; i < proxy->priv->model_nb_cols; i++) {
+			orig = gda_data_model_describe_column (proxy->priv->model, i);
+			gda_column_set_g_type (proxy->priv->columns[i], gda_column_get_g_type (orig));
+		}
+		for (; i < 2 * proxy->priv->model_nb_cols; i++) {
+			orig = gda_data_model_describe_column (proxy->priv->model, 
+							       i -  proxy->priv->model_nb_cols);
+			gda_column_set_g_type (proxy->priv->columns[i], gda_column_get_g_type (orig));
+		}
+	}
+
 	gda_data_model_reset (GDA_DATA_MODEL (proxy));
 }
 
@@ -1908,6 +1924,13 @@
 					gda_value_free (free_val [i]);
 			g_free (free_val);
 			if (!err) {
+				if (proxy->priv->catched_inserted_row < 0) {
+					g_warning (_("Proxied data model reports the modifications as accepted, yet did not emit the "
+						     "corresponding \"row-inserted\", \"row-updated\" or \"row-removed\" signal. This "
+						     "is a bug of the %s's implementation (please report a bug)."),
+						   G_OBJECT_TYPE_NAME (proxy->priv->model));
+				}
+
 				proxy->priv->new_rows = g_slist_remove (proxy->priv->new_rows, rm);
 				proxy->priv->all_modifs = g_slist_remove (proxy->priv->all_modifs, rm);
 				g_hash_table_remove (proxy->priv->modify_rows, GINT_TO_POINTER (rm->model_row));
@@ -1922,12 +1945,6 @@
 					       gda_data_proxy_signals[ROW_CHANGES_APPLIED],
 					       0, proxy_row, -1);
 			}
-			else if (proxy->priv->catched_inserted_row < 0) {
-				g_warning (_("Proxied data model reports the modifications as accepted, yet did not emit the "
-					     "corresponding \"row-inserted\", \"row-updated\" or \"row-removed\" signal. This "
-					     "is a bug of the %s's implementation (please report a bug)."),
-					   G_OBJECT_TYPE_NAME (proxy->priv->model));
-			}
 
 			proxy->priv->catched_inserted_row = -1;
 			proxy->priv->defer_proxied_model_insert = FALSE;
@@ -3125,7 +3142,7 @@
 	/* current proxy's values */
 	for (i = 0; i < proxy->priv->model_nb_cols; i++) {
 		GdaColumn *orig;
-
+		
 		orig = gda_data_model_describe_column (proxy->priv->model, i);
 		proxy->priv->columns[i] = gda_column_copy (orig);
 		gda_column_set_position (proxy->priv->columns[i], i);
@@ -3162,7 +3179,6 @@
 
 	if (!proxy->priv->columns)
 		create_columns (proxy);
-
 	return proxy->priv->columns [col];
 }
 

Modified: trunk/libgda/gda-data-select.c
==============================================================================
--- trunk/libgda/gda-data-select.c	(original)
+++ trunk/libgda/gda-data-select.c	Tue Sep 30 18:33:41 2008
@@ -2725,7 +2725,7 @@
 	if (imodel->priv->modif_internals->safely_locked) {
 		g_set_error (error, GDA_DATA_SELECT_ERROR, GDA_DATA_SELECT_SAFETY_LOCKED_ERROR,
 			     _("Modifications are not allowed anymore"));
-		return FALSE;
+		return -1;
 	}
 	if (! (imodel->priv->usage_flags & GDA_DATA_MODEL_ACCESS_RANDOM)) {
 		g_set_error (error, GDA_DATA_MODEL_ERROR, GDA_DATA_MODEL_ACCESS_ERROR,
@@ -2774,8 +2774,10 @@
 	/* compute INSERT statement */
 	GdaStatement *stmt;
 	if (! imodel->priv->modif_internals->ins_stmts)
-		imodel->priv->modif_internals->ins_stmts = g_hash_table_new_full ((GHashFunc) bvector_hash, (GEqualFunc) bvector_equal, 
-								 (GDestroyNotify) bvector_free, g_object_unref);
+		imodel->priv->modif_internals->ins_stmts = g_hash_table_new_full ((GHashFunc) bvector_hash, 
+										  (GEqualFunc) bvector_equal, 
+										  (GDestroyNotify) bvector_free, 
+										  g_object_unref);
 	stmt = g_hash_table_lookup (imodel->priv->modif_internals->ins_stmts, bv);
 	if (! stmt) {
 		stmt = compute_single_insert_stmt (imodel, bv, error);
@@ -2800,11 +2802,13 @@
 		if (! holder) {
 			g_set_error (error, GDA_DATA_SELECT_ERROR, GDA_DATA_SELECT_MISSING_MODIFICATION_STATEMENT_ERROR,
 				     _("Column %d can't be modified"), i);
-			bvector_free (bv);
+			if (free_bv)
+				bvector_free (bv);
 			return -1;
 		}
 		if (! gda_holder_set_value (holder, (GValue *) list->data, error)) {
-			bvector_free (bv);
+			if (free_bv)
+				bvector_free (bv);
 			return -1;
 		}
 	}
@@ -2832,6 +2836,12 @@
 	g_free (sql);
 #endif
 
+	if (! imodel->priv->modif_internals->one_row_select_stmt) {
+		imodel->priv->modif_internals->one_row_select_stmt = compute_single_select_stmt (imodel, error);
+		if (!imodel->priv->modif_internals->one_row_select_stmt)
+			return -1;
+	}
+
 	GdaSet *last_insert;
 	if (gda_connection_statement_execute_non_select (imodel->priv->cnc, stmt,
 							 imodel->priv->modif_internals->modif_set, &last_insert, error) == -1)
@@ -2840,8 +2850,6 @@
 	/* mark that this row has been modified */
 	DelayedSelectStmt *dstmt;
 	dstmt = g_new0 (DelayedSelectStmt, 1);
-	if (! imodel->priv->modif_internals->one_row_select_stmt)
-		imodel->priv->modif_internals->one_row_select_stmt = compute_single_select_stmt (imodel, error);
 	if (last_insert && imodel->priv->modif_internals->one_row_select_stmt) {
 		dstmt->select = g_object_ref (imodel->priv->modif_internals->one_row_select_stmt);
 		gda_statement_get_parameters (dstmt->select, &(dstmt->params), NULL);
@@ -3017,7 +3025,7 @@
 			goto onerror;
 		}
 		g_assert (cdata.colid);
-		g_print ("SEL param '%s' <=> column named '%s'\n", cdata.hid, cdata.colid);
+		/*g_print ("SEL param '%s' <=> column named '%s'\n", cdata.hid, cdata.colid);*/
 		
 		GSList *ins_list;
 		cdata.hid = NULL;
@@ -3041,7 +3049,7 @@
 			goto onerror;
 		}
 
-		g_print ("column named '%s' <=> INS param '%s'\n", cdata.colid, cdata.hid);
+		/*g_print ("column named '%s' <=> INS param '%s'\n", cdata.colid, cdata.hid);*/
 
 		if (! param_name_to_int (cdata.hid, &ipnum, &ipold) || ipold) {
 			g_warning ("Provider reported a malformed parameter named '%s'", cdata.hid);
@@ -3049,7 +3057,6 @@
 		}
 
 		g_array_insert_val (array, spnum, ipnum);
-		g_print ("    array[%d] = %d\n", spnum, ipnum);
 	}
 
 	retval = (gint *) array->data;

Modified: trunk/libgda/sql-parser/gda-statement-struct-util.c
==============================================================================
--- trunk/libgda/sql-parser/gda-statement-struct-util.c	(original)
+++ trunk/libgda/sql-parser/gda-statement-struct-util.c	Tue Sep 30 18:33:41 2008
@@ -311,7 +311,7 @@
  * - if surrounded by double quotes, then just remove the quotes
  * - otherwise convert to lower case
  *
- * WARNING: @str must NOT be a composed identifier (<part1>."<part2>" for example)
+ * WARNING: @str must NOT be a composed identifier (&lt;part1&gt;."&lt;part2&gt;" for example)
  * 
  * Returns: @str
  */

Modified: trunk/libgda/sql-parser/parser.y
==============================================================================
--- trunk/libgda/sql-parser/parser.y	(original)
+++ trunk/libgda/sql-parser/parser.y	Tue Sep 30 18:33:41 2008
@@ -965,7 +965,7 @@
 // pvalue: values which are parameters (GdaSqlExpr)
 %type pvalue {GdaSqlExpr *}
 %destructor pvalue {gda_sql_expr_free ($$);}
-	pvalue(E) ::= UNSPECVAL LSBRACKET paramspec(P) RSBRACKET. {E = gda_sql_expr_new (NULL); E->param_spec = P;}
+pvalue(E) ::= UNSPECVAL LSBRACKET paramspec(P) RSBRACKET. {E = gda_sql_expr_new (NULL); E->param_spec = P;}
 pvalue(E) ::= value(V) LSBRACKET paramspec(P) RSBRACKET. {E = gda_sql_expr_new (NULL); E->value = V; E->param_spec = P;}
 pvalue(E) ::= SIMPLEPARAM(S). {E = gda_sql_expr_new (NULL); E->param_spec = gda_sql_param_spec_new (S);}
 

Modified: trunk/libgda/sqlite/gda-sqlite-meta.c
==============================================================================
--- trunk/libgda/sqlite/gda-sqlite-meta.c	(original)
+++ trunk/libgda/sqlite/gda-sqlite-meta.c	Tue Sep 30 18:33:41 2008
@@ -1270,8 +1270,6 @@
 	if (!tmpmodel)
 		return FALSE;
 		
-	if (!strcmp (g_value_get_string (p_table_name), "baseFieldMappings"))
-		g_print ("AAA\n");
 	nrows = gda_data_model_get_n_rows (tmpmodel);
 	for (i = 0; i < nrows; i++) {
 		const GValue *cvalue;
@@ -1943,7 +1941,7 @@
 	g_assert (mod_model);
 
 	retval = fill_key_columns_model (cnc, cdata, mod_model, table_schema, table_name, constraint_name, error);
-	if (retval)
+	if (retval) 
 		retval = gda_meta_store_modify_with_context (store, context, mod_model, error);
 	g_object_unref (mod_model);
 

Modified: trunk/libgda/sqlite/virtual/gda-vconnection-data-model-private.h
==============================================================================
--- trunk/libgda/sqlite/virtual/gda-vconnection-data-model-private.h	(original)
+++ trunk/libgda/sqlite/virtual/gda-vconnection-data-model-private.h	Tue Sep 30 18:33:41 2008
@@ -30,6 +30,7 @@
 	GDestroyNotify               spec_free_func;
 
 	GdaDataModel                *real_model; /* data model really being used, a reference count is kept on it */
+	GList                       *columns;
 	gchar                       *table_name;
 	gchar                       *unique_name;
 } GdaVConnectionTableData;

Modified: trunk/libgda/sqlite/virtual/gda-vconnection-data-model.c
==============================================================================
--- trunk/libgda/sqlite/virtual/gda-vconnection-data-model.c	(original)
+++ trunk/libgda/sqlite/virtual/gda-vconnection-data-model.c	Tue Sep 30 18:33:41 2008
@@ -451,6 +451,10 @@
 {
 	if (td->real_model)
 		g_object_unref (td->real_model);
+	if (td->columns) {
+		g_list_foreach (td->columns, (GFunc) g_object_unref, NULL);
+		g_list_free (td->columns);
+	}
 	g_free (td->table_name);
 	g_free (td->unique_name);
 	if (td->spec_free_func)

Modified: trunk/libgda/sqlite/virtual/gda-vconnection-hub.c
==============================================================================
--- trunk/libgda/sqlite/virtual/gda-vconnection-hub.c	(original)
+++ trunk/libgda/sqlite/virtual/gda-vconnection-hub.c	Tue Sep 30 18:33:41 2008
@@ -422,7 +422,7 @@
 	GdaMetaStore *store;
 	GdaMetaContext context;
 	
-	g_object_get (G_OBJECT (hc->cnc), "meta-store", &store, NULL);
+	store = gda_connection_get_meta_store (hc->cnc);
 	g_assert (store);
 
 	/* make sure the meta store is up to date */

Modified: trunk/libgda/sqlite/virtual/gda-vprovider-data-model.c
==============================================================================
--- trunk/libgda/sqlite/virtual/gda-vprovider-data-model.c	(original)
+++ trunk/libgda/sqlite/virtual/gda-vprovider-data-model.c	Tue Sep 30 18:33:41 2008
@@ -349,7 +349,6 @@
 	GString *sql;
 	gint i, ncols;
 	gchar *spec_name;
-	GList *columns = NULL;
 	GdaVConnectionTableData *td;
 
 	TRACE ();
@@ -402,8 +401,9 @@
 	}
 	else  {
 		GError *error = NULL;
-		columns = td->spec->create_columns_func (td->spec, &error);
-		if (! columns) {
+		if (!td->columns)
+			td->columns = td->spec->create_columns_func (td->spec, &error);
+		if (! td->columns) {
 			if (error && error->message) {
 				int len = strlen (error->message) + 1;
 				*pzErr = sqlite3_malloc (sizeof (gchar) * len);
@@ -413,7 +413,7 @@
 				*pzErr = sqlite3_mprintf (_("Could not compute virtual table's columns"));
 			return SQLITE_ERROR;
 		}
-		ncols = g_list_length (columns);
+		ncols = g_list_length (td->columns);
 	}
 
 	/* create the CREATE TABLE statement */
@@ -428,8 +428,8 @@
 
 		if (i != 0)
 			g_string_append (sql, ", ");
-		if (columns)
-			column = g_list_nth_data (columns, i);
+		if (td->columns)
+			column = g_list_nth_data (td->columns, i);
 		else
 			column = gda_data_model_describe_column ((GdaDataModel*) proxy, i);
 		if (!column) {
@@ -487,10 +487,6 @@
 	g_string_append (sql, "__gda_row_nb hidden integer");
 
 	g_string_append_c (sql, ')');
-	if (columns) {
-		g_list_foreach (columns, (GFunc) g_object_unref, NULL);
-		g_list_free (columns);
-	}
 
 	/* VirtualTable structure */
 	VirtualTable *vtable;
@@ -553,6 +549,24 @@
 			g_object_unref (vtable->proxy);
 
 		vtable->td->real_model = vtable->td->spec->create_model_func (vtable->td->spec);
+		if (! vtable->td->columns && vtable->td->spec->create_columns_func)
+			vtable->td->columns = vtable->td->spec->create_columns_func (vtable->td->spec, NULL);
+		if (vtable->td->columns) {
+			/* columns */
+			GList *list;
+			gint i, ncols;
+			ncols = gda_data_model_get_n_columns (vtable->td->real_model);
+			g_assert (ncols == g_list_length (vtable->td->columns));
+			for (i = 0, list = vtable->td->columns;
+			     i < ncols;
+			     i++, list = list->next) {
+				GdaColumn *mcol = gda_data_model_describe_column (vtable->td->real_model, i);
+				GdaColumn *ccol = (GdaColumn*) list->data;
+				if (gda_column_get_g_type (mcol) == GDA_TYPE_NULL)
+					gda_column_set_g_type (mcol, gda_column_get_g_type (ccol));
+			}
+		}
+
 		/*g_print ("Created real model %p for table %s\n", vtable->td->real_model, vtable->td->table_name);*/
 		
 		if (GDA_IS_DATA_PROXY (vtable->td->real_model)) {
@@ -777,7 +791,7 @@
 			GType type;
 			GValue *value;
 			type = gda_column_get_g_type (gda_data_model_describe_column ((GdaDataModel*) vtable->proxy, i - 2));
-			if (sqlite3_value_text (apData [i]))
+			if ((type != GDA_TYPE_NULL) && sqlite3_value_text (apData [i]))
 				value = gda_value_new_from_string ((const gchar*) sqlite3_value_text (apData [i]), type);
 			else
 				value = gda_value_new_null ();
@@ -826,10 +840,22 @@
 	
 	TRACE ();
 
-	if (vtable->proxy)
-		return gda_data_proxy_apply_all_changes (vtable->proxy, NULL) ? SQLITE_OK : SQLITE_READONLY;
+	if (vtable->proxy) {
+		GError *lerror = NULL;
+		if (!gda_data_proxy_apply_all_changes (vtable->proxy, &lerror)) {
+			g_warning ("VirtualCommit error: %s\n", 
+				   lerror && lerror->message ? lerror->message : "No detail");
+			if (lerror)
+				g_error_free (lerror);
+			TO_IMPLEMENT; /* FIXME: the error code does not seem to be taken into account by SQLite
+				       * => maybe the xCommit is not used in the correct context! */
+			return SQLITE_ERROR;
+		}
+		else
+			return SQLITE_OK;
+	}
 	else
-		return TRUE;
+		return SQLITE_OK;
 }
 
 static int

Modified: trunk/samples/TableCopy/common.c
==============================================================================
--- trunk/samples/TableCopy/common.c	(original)
+++ trunk/samples/TableCopy/common.c	Tue Sep 30 18:33:41 2008
@@ -37,17 +37,17 @@
         /* table "products_copied1" */
 	run_sql_non_select (cnc, "DROP table IF EXISTS products_copied1");
 	run_sql_non_select (cnc, "CREATE table products_copied1 (ref string not null primary key, "
-			    "name string not null, price real, wh_stored integer REFERENCES warehouses(id))");
+			    "name string not null, price real, wh_stored integer)");
 
         /* table "products_copied2" */
 	run_sql_non_select (cnc, "DROP table IF EXISTS products_copied2");
 	run_sql_non_select (cnc, "CREATE table products_copied2 (ref string not null primary key, "
-			    "name string not null, price real, wh_stored integer REFERENCES warehouses(id))");
+			    "name string not null, price real, wh_stored integer)");
 
         /* table "products_copied3" */
 	run_sql_non_select (cnc, "DROP table IF EXISTS products_copied3");
 	run_sql_non_select (cnc, "CREATE table products_copied3 (ref string not null primary key, "
-			    "name string not null, price real, wh_stored integer REFERENCES warehouses(id))");
+			    "name string not null, price real, wh_stored integer)");
 
 	return cnc;
 }

Modified: trunk/samples/TableCopy/table-copy.c
==============================================================================
--- trunk/samples/TableCopy/table-copy.c	(original)
+++ trunk/samples/TableCopy/table-copy.c	Tue Sep 30 18:33:41 2008
@@ -111,16 +111,16 @@
 
 		/* REM: exit status for each function should be check but has been omitted for clarity */
 		p = gda_set_get_holder (params, "ref");
-		gda_holder_set_value (p, gda_data_model_get_value_at (source, 0, row, NULL));
+		gda_holder_set_value (p, gda_data_model_get_value_at (source, 0, row, NULL), NULL);
 		p = gda_set_get_holder (params, "name");
-		gda_holder_set_value (p, gda_data_model_get_value_at (source, 1, row, NULL));
+		gda_holder_set_value (p, gda_data_model_get_value_at (source, 1, row, NULL), NULL);
 		p = gda_set_get_holder (params, "price");
 		value = gda_value_new (G_TYPE_DOUBLE);
 		g_value_set_double (value, g_value_get_double (gda_data_model_get_value_at (source, 2, row, NULL)) * 1.05);
-		gda_holder_set_value (p, value);
+		gda_holder_set_value (p, value, NULL);
 		gda_value_free (value);
 		p = gda_set_get_holder (params, "location");
-		gda_holder_set_value (p, gda_data_model_get_value_at (source, 3, row, NULL));
+		gda_holder_set_value (p, gda_data_model_get_value_at (source, 3, row, NULL), NULL);
 
 		res = gda_connection_statement_execute_non_select (d_cnc, stmt, params, NULL, &error);
 		if (res == -1) {
@@ -161,31 +161,32 @@
 	
 	source = get_products_contents (s_cnc);
 
-	/* create GdaDataModelQuery and set it up */
+	/* create GdaDataSelect and set it up */
 	parser = gda_connection_create_parser (d_cnc);
 	sql = "SELECT ref, name, price, wh_stored FROM products_copied2";
 	stmt = gda_sql_parser_parse_string (parser, sql, NULL, &error);
 	g_assert (stmt);
-	dest = gda_data_model_query_new (s_cnc, stmt);
+	dest = gda_connection_statement_execute_select (d_cnc, stmt, NULL, NULL);
 	g_object_unref (stmt);
-
-	sql = "INSERT INTO products_copied2 (ref, name, price, wh_stored) VALUES ("
-		"## /* name:+0 type:gchararray */, "
-		"## /* name:+1 type:gchararray */, "
-		"## /* name:+2 type:gdouble */, "
-		"## /* name:+3 type:gint */)";
-	stmt = gda_sql_parser_parse_string (parser, sql, NULL, &error);
-	g_assert (stmt);
 	g_object_unref (parser);
 
-	if (!gda_data_model_query_set_modification_query (GDA_DATA_MODEL_QUERY (dest), stmt, &error)) {
+	if (!gda_data_select_set_row_selection_condition_sql (GDA_DATA_SELECT (dest), "ref = ##-0::string", &error)) {
+		g_print ("Error setting the GdaDataSelect's condition: %s\n",
+                         error && error->message ? error->message : "No detail");
+		g_error_free (error);
+		retval = FALSE;
+		goto end;
+	}
+
+	sql = "INSERT INTO products_copied2 (ref, name, price, wh_stored) VALUES (##+0::string, ##+1::string, ##+2::gdouble, ##+3::gint)";
+
+	if (!gda_data_select_set_modification_statement_sql (GDA_DATA_SELECT (dest), sql, &error)) {
 		g_print ("Error setting the INSERT query: %s\n",
                          error && error->message ? error->message : "No detail");
 		g_error_free (error);
 		retval = FALSE;
 		goto end;
 	}
-	g_object_unref (stmt);
 
 	if (! gda_data_model_import_from_model (dest, source, TRUE, NULL, &error)) {
 		g_print ("Error importing data: %s\n",



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