From 87ce2aa098dcc1a8f3511ff07260638c83bf62c0 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 11 Oct 2003 17:41:15 +0300 Subject: more resonable errors about name resolving in subqueries (BUG#1483) mysql-test/r/subselect.result: more resonable errors about name resolving in subqueries mysql-test/t/subselect.test: more resonable errors about name resolving in subqueries sql/item.cc: more resonable errors about name resolving in subqueries --- sql/item.cc | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'sql') diff --git a/sql/item.cc b/sql/item.cc index 4de4951cb51..0681fab9d1b 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -794,6 +794,7 @@ bool Item_field::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) if (!field) // If field is not checked { TABLE_LIST *where= 0; + bool upward_lookup= 0; Field *tmp= (Field *)not_found_field; if ((tmp= find_field_in_tables(thd, this, tables, &where, 0)) == not_found_field) @@ -821,6 +822,7 @@ bool Item_field::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) sl; sl= sl->outer_select()) { + upward_lookup= 1; table_list= (last= sl)->get_table_list(); if (sl->resolve_mode == SELECT_LEX::INSERT_MODE && table_list) { @@ -846,8 +848,14 @@ bool Item_field::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) return 1; else if (tmp == not_found_field && refer == (Item **)not_found_item) { - // call to return error code - find_field_in_tables(thd, this, tables, &where, 1); + if (upward_lookup) + // We can't say exactly what absend table or field + my_printf_error(ER_BAD_FIELD_ERROR, ER(ER_BAD_FIELD_ERROR), MYF(0), + full_name(), thd->where); + else + // Call to report error + find_field_in_tables(thd, this, tables, &where, 1); + return -1; } else if (refer != (Item **)not_found_item) @@ -1350,6 +1358,7 @@ bool Item_ref::fix_fields(THD *thd,TABLE_LIST *tables, Item **reference) if (!ref) { TABLE_LIST *where= 0, *table_list; + bool upward_lookup= 0; SELECT_LEX *sl= thd->lex.current_select->outer_select(); /* Finding only in current select will be performed for selects that have @@ -1367,6 +1376,7 @@ bool Item_ref::fix_fields(THD *thd,TABLE_LIST *tables, Item **reference) REPORT_ALL_ERRORS))) == (Item **)not_found_item) { + upward_lookup= 1; Field *tmp= (Field*) not_found_field; /* We can't find table field in table list of current select, @@ -1408,11 +1418,16 @@ bool Item_ref::fix_fields(THD *thd,TABLE_LIST *tables, Item **reference) return -1; else if (ref == (Item **)not_found_item && tmp == not_found_field) { - // Call to report error - find_item_in_list(this, - *(thd->lex.current_select->get_item_list()), - &counter, - REPORT_ALL_ERRORS); + if (upward_lookup) + // We can't say exactly what absend (table or field) + my_printf_error(ER_BAD_FIELD_ERROR, ER(ER_BAD_FIELD_ERROR), MYF(0), + full_name(), thd->where); + else + // Call to report error + find_item_in_list(this, + *(thd->lex.current_select->get_item_list()), + &counter, + REPORT_ALL_ERRORS); ref= 0; return 1; } -- cgit v1.2.1