My Project
Public Member Functions | Static Public Member Functions | Public Attributes | Friends
Table_triggers_list Class Reference

#include <sql_trigger.h>

Inheritance diagram for Table_triggers_list:
Sql_alloc

List of all members.

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 ()
bool has_update_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)

Public Attributes

TABLEtrigger_table
GRANT_INFO subject_table_grants [TRG_EVENT_MAX][TRG_ACTION_MAX]
List< LEX_STRING > definitions_list
List< ulonglong > definition_modes_list
List< LEX_STRING > definers_list
List< LEX_STRING > client_cs_names
List< LEX_STRING > connection_cl_names
List< LEX_STRING > db_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 ?


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.
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
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
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
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
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
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
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
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
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.
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.
void Table_triggers_list::set_table ( TABLE new_table)

Adjust Table_triggers_list with new TABLE pointer.

Parameters:
new_tablenew pointer to TABLE instance

Member Data Documentation

List of sql modes for triggers

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

GRANT_INFO Table_triggers_list::subject_table_grants[TRG_EVENT_MAX][TRG_ACTION_MAX]

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

TABLE instance for which this triggers list object was created.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines