MySQL 8.3.0
Source Code Documentation
Trigger Class Reference

This class represents a trigger object. More...

#include <trigger.h>

Public Member Functions

bool execute (THD *thd)
 Execute trigger's body. More...
 
bool parse (THD *thd, bool is_upgrade)
 Parse CREATE TRIGGER statement. More...
 
void add_tables_and_routines (THD *thd, Query_tables_list *prelocking_ctx, Table_ref *table_list)
 Add tables and routines used by trigger to the set of elements used by statement. More...
 
void print_upgrade_warning (THD *thd)
 Print upgrade warnings (if any). More...
 
const LEX_CSTRINGget_db_name () const
 
const LEX_CSTRINGget_subject_table_name () const
 
const LEX_CSTRINGget_trigger_name () const
 
const LEX_CSTRINGget_definition () const
 
const LEX_CSTRINGget_definition_utf8 () const
 
sql_mode_t get_sql_mode () const
 
const LEX_CSTRINGget_definer () const
 
const LEX_CSTRINGget_definer_user () const
 
const LEX_CSTRINGget_definer_host () const
 
const LEX_CSTRINGget_client_cs_name () const
 
const LEX_CSTRINGget_connection_cl_name () const
 
const LEX_CSTRINGget_db_cl_name () const
 
enum_trigger_event_type get_event () const
 
const LEX_CSTRINGget_event_as_string () const
 
enum_trigger_action_time_type get_action_time () const
 
const LEX_CSTRINGget_action_time_as_string () const
 
bool is_created_timestamp_null () const
 
my_timeval get_created_timestamp () const
 
ulonglong get_action_order () const
 
void set_action_order (ulonglong action_order)
 
sp_headget_sp ()
 
GRANT_INFOget_subject_table_grant ()
 
bool has_parse_error () const
 
const char * get_parse_error_message () const
 
bool create_full_trigger_definition (const THD *thd, String *full_trigger_definition) const
 Construct a full CREATE TRIGGER statement from Trigger's data members. More...
 
 ~Trigger ()
 Destroy associated SP (if any). More...
 

Static Public Member Functions

static Triggercreate_from_parser (THD *thd, TABLE *subject_table, String *binlog_create_trigger_stmt)
 Creates a new Trigger-instance with the state from the parser. More...
 
static Triggercreate_from_dd (MEM_ROOT *mem_root, const LEX_CSTRING &trigger_name, const LEX_CSTRING &db_name, const LEX_CSTRING &subject_table_name, const LEX_CSTRING &definition, const LEX_CSTRING &definition_utf8, sql_mode_t sql_mode, const LEX_CSTRING &definer_user, const LEX_CSTRING &definer_host, const LEX_CSTRING &client_cs_name, const LEX_CSTRING &connection_cl_name, const LEX_CSTRING &db_cl_name, enum_trigger_event_type trg_event_type, enum_trigger_action_time_type trg_time_type, uint action_order, my_timeval created_timestamp)
 Creates a new Trigger-instance with the state loaded from the Data Dictionary. More...
 
static bool construct_create_trigger_stmt_with_definer (THD *thd, String *binlog_query, const LEX_CSTRING &def_user, const LEX_CSTRING &def_host)
 Constructs CREATE TRIGGER statement taking into account a value of the DEFINER clause. More...
 

Private Member Functions

 Trigger (const LEX_CSTRING &trigger_name, MEM_ROOT *mem_root, const LEX_CSTRING &db_name, const LEX_CSTRING &table_name, const LEX_CSTRING &definition, const LEX_CSTRING &definition_utf8, sql_mode_t sql_mode, const LEX_CSTRING &definer_user, const LEX_CSTRING &definer_host, const LEX_CSTRING &client_cs_name, const LEX_CSTRING &connection_cl_name, const LEX_CSTRING &db_cl_name, enum_trigger_event_type event_type, enum_trigger_action_time_type action_time, uint action_order, my_timeval created_timestamp)
 Trigger constructor. More...
 
