diff options
author | unknown <serg@serg.mylan> | 2004-01-13 12:31:25 +0100 |
---|---|---|
committer | unknown <serg@serg.mylan> | 2004-01-13 12:31:25 +0100 |
commit | febc79bb5d8a7cfe1f8e5eef50595f321786c467 (patch) | |
tree | 66fde442464b3be35a42583932a1fda9901670c7 | |
parent | f61cec71d19659759b44f42f1deccbe64a25bdbb (diff) | |
download | mariadb-git-febc79bb5d8a7cfe1f8e5eef50595f321786c467.tar.gz |
BUG#2304 - HANDLER and tables in non-current db
-rw-r--r-- | mysql-test/r/handler.result | 18 | ||||
-rw-r--r-- | mysql-test/t/handler.test | 16 | ||||
-rw-r--r-- | sql/sql_handler.cc | 7 | ||||
-rw-r--r-- | sql/sql_yacc.yy | 15 |
4 files changed, 47 insertions, 9 deletions
diff --git a/mysql-test/r/handler.result b/mysql-test/r/handler.result index 5467ea6dec2..1cfc3a9de8b 100644 --- a/mysql-test/r/handler.result +++ b/mysql-test/r/handler.result @@ -173,3 +173,21 @@ Unknown column 'W' in 'field list' handler t1 read a=(a); Wrong arguments to HANDLER ... READ drop table t1; +create table t1 (a char(5)); +insert into t1 values ("Ok"); +handler t1 open as t; +handler t read first; +a +Ok +use mysql; +handler t read first; +a +Ok +handler t close; +handler test.t1 open as t; +handler t read first; +a +Ok +handler t close; +use test; +drop table t1; diff --git a/mysql-test/t/handler.test b/mysql-test/t/handler.test index 736091a52a9..936902fd9bf 100644 --- a/mysql-test/t/handler.test +++ b/mysql-test/t/handler.test @@ -107,3 +107,19 @@ handler t1 read a=(W); handler t1 read a=(a); drop table t1; +# +# BUG#2304 +# +create table t1 (a char(5)); +insert into t1 values ("Ok"); +handler t1 open as t; +handler t read first; +use mysql; +handler t read first; +handler t close; +handler test.t1 open as t; +handler t read first; +handler t close; +use test; +drop table t1; + diff --git a/sql/sql_handler.cc b/sql/sql_handler.cc index 208545a435b..963111015da 100644 --- a/sql/sql_handler.cc +++ b/sql/sql_handler.cc @@ -276,14 +276,13 @@ static TABLE **find_table_ptr_by_name(THD *thd, const char *db, int dblen; TABLE **ptr; - if (!db || ! *db) - db= thd->db ? thd->db : ""; - dblen=strlen(db)+1; + DBUG_ASSERT(db); + dblen=*db ? strlen(db)+1 : 0; ptr=&(thd->handler_tables); for (TABLE *table=*ptr; table ; table=*ptr) { - if (!memcmp(table->table_cache_key, db, dblen) && + if ((!dblen || !memcmp(table->table_cache_key, db, dblen)) && !my_strcasecmp((is_alias ? table->table_name : table->real_name),table_name)) { if (table->version != refresh_version) diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index b5b9a4cdfb7..991a5f500e6 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -501,7 +501,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b,int *yystacksize); opt_table_alias %type <table> - table_ident + table_ident table_ident_ref %type <simple_string> remember_name remember_end opt_len opt_ident opt_db text_or_password @@ -3243,8 +3243,13 @@ field_ident: table_ident: ident { $$=new Table_ident($1); } | ident '.' ident { $$=new Table_ident($1,$3,0);} - | '.' ident { $$=new Table_ident($2);} - /* For Delphi */; + | '.' ident { $$=new Table_ident($2);} /* For Delphi */ + ; + +table_ident_ref: + ident { LEX_STRING db={"",0}; $$=new Table_ident(db,$1,0); } + | ident '.' ident { $$=new Table_ident($1,$3,0);} + ; ident: IDENT { $$=$1; } @@ -3610,13 +3615,13 @@ handler: if (!add_table_to_list($2,$4,0)) YYABORT; } - | HANDLER_SYM table_ident CLOSE_SYM + | HANDLER_SYM table_ident_ref CLOSE_SYM { Lex->sql_command = SQLCOM_HA_CLOSE; if (!add_table_to_list($2,0,0)) YYABORT; } - | HANDLER_SYM table_ident READ_SYM + | HANDLER_SYM table_ident_ref READ_SYM { LEX *lex=Lex; lex->sql_command = SQLCOM_HA_READ; |