[libgda] Bug correction in GdaStatement structure analysis
- From: Vivien Malerba <vivien src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgda] Bug correction in GdaStatement structure analysis
- Date: Tue, 8 Nov 2011 22:30:06 +0000 (UTC)
commit e87f76b4ef60964ba21a69243b2e76ba72bc363c
Author: Vivien Malerba <malerba gnome-db org>
Date: Tue Nov 8 23:29:27 2011 +0100
Bug correction in GdaStatement structure analysis
when the same table is used more than once in a SELECT and
when sub SELECT statements are used as targets of other SELECT
statements
libgda/sql-parser/gda-statement-struct-select.c | 16 ++++++++--------
libgda/sql-parser/gda-statement-struct.c | 5 ++++-
2 files changed, 12 insertions(+), 9 deletions(-)
---
diff --git a/libgda/sql-parser/gda-statement-struct-select.c b/libgda/sql-parser/gda-statement-struct-select.c
index 619a0d2..cde484c 100644
--- a/libgda/sql-parser/gda-statement-struct-select.c
+++ b/libgda/sql-parser/gda-statement-struct-select.c
@@ -444,23 +444,23 @@ gda_sql_statement_select_check_validity (GdaSqlAnyPart *stmt, G_GNUC_UNUSED gpoi
hash = g_hash_table_new (g_str_hash, g_str_equal);
for (list = select->from->targets; list; list = list->next) {
GdaSqlSelectTarget *t = (GdaSqlSelectTarget*) list->data;
- if (t->table_name) {
- if (g_hash_table_lookup (hash, t->table_name)) {
+ if (t->as) {
+ if (g_hash_table_lookup (hash, t->as)) {
g_set_error (error, GDA_SQL_ERROR, GDA_SQL_VALIDATION_ERROR,
- _("Multiple targets named or aliased '%s'"), t->table_name);
+ _("Multiple targets named or aliased '%s'"), t->as);
retval = FALSE;
break;
}
- g_hash_table_insert (hash, t->table_name, t);
+ g_hash_table_insert (hash, t->as, t);
}
- if (t->as) {
- if (g_hash_table_lookup (hash, t->as)) {
+ else if (t->table_name) {
+ if (g_hash_table_lookup (hash, t->table_name)) {
g_set_error (error, GDA_SQL_ERROR, GDA_SQL_VALIDATION_ERROR,
- _("Multiple targets named or aliased '%s'"), t->as);
+ _("Multiple targets named or aliased '%s'"), t->table_name);
retval = FALSE;
break;
}
- g_hash_table_insert (hash, t->as, t);
+ g_hash_table_insert (hash, t->table_name, t);
}
if (!retval)
diff --git a/libgda/sql-parser/gda-statement-struct.c b/libgda/sql-parser/gda-statement-struct.c
index e6f59f5..571047e 100644
--- a/libgda/sql-parser/gda-statement-struct.c
+++ b/libgda/sql-parser/gda-statement-struct.c
@@ -643,6 +643,7 @@ find_table_or_view (GdaSqlAnyPart *part, GdaSqlStatementCheckValidityData *data,
g_value_unset (&value);
if (!dbo && (*name == '"')) {
gchar *tmp;
+ g_clear_error (&lerror);
tmp = gda_sql_identifier_quote (name, data->cnc, NULL, TRUE, FALSE);
dbo = find_table_or_view (part, data, tmp, error);
g_free (tmp);
@@ -652,7 +653,9 @@ find_table_or_view (GdaSqlAnyPart *part, GdaSqlStatementCheckValidityData *data,
/* use @name as a table alias in the statement */
GdaSqlAnyPart *any;
- for (any = part->parent; any && any->parent; any = any->parent);
+ for (any = part->parent;
+ any && any->parent && (any->type != GDA_SQL_ANY_STMT_SELECT);
+ any = any->parent);
if (!any)
g_set_error (&lerror, GDA_SQL_ERROR, GDA_SQL_STRUCTURE_CONTENTS_ERROR,
"%s", _("GdaSqlSelectField is not part of a SELECT statement"));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]