mirror of
https://github.com/MariaDB/server.git
synced 2025-08-01 03:47:19 +03:00
MDEV-16473 WITH statement throws 'no database selected' error
Different fix, just use NULL, not no_db,
This commit is contained in:
@ -1511,15 +1511,4 @@ a a
|
|||||||
3 3
|
3 3
|
||||||
1 1
|
1 1
|
||||||
drop database db_mdev_16473;
|
drop database db_mdev_16473;
|
||||||
create database `*` ;
|
|
||||||
create table `*`.t1 (a int);
|
|
||||||
insert into `*`.t1 values (2), (7), (3), (1);
|
|
||||||
use `*`;
|
|
||||||
select * from t1;
|
|
||||||
a
|
|
||||||
2
|
|
||||||
7
|
|
||||||
3
|
|
||||||
1
|
|
||||||
drop database `*`;
|
|
||||||
use test;
|
use test;
|
||||||
|
@ -1056,11 +1056,4 @@ select * from cte, db_mdev_16473.t1 as t where cte.a=t.a;
|
|||||||
|
|
||||||
drop database db_mdev_16473;
|
drop database db_mdev_16473;
|
||||||
|
|
||||||
create database `*` ;
|
|
||||||
create table `*`.t1 (a int);
|
|
||||||
insert into `*`.t1 values (2), (7), (3), (1);
|
|
||||||
use `*`;
|
|
||||||
select * from t1;
|
|
||||||
drop database `*`;
|
|
||||||
|
|
||||||
use test;
|
use test;
|
||||||
|
@ -7581,7 +7581,7 @@ bool check_grant(THD *thd, ulong want_access, TABLE_LIST *tables,
|
|||||||
tl->correspondent_table ? tl->correspondent_table : tl;
|
tl->correspondent_table ? tl->correspondent_table : tl;
|
||||||
sctx= t_ref->security_ctx ? t_ref->security_ctx : thd->security_ctx;
|
sctx= t_ref->security_ctx ? t_ref->security_ctx : thd->security_ctx;
|
||||||
|
|
||||||
if (tl->with ||
|
if (tl->with || !tl->db ||
|
||||||
(tl->select_lex &&
|
(tl->select_lex &&
|
||||||
(tl->with= tl->select_lex->find_table_def_in_with_clauses(tl))))
|
(tl->with= tl->select_lex->find_table_def_in_with_clauses(tl))))
|
||||||
continue;
|
continue;
|
||||||
|
@ -1531,6 +1531,12 @@ bool open_table(THD *thd, TABLE_LIST *table_list, Open_table_context *ot_ctx)
|
|||||||
DBUG_RETURN(true);
|
DBUG_RETURN(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!table_list->db)
|
||||||
|
{
|
||||||
|
my_error(ER_NO_DB_ERROR, MYF(0));
|
||||||
|
DBUG_RETURN(true);
|
||||||
|
}
|
||||||
|
|
||||||
key_length= get_table_def_key(table_list, &key);
|
key_length= get_table_def_key(table_list, &key);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -3330,14 +3336,6 @@ open_and_process_table(THD *thd, LEX *lex, TABLE_LIST *tables,
|
|||||||
/*
|
/*
|
||||||
Not a placeholder: must be a base/temporary table or a view. Let us open it.
|
Not a placeholder: must be a base/temporary table or a view. Let us open it.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (tables->no_default_db && !tables->is_fqtn)
|
|
||||||
{
|
|
||||||
my_message(ER_NO_DB_ERROR, ER(ER_NO_DB_ERROR), MYF(0));
|
|
||||||
error= TRUE;
|
|
||||||
goto end;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tables->table)
|
if (tables->table)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
|
@ -3959,12 +3959,9 @@ public:
|
|||||||
my_message(ER_NO_DB_ERROR, ER(ER_NO_DB_ERROR), MYF(0));
|
my_message(ER_NO_DB_ERROR, ER(ER_NO_DB_ERROR), MYF(0));
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
/*
|
/* This will allow to throw an error later for non-CTE references */
|
||||||
It does not matter what database name is set in this case
|
*p_db= NULL;
|
||||||
because it will never be used after parser stage
|
*p_db_length= 0;
|
||||||
*/
|
|
||||||
*p_db_length= strlen(no_db);
|
|
||||||
*p_db= strmake(no_db, *p_db_length);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -156,8 +156,6 @@ struct LEX_TYPE
|
|||||||
extern const LEX_STRING null_lex_str;
|
extern const LEX_STRING null_lex_str;
|
||||||
extern const LEX_STRING empty_lex_str;
|
extern const LEX_STRING empty_lex_str;
|
||||||
|
|
||||||
extern const char *no_db;
|
|
||||||
|
|
||||||
enum enum_sp_suid_behaviour
|
enum enum_sp_suid_behaviour
|
||||||
{
|
{
|
||||||
SP_IS_DEFAULT_SUID= 0,
|
SP_IS_DEFAULT_SUID= 0,
|
||||||
|
@ -139,7 +139,6 @@ static bool execute_show_status(THD *, TABLE_LIST *);
|
|||||||
static bool check_rename_table(THD *, TABLE_LIST *, TABLE_LIST *);
|
static bool check_rename_table(THD *, TABLE_LIST *, TABLE_LIST *);
|
||||||
|
|
||||||
const char *any_db="*any*"; // Special symbol for check_access
|
const char *any_db="*any*"; // Special symbol for check_access
|
||||||
const char *no_db="*"; // Used when no default db is set
|
|
||||||
|
|
||||||
const LEX_STRING command_name[257]={
|
const LEX_STRING command_name[257]={
|
||||||
{ C_STRING_WITH_LEN("Sleep") }, //0
|
{ C_STRING_WITH_LEN("Sleep") }, //0
|
||||||
@ -6685,11 +6684,7 @@ check_access(THD *thd, ulong want_access, const char *db, ulong *save_priv,
|
|||||||
THD_STAGE_INFO(thd, stage_checking_permissions);
|
THD_STAGE_INFO(thd, stage_checking_permissions);
|
||||||
if ((!db || !db[0]) && !thd->db && !dont_check_global_grants)
|
if ((!db || !db[0]) && !thd->db && !dont_check_global_grants)
|
||||||
{
|
{
|
||||||
DBUG_PRINT("error",("No database"));
|
DBUG_RETURN(FALSE); // CTE reference or an error later
|
||||||
if (!no_errors)
|
|
||||||
my_message(ER_NO_DB_ERROR, ER_THD(thd, ER_NO_DB_ERROR),
|
|
||||||
MYF(0)); /* purecov: tested */
|
|
||||||
DBUG_RETURN(TRUE); /* purecov: tested */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((db != NULL) && (db != any_db))
|
if ((db != NULL) && (db != any_db))
|
||||||
@ -8188,7 +8183,6 @@ TABLE_LIST *st_select_lex::add_table_to_list(THD *thd,
|
|||||||
DBUG_RETURN(0);
|
DBUG_RETURN(0);
|
||||||
else
|
else
|
||||||
ptr->is_fqtn= FALSE;
|
ptr->is_fqtn= FALSE;
|
||||||
ptr->no_default_db= !thd->db && !(lex->sphead && lex->sphead->m_name.str);
|
|
||||||
|
|
||||||
ptr->alias= alias_str;
|
ptr->alias= alias_str;
|
||||||
ptr->is_alias= alias ? TRUE : FALSE;
|
ptr->is_alias= alias ? TRUE : FALSE;
|
||||||
@ -8301,7 +8295,7 @@ TABLE_LIST *st_select_lex::add_table_to_list(THD *thd,
|
|||||||
lex->add_to_query_tables(ptr);
|
lex->add_to_query_tables(ptr);
|
||||||
|
|
||||||
// Pure table aliases do not need to be locked:
|
// Pure table aliases do not need to be locked:
|
||||||
if (!MY_TEST(table_options & TL_OPTION_ALIAS))
|
if (ptr->db && !(table_options & TL_OPTION_ALIAS))
|
||||||
{
|
{
|
||||||
ptr->mdl_request.init(MDL_key::TABLE, ptr->db, ptr->table_name, mdl_type,
|
ptr->mdl_request.init(MDL_key::TABLE, ptr->db, ptr->table_name, mdl_type,
|
||||||
MDL_TRANSACTION);
|
MDL_TRANSACTION);
|
||||||
|
@ -2095,8 +2095,7 @@ struct TABLE_LIST
|
|||||||
qualified name (<db_name>.<table_name>).
|
qualified name (<db_name>.<table_name>).
|
||||||
*/
|
*/
|
||||||
bool is_fqtn;
|
bool is_fqtn;
|
||||||
/** TRUE if no default database is defined for the table name */
|
|
||||||
bool no_default_db;
|
|
||||||
/* TRUE <=> derived table should be filled right after optimization. */
|
/* TRUE <=> derived table should be filled right after optimization. */
|
||||||
bool fill_me;
|
bool fill_me;
|
||||||
/* TRUE <=> view/DT is merged. */
|
/* TRUE <=> view/DT is merged. */
|
||||||
|
Reference in New Issue
Block a user