void set_trigger_name (const LEX_CSTRING &trigger_name)
 
void set_trigger_def (const LEX_CSTRING &trigger_def)
 
void set_trigger_def_utf8 (const LEX_CSTRING &trigger_def_utf8)
 
void set_parse_error_message (const char *error_message)
 

Private Attributes

MEM_ROOTm_mem_root
 Memory root to store all data of this Trigger object. More...
 
LEX_CSTRING m_full_trigger_definition
 Full trigger definition reconstructed from a data loaded from the table mysql.trigger. More...
 
LEX_CSTRING m_db_name
 Database name. More...
 
LEX_CSTRING m_subject_table_name
 Table name. More...
 
LEX_CSTRING m_definition
 Trigger definition to save in DD. More...
 
LEX_CSTRING m_definition_utf8
 Trigger definition in UTF8 to save in DD. More...
 
sql_mode_t m_sql_mode
 Trigger sql-mode. More...
 
LEX_CSTRING m_definer
 Trigger definer. More...
 
LEX_CSTRING m_definer_user
 Trigger definer (user part). More...
 
LEX_CSTRING m_definer_host
 Trigger definer (host part). More...
 
LEX_CSTRING m_client_cs_name
 Character set context, used for parsing and executing trigger. More...
 
LEX_CSTRING m_connection_cl_name
 Collation name of the connection within one a trigger are created. More...
 
LEX_CSTRING m_db_cl_name
 Default database collation. More...
 
enum_trigger_event_type m_event
 Trigger event. More...
 
enum_trigger_action_time_type m_action_time
 Trigger action time. More...
 
my_timeval m_created_timestamp
 Current time when the trigger was created (measured in milliseconds since since 0 hours, 0 minutes, 0 seconds, January 1, 1970, UTC). More...
 
ulonglong m_action_order
 Action_order value for the trigger. More...
 
LEX_CSTRING m_trigger_name
 Trigger name. More...
 
GRANT_INFO m_subject_table_grant
 Grant information for the trigger. More...
 
sp_headm_sp
 Pointer to the sp_head corresponding to the trigger. More...
 
bool m_has_parse_error
 This flags specifies whether the trigger has parse error or not. More...
 
char m_parse_error_message [MYSQL_ERRMSG_SIZE]
 This error will be displayed when the user tries to manipulate or invoke triggers on a table that has broken triggers. More...
 

Detailed Description

This class represents a trigger object.

Trigger can be created, initialized, parsed and executed.

Trigger attributes are usually stored on the memory root of the subject table. Trigger object however can exist when the subject table does not. In this case, trigger attributes are stored on a separate memory root.

Trigger objects are created in two ways:

  1. loading from Data Dictionary (by Trigger_loader)

    In this case Trigger object is initialized from the data which is directly available in data dictionary;

    See also
    Trigger::create_from_dd().
  2. creating a new Trigger object that represents the trigger object being created by CREATE TRIGGER statement (by Table_trigger_dispatcher).

    In this case Trigger object is created temporarily.

    See also
    Trigger::create_from_parser().

Constructor & Destructor Documentation

◆ Trigger()

Trigger::Trigger ( const LEX_CSTRING trigger_name,
MEM_ROOT mem_root,
const LEX_CSTRING db_name,
const LEX_CSTRING table_name,
const LEX_CSTRING definition,
const LEX_CSTRING definition_utf8,
sql_mode_t  sql_mode,
const LEX_CSTRING definer_user,
const LEX_CSTRING definer_host,
const LEX_CSTRING client_cs_name,
const LEX_CSTRING connection_cl_name,
const LEX_CSTRING db_cl_name,
enum_trigger_event_type  event_type,
enum_trigger_action_time_type  action_time,
uint  action_order,
my_timeval  created_timestamp 
)
private

Trigger constructor.

◆ ~Trigger()

Trigger::~Trigger ( )

Destroy associated SP (if any).

