diff options
author | Monty <monty@mariadb.org> | 2017-04-23 19:39:57 +0300 |
---|---|---|
committer | Monty <monty@mariadb.org> | 2017-04-23 22:35:46 +0300 |
commit | 5a759d31f766087d5e135e1d3d3d987693bc9b88 (patch) | |
tree | 93c7359e8b211e269bfa73e5f595f34b9dca575a /sql/sql_trigger.cc | |
parent | cba84469eb96481568a9f4ddf3f2989c49c9294c (diff) | |
download | mariadb-git-5a759d31f766087d5e135e1d3d3d987693bc9b88.tar.gz |
Changing field::field_name and Item::name to LEX_CSTRING
Benefits of this patch:
- Removed a lot of calls to strlen(), especially for field_string
- Strings generated by parser are now const strings, less chance of
accidently changing a string
- Removed a lot of calls with LEX_STRING as parameter (changed to pointer)
- More uniform code
- Item::name_length was not kept up to date. Now fixed
- Several bugs found and fixed (Access to null pointers,
access of freed memory, wrong arguments to printf like functions)
- Removed a lot of casts from (const char*) to (char*)
Changes:
- This caused some ABI changes
- lex_string_set now uses LEX_CSTRING
- Some fucntions are now taking const char* instead of char*
- Create_field::change and after changed to LEX_CSTRING
- handler::connect_string, comment and engine_name() changed to LEX_CSTRING
- Checked printf() related calls to find bugs. Found and fixed several
errors in old code.
- A lot of changes from LEX_STRING to LEX_CSTRING, especially related to
parsing and events.
- Some changes from LEX_STRING and LEX_STRING & to LEX_CSTRING*
- Some changes for char* to const char*
- Added printf argument checking for my_snprintf()
- Introduced null_clex_str, star_clex_string, temp_lex_str to simplify
code
- Added item_empty_name and item_used_name to be able to distingush between
items that was given an empty name and items that was not given a name
This is used in sql_yacc.yy to know when to give an item a name.
- select table_name."*' is not anymore same as table_name.*
- removed not used function Item::rename()
- Added comparision of item->name_length before some calls to
my_strcasecmp() to speed up comparison
- Moved Item_sp_variable::make_field() from item.h to item.cc
- Some minimal code changes to avoid copying to const char *
- Fixed wrong error message in wsrep_mysql_parse()
- Fixed wrong code in find_field_in_natural_join() where real_item() was
set when it shouldn't
- ER_ERROR_ON_RENAME was used with extra arguments.
- Removed some (wrong) ER_OUTOFMEMORY, as alloc_root will already
give the error.
TODO:
- Check possible unsafe casts in plugin/auth_examples/qa_auth_interface.c
- Change code to not modify LEX_CSTRING for database name
(as part of lower_case_table_names)
Diffstat (limited to 'sql/sql_trigger.cc')
-rw-r--r-- | sql/sql_trigger.cc | 144 |
1 files changed, 73 insertions, 71 deletions
diff --git a/sql/sql_trigger.cc b/sql/sql_trigger.cc index d804e568b79..1d0d3341b37 100644 --- a/sql/sql_trigger.cc +++ b/sql/sql_trigger.cc @@ -34,8 +34,9 @@ #include "sp_cache.h" // sp_invalidate_cache #include <mysys_err.h> -LEX_STRING *make_lex_string(LEX_STRING *lex_str, const char* str, uint length, - MEM_ROOT *mem_root) +LEX_CSTRING *make_lex_string(LEX_CSTRING *lex_str, + const char* str, uint length, + MEM_ROOT *mem_root) { if (!(lex_str->str= strmake_root(mem_root, str, length))) return 0; @@ -56,9 +57,9 @@ public: static Trigger_creation_ctx *create(THD *thd, const char *db_name, const char *table_name, - const LEX_STRING *client_cs_name, - const LEX_STRING *connection_cl_name, - const LEX_STRING *db_cl_name); + const LEX_CSTRING *client_cs_name, + const LEX_CSTRING *connection_cl_name, + const LEX_CSTRING *db_cl_name); Trigger_creation_ctx(CHARSET_INFO *client_cs, CHARSET_INFO *connection_cl, @@ -92,9 +93,9 @@ Trigger_creation_ctx * Trigger_creation_ctx::create(THD *thd, const char *db_name, const char *table_name, - const LEX_STRING *client_cs_name, - const LEX_STRING *connection_cl_name, - const LEX_STRING *db_cl_name) + const LEX_CSTRING *client_cs_name, + const LEX_CSTRING *connection_cl_name, + const LEX_CSTRING *db_cl_name) { CHARSET_INFO *client_cs; CHARSET_INFO *connection_cl; @@ -162,7 +163,7 @@ Trigger_creation_ctx::create(THD *thd, /*************************************************************************/ -static const LEX_STRING triggers_file_type= +static const LEX_CSTRING triggers_file_type= { C_STRING_WITH_LEN("TRIGGERS") }; const char * const TRG_EXT= ".TRG"; @@ -176,37 +177,37 @@ const char * const TRG_EXT= ".TRG"; static File_option triggers_file_parameters[]= { { - { C_STRING_WITH_LEN("triggers") }, + { STRING_WITH_LEN("triggers") }, my_offsetof(class Table_triggers_list, definitions_list), FILE_OPTIONS_STRLIST }, { - { C_STRING_WITH_LEN("sql_modes") }, + { STRING_WITH_LEN("sql_modes") }, my_offsetof(class Table_triggers_list, definition_modes_list), FILE_OPTIONS_ULLLIST }, { - { C_STRING_WITH_LEN("definers") }, + { STRING_WITH_LEN("definers") }, my_offsetof(class Table_triggers_list, definers_list), FILE_OPTIONS_STRLIST }, { - { C_STRING_WITH_LEN("client_cs_names") }, + { STRING_WITH_LEN("client_cs_names") }, my_offsetof(class Table_triggers_list, client_cs_names), FILE_OPTIONS_STRLIST }, { - { C_STRING_WITH_LEN("connection_cl_names") }, + { STRING_WITH_LEN("connection_cl_names") }, my_offsetof(class Table_triggers_list, connection_cl_names), FILE_OPTIONS_STRLIST }, { - { C_STRING_WITH_LEN("db_cl_names") }, + { STRING_WITH_LEN("db_cl_names") }, my_offsetof(class Table_triggers_list, db_cl_names), FILE_OPTIONS_STRLIST }, { - { C_STRING_WITH_LEN("created") }, + { STRING_WITH_LEN("created") }, my_offsetof(class Table_triggers_list, create_times), FILE_OPTIONS_ULLLIST }, @@ -215,7 +216,7 @@ static File_option triggers_file_parameters[]= File_option sql_modes_parameters= { - { C_STRING_WITH_LEN("sql_modes") }, + { STRING_WITH_LEN("sql_modes") }, my_offsetof(class Table_triggers_list, definition_modes_list), FILE_OPTIONS_ULLLIST }; @@ -238,18 +239,18 @@ static const int TRG_NUM_REQUIRED_PARAMETERS= 7; struct st_trigname { - LEX_STRING trigger_table; + LEX_CSTRING trigger_table; }; -static const LEX_STRING trigname_file_type= - { C_STRING_WITH_LEN("TRIGGERNAME") }; +static const LEX_CSTRING trigname_file_type= + { STRING_WITH_LEN("TRIGGERNAME") }; const char * const TRN_EXT= ".TRN"; static File_option trigname_file_parameters[]= { { - { C_STRING_WITH_LEN("trigger_table")}, + { STRING_WITH_LEN("trigger_table")}, offsetof(struct st_trigname, trigger_table), FILE_OPTIONS_ESTRING }, @@ -260,9 +261,9 @@ static File_option trigname_file_parameters[]= class Handle_old_incorrect_sql_modes_hook: public Unknown_key_hook { private: - char *path; + const char *path; public: - Handle_old_incorrect_sql_modes_hook(char *file_path) + Handle_old_incorrect_sql_modes_hook(const char *file_path) :path(file_path) {}; virtual bool process_unknown_string(const char *&unknown_key, uchar* base, @@ -273,15 +274,15 @@ public: class Handle_old_incorrect_trigger_table_hook: public Unknown_key_hook { public: - Handle_old_incorrect_trigger_table_hook(char *file_path, - LEX_STRING *trigger_table_arg) + Handle_old_incorrect_trigger_table_hook(const char *file_path, + LEX_CSTRING *trigger_table_arg) :path(file_path), trigger_table_value(trigger_table_arg) {}; virtual bool process_unknown_string(const char *&unknown_key, uchar* base, MEM_ROOT *mem_root, const char *end); private: - char *path; - LEX_STRING *trigger_table_value; + const char *path; + LEX_CSTRING *trigger_table_value; }; @@ -299,7 +300,7 @@ class Deprecated_trigger_syntax_handler : public Internal_error_handler private: char m_message[MYSQL_ERRMSG_SIZE]; - LEX_STRING *m_trigger_name; + LEX_CSTRING *m_trigger_name; public: @@ -329,7 +330,7 @@ public: return false; } - LEX_STRING *get_trigger_name() { return m_trigger_name; } + LEX_CSTRING *get_trigger_name() { return m_trigger_name; } char *get_error_message() { return m_message; } }; @@ -643,10 +644,10 @@ end: static void build_trig_stmt_query(THD *thd, TABLE_LIST *tables, String *stmt_query, String *trigger_def, - LEX_STRING *trg_definer, + LEX_CSTRING *trg_definer, char trg_definer_holder[]) { - LEX_STRING stmt_definition; + LEX_CSTRING stmt_definition; LEX *lex= thd->lex; uint prefix_trimmed, suffix_trimmed; size_t original_length; @@ -671,7 +672,7 @@ static void build_trig_stmt_query(THD *thd, TABLE_LIST *tables, } else { - *trg_definer= empty_lex_str; + *trg_definer= empty_clex_str; } @@ -736,7 +737,7 @@ bool Table_triggers_list::create_trigger(THD *thd, TABLE_LIST *tables, LEX *lex= thd->lex; TABLE *table= tables->table; char file_buff[FN_REFLEN], trigname_buff[FN_REFLEN]; - LEX_STRING file, trigname_file; + LEX_CSTRING file, trigname_file; char trg_definer_holder[USER_HOST_BUFF_SIZE]; Item_trigger_field *trg_field; struct st_trigname trigname; @@ -839,7 +840,7 @@ bool Table_triggers_list::create_trigger(THD *thd, TABLE_LIST *tables, ER_TRG_ALREADY_EXISTS, ER_THD(thd, ER_TRG_ALREADY_EXISTS), trigname_buff); - LEX_STRING trg_definer_tmp; + LEX_CSTRING trg_definer_tmp; String trigger_def; /* @@ -1050,7 +1051,7 @@ bool Table_triggers_list::save_trigger_file(THD *thd, const char *db, const char *table_name) { char file_buff[FN_REFLEN]; - LEX_STRING file; + LEX_CSTRING file; if (create_lists_needed_for_files(thd->mem_root)) return true; @@ -1070,7 +1071,7 @@ bool Table_triggers_list::save_trigger_file(THD *thd, const char *db, @param remove_from_list If set, remove trigger if found */ -Trigger *Table_triggers_list::find_trigger(const LEX_STRING *name, +Trigger *Table_triggers_list::find_trigger(const LEX_CSTRING *name, bool remove_from_list) { for (uint i= 0; i < (uint)TRG_EVENT_MAX; i++) @@ -1125,7 +1126,7 @@ Trigger *Table_triggers_list::find_trigger(const LEX_STRING *name, bool Table_triggers_list::drop_trigger(THD *thd, TABLE_LIST *tables, String *stmt_query) { - const LEX_STRING *sp_name= &thd->lex->spname->m_name; // alias + const LEX_CSTRING *sp_name= &thd->lex->spname->m_name; // alias char path[FN_REFLEN]; Trigger *trigger; @@ -1298,7 +1299,7 @@ bool Table_triggers_list::check_n_load(THD *thd, const char *db, bool names_only) { char path_buff[FN_REFLEN]; - LEX_STRING path; + LEX_CSTRING path; File_parser *parser; LEX_STRING save_db; DBUG_ENTER("Table_triggers_list::check_n_load"); @@ -1318,7 +1319,7 @@ bool Table_triggers_list::check_n_load(THD *thd, const char *db, if (is_equal(&triggers_file_type, parser->type())) { Handle_old_incorrect_sql_modes_hook sql_modes_hook(path.str); - LEX_STRING *trg_create_str; + LEX_CSTRING *trg_create_str; ulonglong *trg_sql_mode, *trg_create_time; Trigger *trigger; Table_triggers_list *trigger_list= @@ -1332,7 +1333,7 @@ bool Table_triggers_list::check_n_load(THD *thd, const char *db, &sql_modes_hook)) goto error; - List_iterator_fast<LEX_STRING> it(trigger_list->definitions_list); + List_iterator_fast<LEX_CSTRING> it(trigger_list->definitions_list); if (!trigger_list->definitions_list.is_empty() && (trigger_list->client_cs_names.is_empty() || @@ -1351,10 +1352,10 @@ bool Table_triggers_list::check_n_load(THD *thd, const char *db, status_var_increment(thd->status_var.feature_trigger); List_iterator_fast<ulonglong> itm(trigger_list->definition_modes_list); - List_iterator_fast<LEX_STRING> it_definer(trigger_list->definers_list); - List_iterator_fast<LEX_STRING> it_client_cs_name(trigger_list->client_cs_names); - List_iterator_fast<LEX_STRING> it_connection_cl_name(trigger_list->connection_cl_names); - List_iterator_fast<LEX_STRING> it_db_cl_name(trigger_list->db_cl_names); + List_iterator_fast<LEX_CSTRING> it_definer(trigger_list->definers_list); + List_iterator_fast<LEX_CSTRING> it_client_cs_name(trigger_list->client_cs_names); + List_iterator_fast<LEX_CSTRING> it_connection_cl_name(trigger_list->connection_cl_names); + List_iterator_fast<LEX_CSTRING> it_db_cl_name(trigger_list->db_cl_names); List_iterator_fast<ulonglong> it_create_times(trigger_list->create_times); LEX *old_lex= thd->lex, lex; sp_rcontext *save_spcont= thd->spcont; @@ -1369,7 +1370,7 @@ bool Table_triggers_list::check_n_load(THD *thd, const char *db, { sp_head *sp; sql_mode_t sql_mode; - LEX_STRING *trg_definer; + LEX_CSTRING *trg_definer; Trigger_creation_ctx *creation_ctx; /* @@ -1386,7 +1387,8 @@ bool Table_triggers_list::check_n_load(THD *thd, const char *db, thd->variables.sql_mode= sql_mode; Parser_state parser_state; - if (parser_state.init(thd, trg_create_str->str, trg_create_str->length)) + if (parser_state.init(thd, (char*) trg_create_str->str, + trg_create_str->length)) goto err_with_lex_cleanup; if (!trigger_list->client_cs_names.is_empty()) @@ -1441,7 +1443,7 @@ bool Table_triggers_list::check_n_load(THD *thd, const char *db, trigger->sql_mode= sql_mode; trigger->definition= *trg_create_str; trigger->create_time= trg_create_time ? *trg_create_time : 0; - trigger->name= sp ? sp->m_name : empty_lex_str; + trigger->name= sp ? sp->m_name : empty_clex_str; trigger->on_table_name.str= (char*) lex.raw_trg_on_table_name_begin; trigger->on_table_name.length= (lex.raw_trg_on_table_name_end - lex.raw_trg_on_table_name_begin); @@ -1464,7 +1466,7 @@ bool Table_triggers_list::check_n_load(THD *thd, const char *db, if (parse_error) { - LEX_STRING *name; + LEX_CSTRING *name; /* In case of errors, disable all triggers for the table, but keep @@ -1483,7 +1485,7 @@ bool Table_triggers_list::check_n_load(THD *thd, const char *db, goto err_with_lex_cleanup; } trigger->definer= ((!trg_definer || !trg_definer->length) ? - empty_lex_str : *trg_definer); + empty_clex_str : *trg_definer); continue; } @@ -1509,8 +1511,8 @@ bool Table_triggers_list::check_n_load(THD *thd, const char *db, schema. */ - sp->set_definer((char*) "", 0); - trigger->definer= empty_lex_str; + sp->set_definer("", 0); + trigger->definer= empty_clex_str; /* trigger_list without definer information are executed under the @@ -1622,7 +1624,7 @@ error: void Table_triggers_list::add_trigger(trg_event_type event, trg_action_time_type action_time, trigger_order_type ordering_clause, - LEX_STRING *anchor_trigger_name, + LEX_CSTRING *anchor_trigger_name, Trigger *trigger) { Trigger **parent= &triggers[event][action_time]; @@ -1673,8 +1675,9 @@ void Table_triggers_list::add_trigger(trg_event_type event, True error */ -void Trigger::get_trigger_info(LEX_STRING *trigger_stmt, - LEX_STRING *trigger_body, LEX_STRING *definer) +void Trigger::get_trigger_info(LEX_CSTRING *trigger_stmt, + LEX_CSTRING *trigger_body, + LEX_STRING *definer) { DBUG_ENTER("get_trigger_info"); @@ -1726,7 +1729,7 @@ bool add_table_for_trigger(THD *thd, LEX *lex= thd->lex; char trn_path_buff[FN_REFLEN]; LEX_STRING trn_path= { trn_path_buff, 0 }; - LEX_STRING tbl_name= null_lex_str; + LEX_CSTRING tbl_name= null_clex_str; DBUG_ENTER("add_table_for_trigger"); @@ -1750,7 +1753,8 @@ bool add_table_for_trigger(THD *thd, DBUG_RETURN(TRUE); } - if (load_table_name_for_trigger(thd, trg_name, &trn_path, &tbl_name)) + if (load_table_name_for_trigger(thd, trg_name, (LEX_CSTRING*) &trn_path, + &tbl_name)) DBUG_RETURN(TRUE); *table= sp_add_to_query_tables(thd, lex, trg_name->m_db.str, @@ -1774,7 +1778,8 @@ bool add_table_for_trigger(THD *thd, True error */ -bool Table_triggers_list::drop_all_triggers(THD *thd, char *db, char *name) +bool Table_triggers_list::drop_all_triggers(THD *thd, const char *db, + const char *name) { TABLE table; char path[FN_REFLEN]; @@ -1848,7 +1853,7 @@ struct change_table_name_param THD *thd; const char *old_db_name; const char *new_db_name; - LEX_STRING *new_table_name; + LEX_CSTRING *new_table_name; Trigger *stopper; }; @@ -1857,8 +1862,8 @@ bool Table_triggers_list::change_table_name_in_triggers(THD *thd, const char *old_db_name, const char *new_db_name, - LEX_STRING *old_table_name, - LEX_STRING *new_table_name) + LEX_CSTRING *old_table_name, + LEX_CSTRING *new_table_name) { struct change_table_name_param param; sql_mode_t save_sql_mode= thd->variables.sql_mode; @@ -1890,9 +1895,8 @@ bool Trigger::change_table_name(void* param_arg) { change_table_name_param *param= (change_table_name_param*) param_arg; THD *thd= param->thd; - LEX_STRING *new_table_name= param->new_table_name; - - LEX_STRING *def= &definition, new_def; + LEX_CSTRING *new_table_name= param->new_table_name; + LEX_CSTRING *def= &definition, new_def; size_t on_q_table_name_len, before_on_len; String buff; @@ -1947,7 +1951,7 @@ bool Trigger::change_table_name(void* param_arg) Trigger * Table_triggers_list::change_table_name_in_trignames(const char *old_db_name, const char *new_db_name, - LEX_STRING *new_table_name, + LEX_CSTRING *new_table_name, Trigger *trigger) { struct change_table_name_param param; @@ -1966,7 +1970,7 @@ bool Trigger::change_on_table_name(void* param_arg) char trigname_buff[FN_REFLEN]; struct st_trigname trigname; - LEX_STRING trigname_file; + LEX_CSTRING trigname_file; if (param->stopper == this) return 0; // Stop processing @@ -2056,8 +2060,8 @@ bool Table_triggers_list::change_table_name(THD *thd, const char *db, result= 1; goto end; } - LEX_STRING old_table_name= { (char *) old_alias, strlen(old_alias) }; - LEX_STRING new_table_name= { (char *) new_table, strlen(new_table) }; + LEX_CSTRING old_table_name= { (char *) old_alias, strlen(old_alias) }; + LEX_CSTRING new_table_name= { (char *) new_table, strlen(new_table) }; /* Since triggers should be in the same schema as their subject tables moving table with them between two schemas raises too many questions. @@ -2468,16 +2472,14 @@ bool check_trn_exists(const LEX_STRING *trn_path) bool load_table_name_for_trigger(THD *thd, const sp_name *trg_name, - const LEX_STRING *trn_path, - LEX_STRING *tbl_name) + const LEX_CSTRING *trn_path, + LEX_CSTRING *tbl_name) { File_parser *parser; struct st_trigname trn_data; - Handle_old_incorrect_trigger_table_hook trigger_table_hook( trn_path->str, &trn_data.trigger_table); - DBUG_ENTER("load_table_name_for_trigger"); /* Parse the TRN-file. */ |