After merge fixes.

parent 01bc7616
......@@ -143,24 +143,13 @@ Event_timed::init_name(THD *thd, sp_name *spn)
MEM_ROOT *root= thd->mem_root;
/* We have to copy strings to get them into the right memroot */
if (spn)
{
dbname.length= spn->m_db.length;
if (spn->m_db.length == 0)
dbname.str= NULL;
else
dbname.str= strmake_root(root, spn->m_db.str, spn->m_db.length);
name.length= spn->m_name.length;
name.str= strmake_root(root, spn->m_name.str, spn->m_name.length);
dbname.length= spn->m_db.length;
dbname.str= strmake_root(root, spn->m_db.str, spn->m_db.length);
name.length= spn->m_name.length;
name.str= strmake_root(root, spn->m_name.str, spn->m_name.length);
if (spn->m_qname.length == 0)
spn->init_qname(thd);
}
else if (thd->db)
{
dbname.length= thd->db_length;
dbname.str= strmake_root(root, thd->db, dbname.length);
}
if (spn->m_qname.length == 0)
spn->init_qname(thd);
DBUG_PRINT("dbname", ("len=%d db=%s",dbname.length, dbname.str));
DBUG_PRINT("name", ("len=%d name=%s",name.length, name.str));
......
......@@ -598,8 +598,9 @@ db_create_event(THD *thd, Event_timed *et, my_bool create_if_not,
int ret= 0;
CHARSET_INFO *scs= system_charset_info;
TABLE *table;
char olddb[128];
bool dbchanged= false;
char old_db_buf[NAME_LEN+1];
LEX_STRING old_db= { old_db_buf, sizeof(old_db_buf) };
bool dbchanged;
DBUG_ENTER("db_create_event");
DBUG_PRINT("enter", ("name: %.*s", et->name.length, et->name.str));
......@@ -626,8 +627,7 @@ db_create_event(THD *thd, Event_timed *et, my_bool create_if_not,
}
DBUG_PRINT("info", ("non-existant, go forward"));
if ((ret= sp_use_new_db(thd, et->dbname.str,olddb, sizeof(olddb),0,
&dbchanged)))
if ((ret= sp_use_new_db(thd, et->dbname, &old_db, 0, &dbchanged)))
{
my_error(ER_BAD_DB_ERROR, MYF(0));
goto err;
......@@ -691,14 +691,14 @@ db_create_event(THD *thd, Event_timed *et, my_bool create_if_not,
*rows_affected= 1;
ok:
if (dbchanged)
(void) mysql_change_db(thd, olddb, 1);
(void) mysql_change_db(thd, old_db.str, 1);
if (table)
close_thread_tables(thd);
DBUG_RETURN(EVEX_OK);
err:
if (dbchanged)
(void) mysql_change_db(thd, olddb, 1);
(void) mysql_change_db(thd, old_db.str, 1);
if (table)
close_thread_tables(thd);
DBUG_RETURN(EVEX_GENERAL_ERROR);
......
......@@ -495,20 +495,32 @@ sp_head::init_strings(THD *thd, LEX *lex, sp_name *name)
/* During parsing, we must use thd->mem_root */
MEM_ROOT *root= thd->mem_root;
DBUG_ASSERT(name);
/* Must be initialized in the parser */
DBUG_ASSERT(name->m_db.str && name->m_db.length);
/* We have to copy strings to get them into the right memroot */
m_db.length= name->m_db.length;
m_db.str= strmake_root(root, name->m_db.str, name->m_db.length);
m_name.length= name->m_name.length;
m_name.str= strmake_root(root, name->m_name.str, name->m_name.length);
if (name->m_qname.length == 0)
name->init_qname(thd);
m_qname.length= name->m_qname.length;
m_qname.str= strmake_root(root, name->m_qname.str, m_qname.length);
if (name)
{
/* Must be initialized in the parser */
DBUG_ASSERT(name->m_db.str && name->m_db.length);
/* We have to copy strings to get them into the right memroot */
m_db.length= name->m_db.length;
m_db.str= strmake_root(root, name->m_db.str, name->m_db.length);
m_name.length= name->m_name.length;
m_name.str= strmake_root(root, name->m_name.str, name->m_name.length);
if (name->m_qname.length == 0)
name->init_qname(thd);
m_qname.length= name->m_qname.length;
m_qname.str= strmake_root(root, name->m_qname.str, m_qname.length);
}
else
{
/*
FIXME: the only use case when name is NULL is events, and it should
be rewritten soon. Remove the else part and replace 'if' with
an assert when this is done.
*/
LEX_STRING str_reset= { NULL, 0 };
m_db= m_name= m_qname= str_reset;
}
if (m_param_begin && m_param_end)
{
......
......@@ -66,7 +66,6 @@ static void time_out_user_resource_limits(THD *thd, USER_CONN *uc);
static int check_for_max_user_connections(THD *thd, USER_CONN *uc);
#endif
static void decrease_user_connections(USER_CONN *uc);
static bool check_db_used(THD *thd,TABLE_LIST *tables);
static bool check_multi_update_lock(THD *thd);
static void remove_escape(char *name);
static bool execute_sqlcom_select(THD *thd, TABLE_LIST *all_tables);
......@@ -1362,7 +1361,21 @@ pthread_handler_t handle_bootstrap(void *arg)
}
/* This works because items are allocated with sql_alloc() */
/* This works because items are allocated with sql_alloc() */
void free_items(Item *item)
{
Item *next;
DBUG_ENTER("free_items");
for (; item ; item=next)
{
next=item->next;
item->delete_self();
}
DBUG_VOID_RETURN;
}
/* This works because items are allocated with sql_alloc() */
void cleanup_items(Item *item)
{
......@@ -2719,8 +2732,7 @@ mysql_execute_command(THD *thd)
case SQLCOM_BACKUP_TABLE:
{
DBUG_ASSERT(first_table == all_tables && first_table != 0);
if (check_db_used(thd, all_tables) ||
check_table_access(thd, SELECT_ACL, all_tables, 0) ||
if (check_table_access(thd, SELECT_ACL, all_tables, 0) ||
check_global_access(thd, FILE_ACL))
goto error; /* purecov: inspected */
thd->enable_slow_log= opt_log_slow_admin_statements;
......@@ -2732,8 +2744,7 @@ mysql_execute_command(THD *thd)
case SQLCOM_RESTORE_TABLE:
{
DBUG_ASSERT(first_table == all_tables && first_table != 0);
if (check_db_used(thd, all_tables) ||
check_table_access(thd, INSERT_ACL, all_tables, 0) ||
if (check_table_access(thd, INSERT_ACL, all_tables, 0) ||
check_global_access(thd, FILE_ACL))
goto error; /* purecov: inspected */
thd->enable_slow_log= opt_log_slow_admin_statements;
......@@ -2745,8 +2756,7 @@ mysql_execute_command(THD *thd)
case SQLCOM_ASSIGN_TO_KEYCACHE:
{
DBUG_ASSERT(first_table == all_tables && first_table != 0);
if (check_db_used(thd, all_tables) ||
check_access(thd, INDEX_ACL, first_table->db,
if (check_access(thd, INDEX_ACL, first_table->db,
&first_table->grant.privilege, 0, 0,
test(first_table->schema_table)))
goto error;
......@@ -2756,8 +2766,7 @@ mysql_execute_command(THD *thd)
case SQLCOM_PRELOAD_KEYS:
{
DBUG_ASSERT(first_table == all_tables && first_table != 0);
if (check_db_used(thd, all_tables) ||
check_access(thd, INDEX_ACL, first_table->db,
if (check_access(thd, INDEX_ACL, first_table->db,
&first_table->grant.privilege, 0, 0,
test(first_table->schema_table)))
goto error;
......@@ -3131,8 +3140,6 @@ mysql_execute_command(THD *thd)
{
DBUG_ASSERT(first_table == all_tables && first_table != 0);
TABLE_LIST *table;
if (check_db_used(thd, all_tables))
goto error;
for (table= first_table; table; table= table->next_local->next_local)
{
if (check_access(thd, ALTER_ACL | DROP_ACL, table->db,
......@@ -3189,8 +3196,7 @@ mysql_execute_command(THD *thd)
if (lex->only_view)
first_table->skip_temporary= 1;
if (check_db_used(thd, all_tables) ||
check_access(thd, SELECT_ACL | EXTRA_ACL, first_table->db,
if (check_access(thd, SELECT_ACL | EXTRA_ACL, first_table->db,
&first_table->grant.privilege, 0, 0,
test(first_table->schema_table)))
goto error;
......@@ -3203,8 +3209,7 @@ mysql_execute_command(THD *thd)
case SQLCOM_CHECKSUM:
{
DBUG_ASSERT(first_table == all_tables && first_table != 0);
if (check_db_used(thd, all_tables) ||
check_table_access(thd, SELECT_ACL | EXTRA_ACL, all_tables, 0))
if (check_table_access(thd, SELECT_ACL | EXTRA_ACL, all_tables, 0))
goto error; /* purecov: inspected */
res = mysql_checksum_table(thd, first_table, &lex->check_opt);
break;
......@@ -3212,8 +3217,7 @@ mysql_execute_command(THD *thd)
case SQLCOM_REPAIR:
{
DBUG_ASSERT(first_table == all_tables && first_table != 0);
if (check_db_used(thd, all_tables) ||
check_table_access(thd, SELECT_ACL | INSERT_ACL, all_tables, 0))
if (check_table_access(thd, SELECT_ACL | INSERT_ACL, all_tables, 0))
goto error; /* purecov: inspected */
thd->enable_slow_log= opt_log_slow_admin_statements;
res= mysql_repair_table(thd, first_table, &lex->check_opt);
......@@ -3234,8 +3238,7 @@ mysql_execute_command(THD *thd)
case SQLCOM_CHECK:
{
DBUG_ASSERT(first_table == all_tables && first_table != 0);
if (check_db_used(thd, all_tables) ||
check_table_access(thd, SELECT_ACL | EXTRA_ACL , all_tables, 0))
if (check_table_access(thd, SELECT_ACL | EXTRA_ACL , all_tables, 0))
goto error; /* purecov: inspected */
thd->enable_slow_log= opt_log_slow_admin_statements;
res = mysql_check_table(thd, first_table, &lex->check_opt);
......@@ -3246,8 +3249,7 @@ mysql_execute_command(THD *thd)
case SQLCOM_ANALYZE:
{
DBUG_ASSERT(first_table == all_tables && first_table != 0);
if (check_db_used(thd, all_tables) ||
check_table_access(thd, SELECT_ACL | INSERT_ACL, all_tables, 0))
if (check_table_access(thd, SELECT_ACL | INSERT_ACL, all_tables, 0))
goto error; /* purecov: inspected */
thd->enable_slow_log= opt_log_slow_admin_statements;
res= mysql_analyze_table(thd, first_table, &lex->check_opt);
......@@ -3269,8 +3271,7 @@ mysql_execute_command(THD *thd)
case SQLCOM_OPTIMIZE:
{
DBUG_ASSERT(first_table == all_tables && first_table != 0);
if (check_db_used(thd, all_tables) ||
check_table_access(thd, SELECT_ACL | INSERT_ACL, all_tables, 0))
if (check_table_access(thd, SELECT_ACL | INSERT_ACL, all_tables, 0))
goto error; /* purecov: inspected */
thd->enable_slow_log= opt_log_slow_admin_statements;
res= (specialflag & (SPECIAL_SAFE_MODE | SPECIAL_NO_NEW_FUNC)) ?
......@@ -3690,7 +3691,7 @@ mysql_execute_command(THD *thd)
break;
case SQLCOM_LOCK_TABLES:
unlock_locked_tables(thd);
if (check_db_used(thd, all_tables) || end_active_trans(thd))
if (end_active_trans(thd))
goto error;
if (check_table_access(thd, LOCK_TABLES_ACL | SELECT_ACL, all_tables, 0))
goto error;
......@@ -4167,7 +4168,7 @@ mysql_execute_command(THD *thd)
case SQLCOM_FLUSH:
{
bool write_to_binlog;
if (check_global_access(thd,RELOAD_ACL) || check_db_used(thd, all_tables))
if (check_global_access(thd,RELOAD_ACL))
goto error;
/*
reload_acl_and_cache() will tell us if we are allowed to write to the
......@@ -4216,15 +4217,12 @@ mysql_execute_command(THD *thd)
#endif
case SQLCOM_HA_OPEN:
DBUG_ASSERT(first_table == all_tables && first_table != 0);
if (check_db_used(thd, all_tables) ||
check_table_access(thd, SELECT_ACL, all_tables, 0))
if (check_table_access(thd, SELECT_ACL, all_tables, 0))
goto error;
res= mysql_ha_open(thd, first_table, 0);
break;
case SQLCOM_HA_CLOSE:
DBUG_ASSERT(first_table == all_tables && first_table != 0);
if (check_db_used(thd, all_tables))
goto error;
res= mysql_ha_close(thd, first_table);
break;
case SQLCOM_HA_READ:
......@@ -4234,8 +4232,6 @@ mysql_execute_command(THD *thd)
if a user has no permissions to read a table, he won't be
able to open it (with SQLCOM_HA_OPEN) in the first place.
*/
if (check_db_used(thd, all_tables))
goto error;
unit->set_limit(select_lex);
res= mysql_ha_read(thd, first_table, lex->ha_read_mode, lex->ident.str,
lex->insert_list, lex->ha_rkey_mode, select_lex->where,
......@@ -5734,27 +5730,6 @@ bool check_merge_table_access(THD *thd, char *db,
}
static bool check_db_used(THD *thd,TABLE_LIST *tables)
{
char *current_db= NULL;
for (; tables; tables= tables->next_global)
{
if (tables->db == NULL)
{
/*
This code never works and should be removed in 5.1. All tables
that are added to the list of tables should already have its
database field initialized properly (see st_lex::add_table_to_list).
*/
DBUG_ASSERT(0);
if (thd->copy_db_to(&current_db, 0))
return TRUE;
tables->db= current_db;
}
}
return FALSE;
}
/****************************************************************************
Check stack size; Send error if there isn't enough stack to continue
****************************************************************************/
......@@ -7450,8 +7425,7 @@ bool multi_delete_precheck(THD *thd, TABLE_LIST *tables)
/* sql_yacc guarantees that tables and aux_tables are not zero */
DBUG_ASSERT(aux_tables != 0);
if (check_db_used(thd, tables) || check_db_used(thd,aux_tables) ||
check_table_access(thd, SELECT_ACL, tables, 0))
if (check_table_access(thd, SELECT_ACL, tables, 0))
DBUG_RETURN(TRUE);
/*
......@@ -7551,8 +7525,7 @@ bool update_precheck(THD *thd, TABLE_LIST *tables)
my_message(ER_WRONG_VALUE_COUNT, ER(ER_WRONG_VALUE_COUNT), MYF(0));
DBUG_RETURN(TRUE);
}
DBUG_RETURN(check_db_used(thd, tables) ||
check_one_table_access(thd, UPDATE_ACL, tables));
DBUG_RETURN(check_one_table_access(thd, UPDATE_ACL, tables));
}
......@@ -7614,8 +7587,6 @@ bool insert_precheck(THD *thd, TABLE_LIST *tables)
my_message(ER_WRONG_VALUE_COUNT, ER(ER_WRONG_VALUE_COUNT), MYF(0));
DBUG_RETURN(TRUE);
}
if (check_db_used(thd, tables))
DBUG_RETURN(TRUE);
DBUG_RETURN(FALSE);
}
......
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