MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Table_triggers_list Class Reference

#include <sql_trigger.h>

Inheritance diagram for Table_triggers_list:
Collaboration diagram for Table_triggers_list:

Public Member Functions

 Table_triggers_list (TABLE *table_arg)
bool create_trigger (THD *thd, TABLE_LIST *table, String *stmt_query)
bool drop_trigger (THD *thd, TABLE_LIST *table, String *stmt_query)
bool process_triggers (THD *thd, trg_event_type event, trg_action_time_type time_type, bool old_row_is_record1)
bool get_trigger_info (THD *thd, trg_event_type event, trg_action_time_type time_type, LEX_STRING *trigger_name, LEX_STRING *trigger_stmt, sql_mode_t *sql_mode, LEX_STRING *definer, LEX_STRING *client_cs_name, LEX_STRING *connection_cl_name, LEX_STRING *db_cl_name)
void get_trigger_info (THD *thd, int trigger_idx, LEX_STRING *trigger_name, sql_mode_t *sql_mode, LEX_STRING *sql_original_stmt, LEX_STRING *client_cs_name, LEX_STRING *connection_cl_name, LEX_STRING *db_cl_name)
int find_trigger_by_name (const LEX_STRING *trigger_name)
bool has_triggers (trg_event_type event_type, trg_action_time_type action_time)
bool has_delete_triggers ()
void set_table (TABLE *new_table)
void mark_fields_used (trg_event_type event)
void set_parse_error_message (char *error_message)
bool add_tables_and_routines_for_triggers (THD *thd, Query_tables_list *prelocking_ctx, TABLE_LIST *table_list)
bool is_fields_updated_in_trigger (MY_BITMAP *used_fields, trg_event_type event_type, trg_action_time_type action_time)

Static Public Member Functions

static bool check_n_load (THD *thd, const char *db, const char *table_name, TABLE *table, bool names_only)
static bool drop_all_triggers (THD *thd, char *db, char *table_name)
static bool change_table_name (THD *thd, const char *db, const char *old_alias, const char *old_table, const char *new_db, const char *new_table)
- Static Public Member Functions inherited from Sql_alloc
static void * operator new (size_t size) throw ()
static void * operator new[] (size_t size) throw ()
static void * operator new[] (size_t size, MEM_ROOT *mem_root) throw ()
static void * operator new (size_t size, MEM_ROOT *mem_root) throw ()
static void operator delete (void *ptr, size_t size)
static void operator delete (void *ptr, MEM_ROOT *mem_root)
static void operator delete[] (void *ptr, MEM_ROOT *mem_root)
static void operator delete[] (void *ptr, size_t size)

Public Attributes

TABLEtrigger_table
GRANT_INFO subject_table_grants [TRG_EVENT_MAX][TRG_ACTION_MAX]
List< LEX_STRINGdefinitions_list
List< ulonglong > definition_modes_list
List< LEX_STRINGdefiners_list
List< LEX_STRINGclient_cs_names
List< LEX_STRINGconnection_cl_names
List< LEX_STRINGdb_cl_names

Friends

class Item_trigger_field

Detailed Description

This class holds all information about triggers of table.

QQ: Will it be merged into TABLE in the future ?

Definition at line 59 of file sql_trigger.h.

Member Function Documentation

bool Table_triggers_list::add_tables_and_routines_for_triggers ( THD *  thd,
Query_tables_list *  prelocking_ctx,
TABLE_LIST table_list 
)

Add triggers for table to the set of routines used by statement. Add tables used by them to statement table list. Do the same for routines used by triggers.

Parameters
thdThread context.
prelocking_ctxPrelocking context of the statement.
table_listTable list element for table with trigger.
Return values
FALSESuccess.
TRUEFailure.

Definition at line 2183 of file sql_trigger.cc.

Here is the call graph for this function:

bool Table_triggers_list::change_table_name ( THD *  thd,
const char *  db,
const char *  old_alias,
const char *  old_table,
const char *  new_db,
const char *  new_table 
)
static

Update .TRG and .TRN files after renaming triggers' subject table.

Parameters
[in,out]thdThread context
[in]dbOld database of subject table
[in]old_aliasOld alias of subject table
[in]old_tableOld name of subject table
[in]new_dbNew database for subject table
[in]new_tableNew name of subject table
Note
This method tries to leave trigger related files in consistent state, i.e. it either will complete successfully, or will fail leaving files in their initial state. Also this method assumes that subject table is not renamed to itself. This method needs to be called under an exclusive table metadata lock.
Return values
FALSESuccess
TRUEError

Definition at line 1998 of file sql_trigger.cc.

Here is the call graph for this function:

bool Table_triggers_list::check_n_load ( THD *  thd,
const char *  db,
const char *  table_name,
TABLE table,
bool  names_only 
)
static

Check whenever .TRG file for table exist and load all triggers it contains.

Parameters
thdcurrent thread context
dbtable's database name
table_nametable's name
tablepointer to table object
names_onlystop after loading trigger names
Todo:
A lot of things to do here e.g. how about other funcs and being more paranoical ?
Todo:
This could be avoided if there is no triggers for UPDATE and DELETE.
Return values
Falsesuccess
Trueerror

Definition at line 1156 of file sql_trigger.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

bool Table_triggers_list::create_trigger ( THD *  thd,
TABLE_LIST tables,
String stmt_query 
)

