From 71e84df08afedb85907f37192bbbd605210f20a3 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 7 Jul 2006 03:07:45 +0400 Subject: [PATCH] After merge fixes. sql/event_timed.cc: After merge fixes: dbname can never be NULL. sql/events.cc: After merge fixes: use a new signature of sp_use_new_db sql/sp_head.cc: After merge fixes: replace assert with an if for events code to work. sql/sql_parse.cc: After merge fixes: put back free_items, it's used in partitioning. Whether it is not a bug is to be investigated. Remove check_db_used, as planned. --- sql/event_timed.cc | 23 ++++-------- sql/events.cc | 12 +++---- sql/sp_head.cc | 36 ++++++++++++------- sql/sql_parse.cc | 89 ++++++++++++++++------------------------------ 4 files changed, 66 insertions(+), 94 deletions(-) diff --git a/sql/event_timed.cc b/sql/event_timed.cc index 4ec875f32a3..98369e0e055 100644 --- a/sql/event_timed.cc +++ b/sql/event_timed.cc @@ -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)); diff --git a/sql/events.cc b/sql/events.cc index d67c42326e3..4a2c7338d7c 100644 --- a/sql/events.cc +++ b/sql/events.cc @@ -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); diff --git a/sql/sp_head.cc b/sql/sp_head.cc index 1ebd645d9f9..81f5d502ec9 100644 --- a/sql/sp_head.cc +++ b/sql/sp_head.cc @@ -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); + 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); + /* 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->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) { diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 7201648dbfc..26e6a66b9b4 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -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 @@ end: } - /* 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 @@ end_with_restore_list: { 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 @@ end_with_restore_list: 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 @@ end_with_restore_list: 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 @@ end_with_restore_list: 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 @@ end_with_restore_list: 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 @@ end_with_restore_list: 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 @@ end_with_restore_list: 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 @@ end_with_restore_list: 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 @@ end_with_restore_list: 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 @@ end_with_restore_list: #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 @@ end_with_restore_list: 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(¤t_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); }