[libgda] gda_statement_check_validity() correction



commit edf9917c1f10dd281aad3fc0eea9fe44f514dcae
Author: Vivien Malerba <malerba gnome-db org>
Date:   Wed Oct 19 21:12:57 2011 +0200

    gda_statement_check_validity() correction
    
    and updated test cases

 libgda/sql-parser/gda-statement-struct.c |   11 ++++++++++-
 tests/parser/testvalid.xml               |   10 ++++++++++
 2 files changed, 20 insertions(+), 1 deletions(-)
---
diff --git a/libgda/sql-parser/gda-statement-struct.c b/libgda/sql-parser/gda-statement-struct.c
index 3baafbf..b00c85f 100644
--- a/libgda/sql-parser/gda-statement-struct.c
+++ b/libgda/sql-parser/gda-statement-struct.c
@@ -633,6 +633,7 @@ find_table_or_view (GdaSqlAnyPart *part, GdaSqlStatementCheckValidityData *data,
 	GdaMetaDbObject *dbo;
 	GValue value;
 	GError *lerror = NULL;
+
 	memset (&value, 0, sizeof (GValue));
 
 	/* use @name as the table or view's real name */
@@ -640,6 +641,13 @@ find_table_or_view (GdaSqlAnyPart *part, GdaSqlStatementCheckValidityData *data,
 	dbo = gda_meta_struct_complement (data->mstruct, GDA_META_DB_UNKNOWN,
 					  NULL, NULL, &value, &lerror);
 	g_value_unset (&value);
+	if (!dbo && (*name == '"')) {
+		gchar *tmp;
+		tmp = gda_sql_identifier_quote (name, data->cnc, NULL, TRUE, FALSE);
+		dbo = find_table_or_view (part, data, tmp, error);
+		g_free (tmp);
+		return dbo;
+	}
 	if (!dbo) {
 		/* use @name as a table alias in the statement */
 		GdaSqlAnyPart *any;
@@ -656,7 +664,7 @@ find_table_or_view (GdaSqlAnyPart *part, GdaSqlStatementCheckValidityData *data,
 					GSList *targets;
 					for (targets = select->from->targets; targets; targets = targets->next) {
 						GdaSqlSelectTarget *target = (GdaSqlSelectTarget*) targets->data;
-						if (!target->as)
+						if (!target->as || strcmp (target->as, name))
 							continue;
 						g_value_set_string (g_value_init (&value, G_TYPE_STRING),
 								    target->table_name);
@@ -693,6 +701,7 @@ find_table_or_view (GdaSqlAnyPart *part, GdaSqlStatementCheckValidityData *data,
 		if (lerror)
 			g_propagate_error (error, lerror);
 	}
+
 	return dbo;
 }
 
diff --git a/tests/parser/testvalid.xml b/tests/parser/testvalid.xml
index c0e74f5..208333c 100644
--- a/tests/parser/testvalid.xml
+++ b/tests/parser/testvalid.xml
@@ -27,6 +27,16 @@
   <test id="11">
     <sql valid="f">SELECT version() FROM customers, customers</sql>
   </test>
+
+  <test id="13">
+    <sql valid="t">select p.*, ca.categoryname from products p left join categories ca on (ca.id=p.category)</sql>
+  </test>
+  <test id="14">
+    <sql valid="t">select p.*, ca."categoryname" from products p left join categories ca on (ca.id=p.category)</sql>
+  </test>
+  <test id="14">
+    <sql valid="t">select "p".*, ca."categoryname" from products p left join categories ca on (ca.id=p.category)</sql>
+  </test>
   
   <!-- computing DML commands from SELECT -->
 



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