Create trigger for table.

Parameters
thdcurrent thread context (including trigger definition in LEX)
tablestable list containing one open table for which the trigger is created.
[out]stmt_queryafter successful return, this string contains well-formed statement for creation this trigger.
Note
  • Assumes that trigger name is fully qualified.
  • NULL-string means the following LEX_STRING instance: { str = 0; length = 0 }.
  • In other words, definer_user and definer_host should contain simultaneously NULL-strings (non-SUID/old trigger) or valid strings (SUID/new trigger).
Return values
Falsesuccess
Trueerror

Definition at line 628 of file sql_trigger.cc.

Here is the call graph for this function:

bool Table_triggers_list::drop_all_triggers ( THD *  thd,
char *  db,
char *  name 
)
static

Drop all triggers for table.

Parameters
thdcurrent thread context
dbschema for table
namename for table
Return values
Falsesuccess
Trueerror

Definition at line 1783 of file sql_trigger.cc.

Here is the call graph for this function:

bool Table_triggers_list::drop_trigger ( THD *  thd,
TABLE_LIST tables,
String stmt_query 
)

Drop trigger for table.

Parameters
thdcurrent thread context (including trigger definition in LEX)
tablestable list containing one open table for which trigger is dropped.
[out]stmt_queryafter successful return, this string contains well-formed statement for creation this trigger.
Todo:
Probably instead of removing .TRG file we should move to archive directory but this should be done as part of parse_file.cc functionality (because we will need it elsewhere).
Return values
Falsesuccess
Trueerror

Definition at line 999 of file sql_trigger.cc.

bool Table_triggers_list::get_trigger_info ( THD *  thd,
trg_event_type  event,
trg_action_time_type  time_type,
LEX_STRING trigger_name,
LEX_STRING trigger_stmt,
sql_mode_t *  sql_mode,
LEX_STRING definer,
LEX_STRING client_cs_name,
LEX_STRING connection_cl_name,
LEX_STRING db_cl_name 
)

Obtains and returns trigger metadata.

Parameters
thdcurrent thread context
eventtrigger event type
time_typetrigger action time
trigger_namereturns name of trigger
trigger_stmtreturns statement of trigger
sql_modereturns sql_mode of trigger
definerreturns definer/creator of trigger. The caller is responsible to allocate enough space for storing definer information.
Return values
Falsesuccess
Trueerror

Definition at line 1610 of file sql_trigger.cc.

bool Table_triggers_list::is_fields_updated_in_trigger ( MY_BITMAP used_fields,
trg_event_type  event_type,
trg_action_time_type  action_time 
)

Check if any of the marked fields are used in the trigger.

Parameters
used_fieldsBitmap over fields to check
event_typeType of event triggers for which we are going to inspect
action_timeType of trigger action time we are going to inspect

Definition at line 2231 of file sql_trigger.cc.

void Table_triggers_list::mark_fields_used ( trg_event_type  event)

Mark fields of subject table which we read/set in its triggers as such.

This method marks fields of subject table which are read/set in its triggers as such (by properly updating TABLE::read_set/write_set) and thus informs handler that values for these fields should be retrieved/stored during execution of statement.

Parameters
eventType of event triggers for which we are going to inspect

Definition at line 2266 of file sql_trigger.cc.

Here is the call graph for this function:

bool Table_triggers_list::process_triggers ( THD *  thd,
trg_event_type  event,
trg_action_time_type  time_type,
bool  old_row_is_record1 
)

Execute trigger for given (event, time) pair.

The operation executes trigger for the specified event (insert, update, delete) and time (after, before) if it is set.

Parameters
thd
event
time_type
old_row_is_record1
Returns
Error status.
Return values
FALSEon success.
TRUEon error.

Definition at line 2113 of file sql_trigger.cc.

Here is the call graph for this function:

void Table_triggers_list::set_parse_error_message ( char *  error_message)

Signals to the Table_triggers_list that a parse error has occured when reading a trigger from file. This makes the Table_triggers_list enter an error state flagged by m_has_unparseable_trigger == true. The error message will be used whenever a statement invoking or manipulating triggers is issued against the Table_triggers_list's table.

Parameters
error_messageThe error message thrown by the parser.

Definition at line 2303 of file sql_trigger.cc.

Here is the caller graph for this function:

void Table_triggers_list::set_table ( TABLE new_table)

Adjust Table_triggers_list with new TABLE pointer.

Parameters
new_tablenew pointer to TABLE instance

Definition at line 1123 of file sql_trigger.cc.

Member Data Documentation

List<ulonglong> Table_triggers_list::definition_modes_list

List of sql modes for triggers

Definition at line 135 of file sql_trigger.h.

List<LEX_STRING> Table_triggers_list::definitions_list

Field responsible for storing triggers definitions in file. It have to be public because we are using it directly from parser.

Definition at line 130 of file sql_trigger.h.

GRANT_INFO Table_triggers_list::subject_table_grants[TRG_EVENT_MAX][TRG_ACTION_MAX]

Grant information for each trigger (pair: subject table, trigger definer).

Definition at line 101 of file sql_trigger.h.

TABLE* Table_triggers_list::trigger_table

TABLE instance for which this triggers list object was created.

Definition at line 81 of file sql_trigger.h.


The documentation for this class was generated from the following files: