[libgda] Avoid column names duplication in GdaDataProxy filtering



commit c928254ab6e341bc2d73e88d38263f04f3057616
Author: Vivien Malerba <malerba gnome-db org>
Date:   Wed Aug 4 18:33:27 2010 +0200

    Avoid column names duplication in GdaDataProxy filtering
    
    which caused an error when the creating the virtual table and
    made the filtering impossible

 libgda/gda-data-proxy.c |   21 ++++++++++++++++++++-
 1 files changed, 20 insertions(+), 1 deletions(-)
---
diff --git a/libgda/gda-data-proxy.c b/libgda/gda-data-proxy.c
index 35e5f01..ad95571 100644
--- a/libgda/gda-data-proxy.c
+++ b/libgda/gda-data-proxy.c
@@ -3325,7 +3325,8 @@ static void create_columns (GdaDataProxy *proxy)
 		GdaColumn *orig;
 		const gchar *cname;
 		gchar *newname;
-
+		gint k;
+		
 		orig = gda_data_model_describe_column (proxy->priv->model, 
 						       i -  proxy->priv->model_nb_cols);
 		proxy->priv->columns[i] = gda_column_copy (orig);
@@ -3334,6 +3335,24 @@ static void create_columns (GdaDataProxy *proxy)
 			newname = g_strdup_printf ("pre%s", cname);
 		else
 			newname = g_strdup_printf ("pre%d", i);
+		
+		/* make sure there is no duplicate name */
+		for (k = 0; ; k++) {
+			gint j;
+			for (j = 0; j < i; j++) {
+				const gchar *cname2;
+				cname2 =  gda_column_get_name (proxy->priv->columns[j]);
+				if (cname2 && *cname2 && !strcmp (cname2, newname))
+					break;
+			}
+			if (j == i)
+				break;
+			g_free (newname);
+			if (cname && *cname) 
+				newname = g_strdup_printf ("pre%s_%d", cname, k);
+			else
+				newname = g_strdup_printf ("pre%d_%d", i, k);
+		}
 		gda_column_set_name (proxy->priv->columns[i], newname);
 		gda_column_set_description (proxy->priv->columns[i], newname);
 		g_free (newname);



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