Member Function Documentation

◆ add_tables_and_routines()

void Trigger::add_tables_and_routines ( THD thd,
Query_tables_list prelocking_ctx,
Table_ref table_list 
)

Add tables and routines used by trigger to the set of elements used by statement.

Parameters
[in]thdthread handle
[in,out]prelocking_ctxprelocking context of the statement
[in]table_listTable_ref for the table

◆ construct_create_trigger_stmt_with_definer()

bool Trigger::construct_create_trigger_stmt_with_definer ( THD thd,
String binlog_query,
const LEX_CSTRING def_user,
const LEX_CSTRING def_host 
)
static

Constructs CREATE TRIGGER statement taking into account a value of the DEFINER clause.

The point of this method is to create canonical forms of CREATE TRIGGER statement for writing into the binlog.

Note
A statement for the binlog form must preserve FOLLOWS/PRECEDES clause if it was in the original statement. The reason for that difference is this:
  • the Data Dictionary preserves the trigger execution order (action_order), thus FOLLOWS/PRECEDES clause is not needed.
  • moreover, FOLLOWS/PRECEDES clause usually makes problem in mysqldump, because CREATE TRIGGER statement will have a reference to not-yet-existing trigger (which is about to be created right after this one).
  • thus, FOLLOWS/PRECEDES must not be stored in the Data Dictionary.
  • on the other hand, the binlog contains statements in the user order (as the user executes them). Thus, it is important to preserve FOLLOWS/PRECEDES clause if the user has specified it so that the trigger execution order on master and slave will be the same.
Parameters
thdthread context
[out]binlog_querywell-formed CREATE TRIGGER statement for putting into binlog (after successful execution)
def_useruser part of a definer value
def_hosthost part of a definer value
Returns
Operation status.
Return values
falseSuccess
trueFailure

◆ create_from_dd()

Trigger * Trigger::create_from_dd ( MEM_ROOT mem_root,
const LEX_CSTRING trigger_name,
const LEX_CSTRING db_name,
const LEX_CSTRING subject_table_name,
const LEX_CSTRING definition,
const LEX_CSTRING definition_utf8,
sql_mode_t  sql_mode,
const LEX_CSTRING definer_user,
const LEX_CSTRING definer_host,
const LEX_CSTRING client_cs_name,
const LEX_CSTRING connection_cl_name,
const LEX_CSTRING db_cl_name,
enum_trigger_event_type  trg_event_type,
enum_trigger_action_time_type  trg_time_type,
uint  action_order,
my_timeval  created_timestamp 
)
static

Creates a new Trigger-instance with the state loaded from the Data Dictionary.

Note
the Data Dictionary currently stores not all needed information, so the complete state of Trigger-object can be obtained only after parsing the definition (CREATE TRIGGER) statement. In order to do that, Trigger::parse() should be called.
See also
also Trigger::create_from_parser()
Parameters
[in]mem_rootMEM_ROOT for memory allocation.
[in]trigger_namename of trigger
[in]db_namename of schema.
[in]subject_table_namesubject table name.
[in]definitionCREATE TRIGGER statement.
[in]definition_utf8CREATE TRIGGER statement in UTF8.
[in]sql_modesql_mode value.
[in]definer_useruser part of a 'definer' value.
[in]definer_hosthost part of a 'definer' value.
[in]client_cs_nameclient character set name.
[in]connection_cl_nameconnection collation name.
[in]db_cl_namedatabase collation name.
[in]trg_event_typetrigger event type
[in]trg_time_typetrigger action timing
[in]action_orderaction order
[in]created_timestamptrigger creation time stamp.
Returns
Pointer to a new Trigger instance, NULL in case of OOM error.

◆ create_from_parser()

Trigger * Trigger::create_from_parser ( THD thd,
TABLE subject_table,
String binlog_create_trigger_stmt 
)
static

Creates a new Trigger-instance with the state from the parser.

This method is used to create a Trigger-object after CREATE TRIGGER statement is parsed.

