Commit 742de8f5 authored by unknown's avatar unknown

after merging fixing


include/m_string.h:
  added include to va_list bicame known
mysql-test/r/union.result:
  some changing in error message
sql/sql_base.cc:
  error detection moved
sql/sql_lex.cc:
  new flag to detect table name error
sql/sql_lex.h:
  new flag to detect table name error
sql/sql_yacc.yy:
  check possibility of using table name added
parent 8b255948
...@@ -31,6 +31,9 @@ ...@@ -31,6 +31,9 @@
#include <string.h> #include <string.h>
#endif #endif
/* need by my_vsnprintf */
#include <stdarg.h>
/* Correct some things for UNIXWARE7 */ /* Correct some things for UNIXWARE7 */
#ifdef HAVE_UNIXWARE7_THREADS #ifdef HAVE_UNIXWARE7_THREADS
#undef HAVE_STRINGS_H #undef HAVE_STRINGS_H
......
...@@ -85,7 +85,7 @@ a b ...@@ -85,7 +85,7 @@ a b
2 b 2 b
1 a 1 a
(select a,b from t1 limit 2) union all (select a,b from t2 order by a limit 1) order by t1.b; (select a,b from t1 limit 2) union all (select a,b from t2 order by a limit 1) order by t1.b;
Table 't1' from one of SELECT's can not be used in order clause Table 't1' from one of SELECT's can not be used in global ORDER clause
explain (select a,b from t1 limit 2) union all (select a,b from t2 order by a limit 1) order by b desc; explain (select a,b from t1 limit 2) union all (select a,b from t2 order by a limit 1) order by b desc;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 4 1 PRIMARY t1 ALL NULL NULL NULL NULL 4
......
...@@ -1749,10 +1749,6 @@ find_field_in_tables(THD *thd, Item_ident *item, TABLE_LIST *tables, ...@@ -1749,10 +1749,6 @@ find_field_in_tables(THD *thd, Item_ident *item, TABLE_LIST *tables,
} }
if (report_error) if (report_error)
{ {
if (thd->lex.current_select->get_master()->order_list.elements)
my_printf_error(ER_TABLENAME_NOT_ALLOWED_HERE, ER(ER_TABLENAME_NOT_ALLOWED_HERE),
MYF(0), table_name, thd->where);
else
my_printf_error(ER_UNKNOWN_TABLE, ER(ER_UNKNOWN_TABLE), MYF(0), my_printf_error(ER_UNKNOWN_TABLE, ER(ER_UNKNOWN_TABLE), MYF(0),
table_name, thd->where); table_name, thd->where);
} }
......
...@@ -943,7 +943,7 @@ int yylex(void *arg, void *yythd) ...@@ -943,7 +943,7 @@ int yylex(void *arg, void *yythd)
void st_select_lex_node::init_query() void st_select_lex_node::init_query()
{ {
dependent= 0; no_table_names_allowed= dependent= 0;
} }
void st_select_lex_node::init_select() void st_select_lex_node::init_select()
......
...@@ -212,6 +212,7 @@ class st_select_lex_node { ...@@ -212,6 +212,7 @@ class st_select_lex_node {
bool with_sum_func; bool with_sum_func;
bool create_refs; bool create_refs;
bool dependent; /* dependent from outer select subselect */ bool dependent; /* dependent from outer select subselect */
bool no_table_names_allowed; /* used for global order by */
static void *operator new(size_t size) static void *operator new(size_t size)
{ {
......
...@@ -3740,17 +3740,41 @@ simple_ident: ...@@ -3740,17 +3740,41 @@ simple_ident:
} }
| ident '.' ident | ident '.' ident
{ {
SELECT_LEX_NODE *sel=Select; THD *thd= YYTHD;
LEX *lex= &thd->lex;
SELECT_LEX_NODE *sel= lex->current_select;
if (sel->no_table_names_allowed)
{
my_printf_error(ER_TABLENAME_NOT_ALLOWED_HERE,
ER(ER_TABLENAME_NOT_ALLOWED_HERE),
MYF(0), $1.str, thd->where);
}
$$ = !sel->create_refs || sel->get_in_sum_expr() > 0 ? (Item*) new Item_field(NullS,$1.str,$3.str) : (Item*) new Item_ref(NullS,$1.str,$3.str); $$ = !sel->create_refs || sel->get_in_sum_expr() > 0 ? (Item*) new Item_field(NullS,$1.str,$3.str) : (Item*) new Item_ref(NullS,$1.str,$3.str);
} }
| '.' ident '.' ident | '.' ident '.' ident
{ {
SELECT_LEX_NODE *sel=Select; THD *thd= YYTHD;
LEX *lex= &thd->lex;
SELECT_LEX_NODE *sel= lex->current_select;
if (sel->no_table_names_allowed)
{
my_printf_error(ER_TABLENAME_NOT_ALLOWED_HERE,
ER(ER_TABLENAME_NOT_ALLOWED_HERE),
MYF(0), $2.str, thd->where);
}
$$ = !sel->create_refs || sel->get_in_sum_expr() > 0 ? (Item*) new Item_field(NullS,$2.str,$4.str) : (Item*) new Item_ref(NullS,$2.str,$4.str); $$ = !sel->create_refs || sel->get_in_sum_expr() > 0 ? (Item*) new Item_field(NullS,$2.str,$4.str) : (Item*) new Item_ref(NullS,$2.str,$4.str);
} }
| ident '.' ident '.' ident | ident '.' ident '.' ident
{ {
SELECT_LEX_NODE *sel=Select; THD *thd= YYTHD;
LEX *lex= &thd->lex;
SELECT_LEX_NODE *sel= lex->current_select;
if (sel->no_table_names_allowed)
{
my_printf_error(ER_TABLENAME_NOT_ALLOWED_HERE,
ER(ER_TABLENAME_NOT_ALLOWED_HERE),
MYF(0), $3.str, thd->where);
}
$$ = !sel->create_refs || sel->get_in_sum_expr() > 0 ? (Item*) new Item_field((YYTHD->client_capabilities & CLIENT_NO_SCHEMA ? NullS :$1.str),$3.str,$5.str) : (Item*) new Item_ref((YYTHD->client_capabilities & CLIENT_NO_SCHEMA ? NullS :$1.str),$3.str,$5.str); $$ = !sel->create_refs || sel->get_in_sum_expr() > 0 ? (Item*) new Item_field((YYTHD->client_capabilities & CLIENT_NO_SCHEMA ? NullS :$1.str),$3.str,$5.str) : (Item*) new Item_ref((YYTHD->client_capabilities & CLIENT_NO_SCHEMA ? NullS :$1.str),$3.str,$5.str);
}; };
...@@ -4535,7 +4559,8 @@ optional_order_or_limit: ...@@ -4535,7 +4559,8 @@ optional_order_or_limit:
/* Empty */ {} /* Empty */ {}
| |
{ {
LEX *lex=Lex; THD *thd= YYTHD;
LEX *lex= &thd->lex;
if (!lex->current_select->linkage == GLOBAL_OPTIONS_TYPE) if (!lex->current_select->linkage == GLOBAL_OPTIONS_TYPE)
{ {
send_error(lex->thd, ER_SYNTAX_ERROR); send_error(lex->thd, ER_SYNTAX_ERROR);
...@@ -4547,8 +4572,15 @@ optional_order_or_limit: ...@@ -4547,8 +4572,15 @@ optional_order_or_limit:
lex->current_select= sel->master_unit(); lex->current_select= sel->master_unit();
lex->current_select->select_limit= lex->current_select->select_limit=
lex->thd->variables.select_limit; lex->thd->variables.select_limit;
lex->current_select->no_table_names_allowed= 1;
thd->where= "global ORDER clause";
} }
order_or_limit order_or_limit
{
THD *thd= YYTHD;
thd->lex.current_select->no_table_names_allowed= 0;
thd->where= "";
}
; ;
order_or_limit: order_or_limit:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment