sending right error message where VIEW is not expected (BUG#4606)
mysql-test/r/view.result: using VIEW where table is required mysql-test/t/view.test: using VIEW where table is required sql/sql_base.cc: sending right error message where VIEW is not expected sql/sql_view.h: frm_type_enum moved to table.h becuae used in TABLE_LIST sql/table.h: frm_type_enum moved to table.h becuae used in TABLE_LIST
This commit is contained in:
parent
2f16033f2f
commit
46a0c8a7df
@ -1047,3 +1047,9 @@ select * from v1;
|
||||
EXISTS (SELECT 1 UNION SELECT 2)
|
||||
1
|
||||
drop view v1;
|
||||
create table t1 (col1 int,col2 char(22));
|
||||
create view v1 as select * from t1;
|
||||
create index i1 on v1 (col1);
|
||||
ERROR HY000: 'test.v1' is not BASIC TABLE
|
||||
drop view v1;
|
||||
drop table t1;
|
||||
|
@ -987,3 +987,13 @@ SHOW TABLES;
|
||||
CREATE VIEW v1 AS SELECT EXISTS (SELECT 1 UNION SELECT 2);
|
||||
select * from v1;
|
||||
drop view v1;
|
||||
|
||||
#
|
||||
# using VIEW where table is required
|
||||
#
|
||||
create table t1 (col1 int,col2 char(22));
|
||||
create view v1 as select * from t1;
|
||||
-- error 1346
|
||||
create index i1 on v1 (col1);
|
||||
drop view v1;
|
||||
drop table t1;
|
||||
|
@ -38,6 +38,7 @@ static int open_unireg_entry(THD *thd, TABLE *entry, const char *db,
|
||||
static void free_cache_entry(TABLE *entry);
|
||||
static void mysql_rm_tmp_tables(void);
|
||||
static my_bool open_new_frm(const char *path, const char *alias,
|
||||
const char *db, const char *table_name,
|
||||
uint db_stat, uint prgflag,
|
||||
uint ha_open_flags, TABLE *outparam,
|
||||
TABLE_LIST *table_desc, MEM_ROOT *mem_root);
|
||||
@ -1379,8 +1380,6 @@ static int open_unireg_entry(THD *thd, TABLE *entry, const char *db,
|
||||
{
|
||||
char path[FN_REFLEN];
|
||||
int error;
|
||||
// we support new format only is have all parameters for it
|
||||
uint new_frm_flag= (table_desc && mem_root) ? NO_ERR_ON_NEW_FRM : 0;
|
||||
uint discover_retry_count= 0;
|
||||
DBUG_ENTER("open_unireg_entry");
|
||||
|
||||
@ -1388,12 +1387,12 @@ static int open_unireg_entry(THD *thd, TABLE *entry, const char *db,
|
||||
while ((error= openfrm(path, alias,
|
||||
(uint) (HA_OPEN_KEYFILE | HA_OPEN_RNDFILE |
|
||||
HA_GET_INDEX | HA_TRY_READ_ONLY |
|
||||
new_frm_flag),
|
||||
NO_ERR_ON_NEW_FRM),
|
||||
READ_KEYINFO | COMPUTE_TYPES | EXTRA_RECORD,
|
||||
thd->open_options, entry)) &&
|
||||
(error != 5 ||
|
||||
fn_format(path, path, 0, reg_ext, MY_UNPACK_FILENAME),
|
||||
open_new_frm(path, alias,
|
||||
open_new_frm(path, alias, db, name,
|
||||
(uint) (HA_OPEN_KEYFILE | HA_OPEN_RNDFILE |
|
||||
HA_GET_INDEX | HA_TRY_READ_ONLY),
|
||||
READ_KEYINFO | COMPUTE_TYPES | EXTRA_RECORD,
|
||||
@ -1679,6 +1678,8 @@ TABLE *open_ltable(THD *thd, TABLE_LIST *table_list, thr_lock_type lock_type)
|
||||
|
||||
thd->proc_info="Opening table";
|
||||
thd->current_tablenr= 0;
|
||||
/* open_ltable can be used only for BASIC TABLEs */
|
||||
table_list->required_type= FRMTYPE_TABLE;
|
||||
while (!(table= open_table(thd, table_list, 0, &refresh)) && refresh) ;
|
||||
|
||||
if (table)
|
||||
@ -3209,6 +3210,8 @@ int init_ftfuncs(THD *thd, SELECT_LEX *select_lex, bool no_order)
|
||||
open_new_frm()
|
||||
path path to .frm
|
||||
alias alias for table
|
||||
db database
|
||||
table_name name of table
|
||||
db_stat open flags (for example HA_OPEN_KEYFILE|HA_OPEN_RNDFILE..)
|
||||
can be 0 (example in ha_example_table)
|
||||
prgflag READ_ALL etc..
|
||||
@ -3218,7 +3221,9 @@ int init_ftfuncs(THD *thd, SELECT_LEX *select_lex, bool no_order)
|
||||
mem_root temporary MEM_ROOT for parsing
|
||||
*/
|
||||
static my_bool
|
||||
open_new_frm(const char *path, const char *alias, uint db_stat, uint prgflag,
|
||||
open_new_frm(const char *path, const char *alias,
|
||||
const char *db, const char *table_name,
|
||||
uint db_stat, uint prgflag,
|
||||
uint ha_open_flags, TABLE *outparam, TABLE_LIST *table_desc,
|
||||
MEM_ROOT *mem_root)
|
||||
{
|
||||
@ -3226,28 +3231,36 @@ open_new_frm(const char *path, const char *alias, uint db_stat, uint prgflag,
|
||||
LEX_STRING pathstr;
|
||||
pathstr.str= (char *)path;
|
||||
pathstr.length= strlen(path);
|
||||
|
||||
if (!mem_root)
|
||||
mem_root= ¤t_thd->mem_root;
|
||||
|
||||
File_parser *parser= sql_parse_prepare(&pathstr, mem_root, 1);
|
||||
if (parser)
|
||||
{
|
||||
if (!strncmp("VIEW", parser->type()->str, parser->type()->length))
|
||||
{
|
||||
if (mysql_make_view(parser, table_desc))
|
||||
if (table_desc == 0 || table_desc->required_type == FRMTYPE_TABLE)
|
||||
{
|
||||
bzero(outparam, sizeof(*outparam)); // do not run repair
|
||||
DBUG_RETURN(1);
|
||||
my_error(ER_WRONG_OBJECT, MYF(0), db, table_name, "BASIC TABLE");
|
||||
goto err;
|
||||
}
|
||||
if (mysql_make_view(parser, table_desc))
|
||||
goto err;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* only VIEWs are supported now */
|
||||
my_error(ER_FRM_UNKNOWN_TYPE, MYF(0), path, parser->type()->str);
|
||||
bzero(outparam, sizeof(outparam)); // do not run repair
|
||||
DBUG_RETURN(1);
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DBUG_RETURN(1);
|
||||
}
|
||||
goto err;
|
||||
|
||||
DBUG_RETURN(0);
|
||||
|
||||
err:
|
||||
bzero(outparam, sizeof(TABLE)); // do not run repair
|
||||
DBUG_RETURN(1);
|
||||
}
|
||||
|
@ -27,13 +27,6 @@ bool check_key_in_view(THD *thd, TABLE_LIST * view);
|
||||
|
||||
void insert_view_fields(List<Item> *list, TABLE_LIST *view);
|
||||
|
||||
enum frm_type_enum
|
||||
{
|
||||
FRMTYPE_ERROR,
|
||||
FRMTYPE_TABLE,
|
||||
FRMTYPE_VIEW
|
||||
};
|
||||
|
||||
frm_type_enum mysql_frm_type(char *path);
|
||||
|
||||
extern TYPELIB sql_updatable_view_key_typelib;
|
||||
|
@ -47,6 +47,13 @@ typedef struct st_grant_info
|
||||
|
||||
enum tmp_table_type {NO_TMP_TABLE=0, TMP_TABLE=1, TRANSACTIONAL_TMP_TABLE=2};
|
||||
|
||||
enum frm_type_enum
|
||||
{
|
||||
FRMTYPE_ERROR= 0,
|
||||
FRMTYPE_TABLE,
|
||||
FRMTYPE_VIEW
|
||||
};
|
||||
|
||||
typedef struct st_filesort_info
|
||||
{
|
||||
IO_CACHE *io_cache; /* If sorted through filebyte */
|
||||
@ -241,6 +248,8 @@ typedef struct st_table_list
|
||||
bool setup_is_done; /* setup_tables() is done */
|
||||
/* do view contain auto_increment field */
|
||||
bool contain_auto_increment;
|
||||
/* FRMTYPE_ERROR if any type is acceptable */
|
||||
enum frm_type_enum required_type;
|
||||
char timestamp_buffer[20]; /* buffer for timestamp (19+1) */
|
||||
|
||||
void calc_md5(char *buffer);
|
||||
|
Loading…
x
Reference in New Issue
Block a user