See also
also Trigger::create_from_dd()
Parameters
thdThread context with a valid LEX-tree of CREATE TRIGGER statement
subject_tableA valid (not fake!) subject TABLE-object
[out]binlog_create_trigger_stmtStore CREATE TRIGGER appropriate to writing into the binlog. It should have DEFINER clause and should not have FOLLOWS/PRECEDES clause.
Returns
Pointer to a new Trigger instance, NULL in case of error.

◆ create_full_trigger_definition()

bool Trigger::create_full_trigger_definition ( const THD thd,
String full_trigger_definition 
) const

Construct a full CREATE TRIGGER statement from Trigger's data members.

Parameters
[in]thdThread context
[out]full_trigger_definitionPlace where a CREATE TRIGGER statement be stored.
Returns
Operation status
Return values
trueFailure
falseSuccess

◆ execute()

bool Trigger::execute ( THD thd)

Execute trigger's body.

Parameters
[in]thdThread context
Returns
Operation status
Return values
trueTrigger execution failed or trigger has compilation errors
falseSuccess

◆ get_action_order()

ulonglong Trigger::get_action_order ( ) const
inline

◆ get_action_time()

enum_trigger_action_time_type Trigger::get_action_time ( ) const
inline

◆ get_action_time_as_string()

const LEX_CSTRING & Trigger::get_action_time_as_string ( ) const

◆ get_client_cs_name()

const LEX_CSTRING & Trigger::get_client_cs_name ( ) const
inline

◆ get_connection_cl_name()

const LEX_CSTRING & Trigger::get_connection_cl_name ( ) const
inline

◆ get_created_timestamp()

my_timeval Trigger::get_created_timestamp ( ) const
inline

◆ get_db_cl_name()

const LEX_CSTRING & Trigger::get_db_cl_name ( ) const
inline

◆ get_db_name()

const LEX_CSTRING & Trigger::get_db_name ( ) const
inline

◆ get_definer()

const LEX_CSTRING & Trigger::get_definer ( ) const
inline

◆ get_definer_host()

const LEX_CSTRING & Trigger::get_definer_host ( ) const
inline

◆ get_definer_user()

const LEX_CSTRING & Trigger::get_definer_user ( ) const
inline

◆ get_definition()

const LEX_CSTRING & Trigger::get_definition ( ) const
inline

◆ get_definition_utf8()

const LEX_CSTRING & Trigger::get_definition_utf8 ( ) const
inline

◆ get_event()

enum_trigger_event_type Trigger::get_event ( ) const
inline

◆ get_event_as_string()

const LEX_CSTRING & Trigger::get_event_as_string ( ) const

◆ get_parse_error_message()

const char * Trigger::get_parse_error_message ( ) const
inline

◆ get_sp()

sp_head * Trigger::get_sp ( )
inline

◆ get_sql_mode()

sql_mode_t Trigger::get_sql_mode ( ) const
inline

◆ get_subject_table_grant()

GRANT_INFO * Trigger::get_subject_table_grant ( )
inline

◆ get_subject_table_name()

const LEX_CSTRING & Trigger::get_subject_table_name ( ) const
inline

◆ get_trigger_name()

const LEX_CSTRING & Trigger::get_trigger_name ( ) const
inline

◆ has_parse_error()

bool Trigger::has_parse_error ( ) const
inline

◆ is_created_timestamp_null()

bool Trigger::is_created_timestamp_null ( ) const
inline

◆ parse()

bool Trigger::parse ( THD thd,
bool  is_upgrade 
)

Parse CREATE TRIGGER statement.

Parameters
[in]thdThread context
[in]is_upgradeFlag to indicate that trigger being parsed is read from .TRG file in case of upgrade.
Returns
true if a fatal parse error happened (the parser failed to extract even the trigger name), false otherwise (Trigger::has_parse_error() might still return true in this case).

◆ print_upgrade_warning()

void Trigger::print_upgrade_warning ( THD thd)

