MCPcopy Create free account
hub / github.com/MariaDB/server / create_trigger

Method create_trigger

sql/sql_trigger.cc:930–1174  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

928*/
929
930bool Table_triggers_list::create_trigger(THD *thd, TABLE_LIST *tables,
931 String *stmt_query,
932 DDL_LOG_STATE *ddl_log_state,
933 DDL_LOG_STATE *ddl_log_state_tmp_file)
934{
935 LEX *lex= thd->lex;
936 TABLE *table= tables->table;
937 char file_buff[FN_REFLEN], trigname_buff[FN_REFLEN];
938 char backup_file_buff[FN_REFLEN];
939 char trg_definer_holder[USER_HOST_BUFF_SIZE];
940 LEX_CSTRING backup_name= { backup_file_buff, 0 };
941 LEX_CSTRING file, trigname_file;
942 struct st_trigname trigname;
943 String trigger_definition;
944 Trigger *trigger= 0;
945 int error;
946 bool trigger_exists;
947 DBUG_ENTER("create_trigger");
948
949 if (check_for_broken_triggers())
950 DBUG_RETURN(true);
951
952 /* Trigger must be in the same schema as target table. */
953 if (!table->s->db.streq(lex->spname->m_db))
954 {
955 my_error(ER_TRG_IN_WRONG_SCHEMA, MYF(0));
956 DBUG_RETURN(true);
957 }
958
959 if (sp_process_definer(thd))
960 DBUG_RETURN(true);
961
962 /*
963 Let us check if all references to fields in old/new versions of row in
964 this trigger are ok.
965
966 NOTE: We do it here more from ease of use standpoint. We still have to
967 do some checks on each execution. E.g. we can catch privilege changes
968 only during execution. Also in near future, when we will allow access
969 to other tables from trigger we won't be able to catch changes in other
970 tables...
971
972 Since we don't plan to access to contents of the fields it does not
973 matter that we choose for both OLD and NEW values the same versions
974 of Field objects here.
975 */
976 old_field= new_field= table->field;
977
978 if (iterate_trigger_fields_and_run_func(
979 lex->sphead->m_trg_table_fields,
980 [thd, table] (Item_trigger_field* trg_field)
981 {
982 /*
983 NOTE: now we do not check privileges at CREATE TRIGGER time.
984 This will be changed in the future.
985 */
986 trg_field->setup_field(thd, table, nullptr);
987

Callers 1

Calls 15

my_errorFunction · 0.85
sp_process_definerFunction · 0.85
is_subset_of_trg_eventsFunction · 0.85
build_table_filenameFunction · 0.85
ddl_log_create_triggerFunction · 0.85
ddl_log_delete_tmp_fileFunction · 0.85
ddl_log_update_phaseFunction · 0.85
strxnmovFunction · 0.85
push_warning_printfFunction · 0.85
build_trig_stmt_queryFunction · 0.85

Tested by

no test coverage detected