[libgda] Corrections for bug #589822



commit 7e4810769678871bb6538efe6250e72ee5ae2601
Author: Vivien Malerba <malerba gnome-db org>
Date:   Tue Jul 28 18:37:08 2009 +0200

    Corrections for bug #589822
    
    Also added a providers test

 libgda/gda-data-meta-wrapper.c     |   14 +-
 libgda/gda-data-meta-wrapper.h     |    2 +
 libgda/gda-meta-store.c            |    9 +-
 tests/providers/check_postgres.c   |    4 +
 tests/providers/check_sqlite.c     |    4 +
 tests/providers/prov-test-common.c |  284 +++++++++++++++++++++++++++++++++++-
 tests/providers/prov-test-common.h |    1 +
 7 files changed, 311 insertions(+), 7 deletions(-)
---
diff --git a/libgda/gda-data-meta-wrapper.c b/libgda/gda-data-meta-wrapper.c
index a0a437d..8dc3e2a 100644
--- a/libgda/gda-data-meta-wrapper.c
+++ b/libgda/gda-data-meta-wrapper.c
@@ -466,13 +466,15 @@ to_lower (gchar *str)
 	return str;
 }
 
-/*
+/**
+ * _gda_data_meta_wrapper_compute_value
+ *
  * Returns:
  *  - NULL if no changes are necessary from the current value
  *  - a new GValue if changes were necessary
  */