Print upgrade warnings (if any).

Parameters
[in]thdThread handle.

◆ set_action_order()

void Trigger::set_action_order ( ulonglong  action_order)
inline

◆ set_parse_error_message()

void Trigger::set_parse_error_message ( const char *  error_message)
inlineprivate

◆ set_trigger_def()

void Trigger::set_trigger_def ( const LEX_CSTRING trigger_def)
inlineprivate

◆ set_trigger_def_utf8()

void Trigger::set_trigger_def_utf8 ( const LEX_CSTRING trigger_def_utf8)
inlineprivate

◆ set_trigger_name()

void Trigger::set_trigger_name ( const LEX_CSTRING trigger_name)
inlineprivate

Member Data Documentation

◆ m_action_order

ulonglong Trigger::m_action_order
private

Action_order value for the trigger.

Action_order is the ordinal position of the trigger in the list of triggers with the same EVENT_MANIPULATION, CONDITION_TIMING, and ACTION_ORIENTATION.

◆ m_action_time

enum_trigger_action_time_type Trigger::m_action_time
private

Trigger action time.

◆ m_client_cs_name

LEX_CSTRING Trigger::m_client_cs_name
private

Character set context, used for parsing and executing trigger.

◆ m_connection_cl_name

LEX_CSTRING Trigger::m_connection_cl_name
private

Collation name of the connection within one a trigger are created.

◆ m_created_timestamp

my_timeval Trigger::m_created_timestamp
private

Current time when the trigger was created (measured in milliseconds since since 0 hours, 0 minutes, 0 seconds, January 1, 1970, UTC).

This is the value of CREATED attribute.

There is special value – zero means CREATED is not set (NULL).

◆ m_db_cl_name

LEX_CSTRING Trigger::m_db_cl_name
private

Default database collation.

◆ m_db_name

LEX_CSTRING Trigger::m_db_name
private

Database name.

◆ m_definer

LEX_CSTRING Trigger::m_definer
private

Trigger definer.

◆ m_definer_host

LEX_CSTRING Trigger::m_definer_host
private

Trigger definer (host part).

◆ m_definer_user

LEX_CSTRING Trigger::m_definer_user
private

Trigger definer (user part).

◆ m_definition

LEX_CSTRING Trigger::m_definition
private

Trigger definition to save in DD.

◆ m_definition_utf8

LEX_CSTRING Trigger::m_definition_utf8
private

Trigger definition in UTF8 to save in DD.

◆ m_event

enum_trigger_event_type Trigger::m_event
private

Trigger event.

◆ m_full_trigger_definition

LEX_CSTRING Trigger::m_full_trigger_definition
private

Full trigger definition reconstructed from a data loaded from the table mysql.trigger.

◆ m_has_parse_error

bool Trigger::m_has_parse_error
private

This flags specifies whether the trigger has parse error or not.

◆ m_mem_root

MEM_ROOT* Trigger::m_mem_root
private

Memory root to store all data of this Trigger object.

This can be a pointer to the subject table memory root, or it can be a pointer to a dedicated memory root if subject table does not exist.

◆ m_parse_error_message

char Trigger::m_parse_error_message[MYSQL_ERRMSG_SIZE]
private

This error will be displayed when the user tries to manipulate or invoke triggers on a table that has broken triggers.

It will get set only once per statement and thus will contain the first parse error encountered in the trigger file.

◆ m_sp

sp_head* Trigger::m_sp
private

Pointer to the sp_head corresponding to the trigger.

◆ m_sql_mode

sql_mode_t Trigger::m_sql_mode
private

Trigger sql-mode.

◆ m_subject_table_grant

GRANT_INFO Trigger::m_subject_table_grant
private

Grant information for the trigger.

◆ m_subject_table_name

LEX_CSTRING Trigger::m_subject_table_name
private

Table name.

◆ m_trigger_name

LEX_CSTRING Trigger::m_trigger_name
private

Trigger name.


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