-static GValue *
-compute_value (const GValue *value, GdaSqlIdentifierStyle mode, GdaSqlReservedKeywordsFunc reserved_keyword_func)
+GValue *
+_gda_data_meta_wrapper_compute_value (const GValue *value, GdaSqlIdentifierStyle mode, GdaSqlReservedKeywordsFunc reserved_keyword_func)
 {
 	GValue *retval = NULL;
 	const gchar *str;
@@ -591,7 +593,8 @@ gda_data_meta_wrapper_get_value_at (GdaDataModel *model, gint col, gint row, GEr
 				return NULL;
 			
 			GValue *retval;
-			retval = compute_value (cvalue, imodel->priv->mode, imodel->priv->reserved_keyword_func);
+			retval = _gda_data_meta_wrapper_compute_value (cvalue, imodel->priv->mode,
+								       imodel->priv->reserved_keyword_func);
 			if (!retval)
 				return cvalue;
 			
@@ -618,7 +621,8 @@ gda_data_meta_wrapper_get_value_at (GdaDataModel *model, gint col, gint row, GEr
 			return NULL;
 
 		GValue *retval;
-		retval = compute_value (cvalue, imodel->priv->mode, imodel->priv->reserved_keyword_func);
+		retval = _gda_data_meta_wrapper_compute_value (cvalue, imodel->priv->mode,
+							       imodel->priv->reserved_keyword_func);
 		if (!retval)
 			return cvalue;
 		if (imodel->priv->buffer->values [indexcol])
diff --git a/libgda/gda-data-meta-wrapper.h b/libgda/gda-data-meta-wrapper.h
index eff38c0..da4b254 100644
--- a/libgda/gda-data-meta-wrapper.h
+++ b/libgda/gda-data-meta-wrapper.h
@@ -63,6 +63,8 @@ GdaDataModel *_gda_data_meta_wrapper_new         (GdaDataModel *model, gboolean
 						  gint *cols, gint size, GdaSqlIdentifierStyle mode,
 						  GdaSqlReservedKeywordsFunc reserved_keyword_func);
 
+GValue       *_gda_data_meta_wrapper_compute_value (const GValue *value, GdaSqlIdentifierStyle mode,
+						    GdaSqlReservedKeywordsFunc reserved_keyword_func);
 G_END_DECLS
 
 #endif
diff --git a/libgda/gda-meta-store.c b/libgda/gda-meta-store.c
index 6e9c9a1..6f343c4 100644
--- a/libgda/gda-meta-store.c
+++ b/libgda/gda-meta-store.c
@@ -2810,13 +2810,20 @@ prepare_tables_infos (GdaMetaStore *store, TableInfo **out_table_infos, TableCon
 	gint i;
 	for (i = 0; i < nvalues; i++) {
 		GdaHolder *h;
+		GValue *wvalue;
 		
+		wvalue = _gda_data_meta_wrapper_compute_value (values [i], store->priv->ident_style,
+							       store->priv->reserved_keyword_func);
 		h = gda_set_get_holder ((*out_cond_infos)->params, value_names [i]);
-		if (!h || !gda_holder_set_value (h, values[i], NULL)) {
+		if (!h || !gda_holder_set_value (h, wvalue ? wvalue : values[i], NULL)) {
 			g_set_error (error, GDA_META_STORE_ERROR, GDA_META_STORE_INTERNAL_ERROR,
 				_ ("Could not set value for parameter '%s'"), value_names [i]);
+			if (wvalue)
+				gda_value_free (wvalue);
 			return FALSE;
 		}
+		if (wvalue)
+			gda_value_free (wvalue);
 	}
 	
 	return TRUE;
diff --git a/tests/providers/check_postgres.c b/tests/providers/check_postgres.c
index fa28342..2e596d0 100644
--- a/tests/providers/check_postgres.c
+++ b/tests/providers/check_postgres.c
@@ -30,6 +30,10 @@ main (int argc, char **argv)
 
 	if (cnc) {
 		number_failed += prov_test_common_check_meta ();
+		number_failed += prov_test_common_check_meta_identifiers (TRUE, TRUE);
+		number_failed += prov_test_common_check_meta_identifiers (TRUE, FALSE);
+		number_failed += prov_test_common_check_meta_identifiers (FALSE, TRUE);
+		number_failed += prov_test_common_check_meta_identifiers (FALSE, FALSE);
 		number_failed += prov_test_common_load_data ();
 		number_failed += prov_test_common_check_cursor_models ();
 		number_failed += prov_test_common_check_data_select ();
diff --git a/tests/providers/check_sqlite.c b/tests/providers/check_sqlite.c
index 56fe118..a0643a5 100644
--- a/tests/providers/check_sqlite.c
+++ b/tests/providers/check_sqlite.c
@@ -30,6 +30,10 @@ main (int argc, char **argv)
 
 	if (cnc) {
 		number_failed += prov_test_common_check_meta ();
+		number_failed += prov_test_common_check_meta_identifiers (TRUE, TRUE);
+		number_failed += prov_test_common_check_meta_identifiers (TRUE, FALSE);
+		number_failed += prov_test_common_check_meta_identifiers (FALSE, TRUE);
+		number_failed += prov_test_common_check_meta_identifiers (FALSE, FALSE);
 		number_failed += prov_test_common_load_data ();
 		number_failed += prov_test_common_check_cursor_models ();
 		number_failed += prov_test_common_check_data_select ();
diff --git a/tests/providers/prov-test-common.c b/tests/providers/prov-test-common.c
index a7af5ca..61fae18 100644
--- a/tests/providers/prov-test-common.c
+++ b/tests/providers/prov-test-common.c
@@ -25,6 +25,11 @@ prov_test_common_setup ()
 {
 	int number_failed = 0;
 	GError *error = NULL;
+
+#ifdef CHECK_EXTRA_INFO
+	g_print ("\n============= %s() =============\n", __FUNCTION__);
+#endif
+
 	cnc = test_cnc_setup_connection (pinfo->id, "testcheckdb", &error);
 	if (!cnc) {
 		if (error) {
@@ -68,6 +73,10 @@ prov_test_common_clean ()
 {
 	int number_failed = 0;
 
+#ifdef CHECK_EXTRA_INFO
+	g_print ("\n============= %s() =============\n", __FUNCTION__);
+#endif
+
 	if (!test_cnc_clean_connection (cnc, NULL))
 		number_failed++;
 
@@ -91,7 +100,14 @@ prov_test_common_check_meta ()
 	GError *gerror = NULL;
 	gint ntables, i;
 
+#ifdef CHECK_EXTRA_INFO
+	g_print ("\n============= %s() =============\n", __FUNCTION__);
+#endif
+
 	/* update meta store */
+#ifdef CHECK_EXTRA_INFO
+	g_print ("Updating the complete meta store...\n");
+#endif
 	if (! gda_connection_update_meta_store (cnc, NULL, &gerror)) {
 #ifdef CHECK_EXTRA_INFO
 		g_warning ("Can't update meta store (1): %s\n",
@@ -143,6 +159,9 @@ prov_test_common_check_meta ()
 	}
 
 	/* update meta store */
+#ifdef CHECK_EXTRA_INFO
+	g_print ("Updating the complete meta store...\n");
+#endif
 	if (! gda_connection_update_meta_store (cnc, NULL, &gerror)) {
 #ifdef CHECK_EXTRA_INFO
 		g_warning ("Can't update meta store (2): %s\n",
@@ -203,7 +222,256 @@ prov_test_common_check_meta ()
 		g_strfreev (dump1);
 	g_slist_free (tables);
 
-	return number_failed;	
+	return number_failed;
+}
+
+/*
+ *
+ * CHECK_META_IDENTIFIERS
+ *
+ */
+
+int
+prov_test_common_check_meta_identifiers (gboolean case_sensitive, gboolean update_all)
+{
+	GdaMetaStore *store;
+	GError *error = NULL;
+	gchar *table_name = "CapitalTest";
+	gchar *field_name = "AName";
+	GdaServerProvider* provider = gda_connection_get_provider (cnc);
+	GdaServerOperation* operation;
+	GdaDataModel* data;
+	GValue *value, *value2;
+	const GValue *cvalue;
+	GdaMetaContext mcontext = {"_tables", 1, NULL, NULL};
+	GdaConnectionOptions options;
+
+#ifdef CHECK_EXTRA_INFO
+	g_print ("\n============= %s(%s, %s) =============\n", __FUNCTION__,
+		 case_sensitive ? "case sensitive" : "case NOT sensitive",
+		 update_all ? "complete meta data update" : "partial meta data update");
+#endif
+
+	g_object_get (G_OBJECT (cnc), "options", &options, NULL);
+	if (case_sensitive)
+		g_object_set (G_OBJECT (cnc), "options",
+			      options | GDA_CONNECTION_OPTIONS_SQL_IDENTIFIERS_CASE_SENSITIVE, NULL);
+
+	
+
+	/* DROP table */
+        operation = gda_server_provider_create_operation (provider, cnc,
+							  GDA_SERVER_OPERATION_DROP_TABLE, NULL, &error);
+        g_assert (operation);
+        gda_server_operation_set_value_at (operation, table_name, NULL, "/TABLE_DESC_P/TABLE_NAME");
+        gda_server_provider_perform_operation (provider, cnc, operation, NULL);
+	g_object_unref (operation);
+
+	/* CREATE table */
+	operation = gda_server_provider_create_operation (provider, cnc,
+							  GDA_SERVER_OPERATION_CREATE_TABLE, NULL, &error);
+        g_assert (operation);
+        gda_server_operation_set_value_at (operation, table_name, NULL, "/TABLE_DEF_P/TABLE_NAME");
+        gda_server_operation_set_value_at (operation, "id", NULL, "/FIELDS_A/@COLUMN_NAME/0");
+        gda_server_operation_set_value_at (operation, "int", NULL, "/FIELDS_A/@COLUMN_TYPE/0");
+        gda_server_operation_set_value_at (operation, "TRUE", NULL, "/FIELDS_A/@COLUMN_PKEY/0");
+        if (! gda_server_provider_perform_operation (provider, cnc, operation, &error)) {
+#ifdef CHECK_EXTRA_INFO
+                g_warning ("perform_operation(CREATE_TABLE) failed: %s\n", error && error->message ? 
+			   error->message : "???");
+#endif
+                g_clear_error (&error);
+		g_object_set (G_OBJECT (cnc), "options", options, NULL);
+                return 1;
+        }
+
+
+	/* update meta store */
+#ifdef CHECK_EXTRA_INFO
+	g_print ("Updating the complete meta store...\n");
+#endif
+	if (!update_all) {
+		g_value_take_string ((value = gda_value_new (G_TYPE_STRING)),
+				     gda_meta_store_sql_identifier_quote (table_name, cnc));
+		mcontext.column_names = g_new (gchar *, 1);
+		mcontext.column_names [0] = "table_name";
+		mcontext.column_values = g_new (GValue *, 1);
+		mcontext.column_values [0] = value;
+	}
+	store = gda_meta_store_new (NULL); /* create an in memory meta store */
+	g_object_set (G_OBJECT (cnc), "meta-store", store, NULL);
+	g_object_unref (store);
+	if (! gda_connection_update_meta_store (cnc, update_all ? NULL : &mcontext, &error)) {
+#ifdef CHECK_EXTRA_INFO
+		g_warning ("Can't FULL update meta store: %s\n",
+			   error && error->message ? error->message : "???");
+#endif
+		g_clear_error (&error);
+		g_object_set (G_OBJECT (cnc), "options", options, NULL);
+		return 1;
+	}
+
+	/* check table */
+#ifdef CHECK_EXTRA_INFO
+	g_print ("Checking fetched meta data...\n");
+#endif
+	g_value_take_string ((value = gda_value_new (G_TYPE_STRING)),
+			     gda_meta_store_sql_identifier_quote (table_name, cnc));
+	data = gda_connection_get_meta_store_data (cnc, GDA_CONNECTION_META_TABLES, &error, 1,
+						   "name", value);
+	g_assert (data);
+	if (gda_data_model_get_n_rows (data) != 1) {
+#ifdef CHECK_EXTRA_INFO
+                g_warning ("gda_connection_get_meta_store_data(): wrong number of rows : %d\n",
+			   gda_data_model_get_n_rows (data));
+#endif
+		gda_value_free (value);
+		g_object_unref (data);
+		g_object_set (G_OBJECT (cnc), "options", options, NULL);
+		return 1;
+	}
+	cvalue = gda_data_model_get_value_at (data, 0, 0, &error);
+	g_assert (cvalue);
+	if (gda_value_compare (value, cvalue)) {
+#ifdef CHECK_EXTRA_INFO
+                g_warning ("gda_connection_get_meta_store_data(): expected %s and got %s\n",
+			   gda_value_stringify (cvalue), gda_value_stringify (value));
+#endif
+		gda_value_free (value);
+		g_object_unref (data);
+		g_object_set (G_OBJECT (cnc), "options", options, NULL);
+		return 1;
+	}
+	g_object_unref (data);
+
+	/* check fields of table */
+	data = gda_connection_get_meta_store_data (cnc, GDA_CONNECTION_META_FIELDS, &error, 1,
+						   "name", value);
+	g_assert (data);
+	if (gda_data_model_get_n_rows (data) != 1) {
+#ifdef CHECK_EXTRA_INFO
+                g_warning ("gda_connection_get_meta_store_data(): wrong number of rows : %d\n",
+			   gda_data_model_get_n_rows (data));
+#endif
+		gda_value_free (value);
+		g_object_unref (data);
+		g_object_set (G_OBJECT (cnc), "options", options, NULL);
+		return 1;
+	}
+	cvalue = gda_data_model_get_value_at (data, 0, 0, &error);
+	g_assert (cvalue);
+	g_value_set_string ((value2 = gda_value_new (G_TYPE_STRING)), "id");
+	if (gda_value_compare (value2, cvalue)) {
+#ifdef CHECK_EXTRA_INFO
+                g_warning ("gda_connection_get_meta_store_data(): expected %s and got %s\n",
+			   gda_value_stringify (cvalue), gda_value_stringify (value));
+#endif
+		gda_value_free (value);
+		g_object_unref (data);
+		g_object_set (G_OBJECT (cnc), "options", options, NULL);
+		return 1;
+	}
+	gda_value_free (value);
+	gda_value_free (value2);
+	g_object_unref (data);
+
+	/* ALTER table to add a column */
+	operation = gda_server_provider_create_operation (provider, cnc,
+							  GDA_SERVER_OPERATION_ADD_COLUMN, NULL, &error);
+        g_assert (operation);
+        gda_server_operation_set_value_at (operation, table_name, NULL, "/COLUMN_DEF_P/TABLE_NAME");
+        gda_server_operation_set_value_at (operation, field_name, NULL, "/COLUMN_DEF_P/COLUMN_NAME");
+        gda_server_operation_set_value_at (operation, "int", NULL, "/COLUMN_DEF_P/COLUMN_TYPE");
+        if (! gda_server_provider_perform_operation (provider, cnc, operation, &error)) {
+#ifdef CHECK_EXTRA_INFO
+                g_warning ("perform_operation(ADD_COLUMN) failed: %s\n", error && error->message ? 
+			   error->message : "???");
+#endif
+                g_clear_error (&error);
+		g_object_set (G_OBJECT (cnc), "options", options, NULL);
+                return 1;
+        }
+
+	/* update meta store */
+#ifdef CHECK_EXTRA_INFO
+	g_print ("Updating the complete meta store...\n");
+#endif
+	if (! gda_connection_update_meta_store (cnc, update_all ? NULL : &mcontext, &error)) {
+#ifdef CHECK_EXTRA_INFO
+		g_warning ("Can't FULL update meta store: %s\n",
+			   error && error->message ? error->message : "???");
+#endif
+		g_clear_error (&error);
+		g_object_set (G_OBJECT (cnc), "options", options, NULL);
+		return 1;
+	}
+
+	/* check table */
+#ifdef CHECK_EXTRA_INFO
+	g_print ("Checking fetched meta data...\n");
+#endif
+	g_value_take_string ((value = gda_value_new (G_TYPE_STRING)),
+			     gda_meta_store_sql_identifier_quote (table_name, cnc));
+	data = gda_connection_get_meta_store_data (cnc, GDA_CONNECTION_META_TABLES, &error, 1,
+						   "name", value);
+	g_assert (data);
+	if (gda_data_model_get_n_rows (data) != 1) {
+#ifdef CHECK_EXTRA_INFO
+                g_warning ("gda_connection_get_meta_store_data(): wrong number of rows : %d\n",
+			   gda_data_model_get_n_rows (data));
+#endif
+		gda_value_free (value);
+		g_object_unref (data);
+		g_object_set (G_OBJECT (cnc), "options", options, NULL);
+		return 1;
+	}
+	cvalue = gda_data_model_get_value_at (data, 0, 0, &error);
+	g_assert (cvalue);
+	if (gda_value_compare (value, cvalue)) {
+#ifdef CHECK_EXTRA_INFO
+                g_warning ("gda_connection_get_meta_store_data(): expected %s and got %s\n",
+			   gda_value_stringify (cvalue), gda_value_stringify (value));
+#endif
+		gda_value_free (value);
+		g_object_unref (data);
+		g_object_set (G_OBJECT (cnc), "options", options, NULL);
+		return 1;
+	}
+	g_object_unref (data);
+
+	/* check fields of table */
+	g_value_take_string ((value2 = gda_value_new (G_TYPE_STRING)),
+			     gda_meta_store_sql_identifier_quote (field_name, cnc));
+	data = gda_connection_get_meta_store_data (cnc, GDA_CONNECTION_META_FIELDS, &error, 2,
+						   "name", value, "field_name", value2);
+	g_assert (data);
+	if (gda_data_model_get_n_rows (data) != 1) {
+#ifdef CHECK_EXTRA_INFO
+                g_warning ("gda_connection_get_meta_store_data(): wrong number of rows : %d\n",
+			   gda_data_model_get_n_rows (data));
+#endif
+		gda_value_free (value);
+		g_object_unref (data);
+		g_object_set (G_OBJECT (cnc), "options", options, NULL);
+		return 1;
+	}
+	cvalue = gda_data_model_get_value_at (data, 0, 0, &error);
+	g_assert (cvalue);
+	if (gda_value_compare (value2, cvalue)) {
+#ifdef CHECK_EXTRA_INFO
+                g_warning ("gda_connection_get_meta_store_data(): expected %s and got %s\n",
+			   gda_value_stringify (cvalue), gda_value_stringify (value));
+#endif
+		gda_value_free (value);
+		g_object_unref (data);
+		g_object_set (G_OBJECT (cnc), "options", options, NULL);
+		return 1;
+	}
+	gda_value_free (value);
+	g_object_unref (data);
+
+	g_object_set (G_OBJECT (cnc), "options", options, NULL);
+	return 0;
 }
 
 /*
@@ -215,6 +483,11 @@ int
 prov_test_common_load_data ()
 {
 	int number_failed = 0;
+
+#ifdef CHECK_EXTRA_INFO
+	g_print ("\n============= %s() =============\n", __FUNCTION__);
+#endif
+
 	if (!prov_test_load_data (cnc, "actor"))
 		number_failed++;
 	if (!prov_test_load_data (cnc, "language"))
@@ -236,6 +509,11 @@ int
 prov_test_common_check_cursor_models ()
 {
 	int number_failed = 0;
+
+#ifdef CHECK_EXTRA_INFO
+	g_print ("\n============= %s() =============\n", __FUNCTION__);
+#endif
+
 	if (!prov_test_check_table_cursor_model (cnc, "actor"))
 		number_failed++;
 	if (!prov_test_check_table_cursor_model (cnc, "language"))
@@ -269,6 +547,10 @@ prov_test_common_check_data_select ()
 	GSList *columns;
 	gint i, ncols;
 
+#ifdef CHECK_EXTRA_INFO
+	g_print ("\n============= %s() =============\n", __FUNCTION__);
+#endif
+
 	parser = gda_connection_create_parser (cnc);
 	if (!parser)
 		parser = gda_sql_parser_new ();
diff --git a/tests/providers/prov-test-common.h b/tests/providers/prov-test-common.h
index 045e3f8..80ff776 100644
--- a/tests/providers/prov-test-common.h
+++ b/tests/providers/prov-test-common.h
@@ -13,6 +13,7 @@
 int prov_test_common_setup ();
 int prov_test_common_load_data ();
 int prov_test_common_check_meta ();
+int prov_test_common_check_meta_identifiers (gboolean case_sensitive, gboolean update_all);
 int prov_test_common_check_cursor_models ();
 int prov_test_common_check_data_select ();
 int prov_test_common_clean ();



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