Database Trigger Library



( ZN >= 4.0.1-EIP )

Triggers are usually used when more than one query is requested to run at the same time. You may have information about using TRIGGER from SQL sources . This section describes how triggers are implemented with the ZN Framework.

 

 

# Methods


this when ( String $ type )
this event ( String $ type )
this order ( String $ type , String $ name )
this body ( String ... $ args )
Bool create ( String $ name )
Bool drop ( String $ name )
Array list ( String $ name = NULL )
Bool exists ( String $ name )

 

 

# When ( ZN> = 4.0.1-EIP )


Used to specify BEFORE and AFTER condition in the  query .

Parameters
String $ Type Kind.
Options BEFORE , AFTER
return this
Use of
DBTrigger::when('BEFORE')->...

 

 

# Event ( ZN >= 4.0.1-EIP )


Used to specify the INSERT , UPDATE , or DELETE status in the query .

Parameters
String $ Type Kind.
Options INSERT , UPDATE , DELETE
return this
Use of
DBTrigger::event('DELETE')->...

 

 

# Order ( ZN> = 4.0.1-EIP )


In the query FOLLOWS is used to specify the PRECEDES state.

Parameters
String $ Type Kind.
Options FOLLOWS , PRECEDES
String $ name Another trigger name.
return this
Use of
DBTrigger::order('FOLLOWS', ''otherTriggerName)->...

 

 

# Body ( ZN >= 4.0.1-EIP )


In the query BEGIN ... END allows you to enter commands to be written into the block.

Parameters
String ... $ queries Queries.
return this
Use of
DBTrigger::body('INSERT ...', 'UPDATE ...')->...

 

 

# CreateTrigger ( ZN >= 4.0.1-EIP ) / Create ( ZN >= 4.2.8 )


Used to create triggers.

Parameters
String $ name Trigger name.
return this
Use of
DBTrigger::table('exampleTable')
         ->when('before')
         ->event('insert')
         ->body('INSERT ... QUERY', 'UPDATE ... QUERY')
         ->create('exampleTrigger');
CREATE TRIGGER exampleTrigger before insert ON exampleTable
FOR EACH ROW
BEGIN INSERT ... QUERY; UPDATE ... QUERY;
END ;

 

 

# DropTrigger ( ZN >= 4.0.1-EIP ) / Drop ( ZN >= 4.2.8 )


Used to remove the trigger.

Parameters
String $ name Trigger name.
return this
Use of
DBTrigger::drop('exampleTrigger');
DROP TRIGGER exampleTrigger

 

 

# List ( ZN >= 4.3.4 )


Gives the current trigger list.

Parameters
String $ name = NULL If no trigger name is specified, all triggers are listed.
return this
Use of
output(DBTrigger::list('exampleTrigger'));
TRIGGER_CATALOG => string 'def' (length = 5 )
TRIGGER_SCH but => string 'test' (length = 6 )
TRIGGER_NAME => string 'exampletrigg's (length = 16 )
EVENT_MANIPULATIO of => string ' INSERT ' (length = 8 )
EVENT_OBJECT_CATALOG = > string 'def' (length = 5 )
EVENT_OBJECT_SCHEMA => string 'test' (length = 6 )
EVENT_OBJECT_TABLE => string 'users' (length = 7 )
ACTION_ORDER => string ' 0 ' (length = 3 )
ACTION_CONDITION => NULL (length = 0 )
ACTION_STATEMENT => string ' BEGIN INSERT INTO users (username) VALUES (' 1'); END ' (length = 55 )
ACTION_ORIENTATION => String " ROW " (length = 5 )
ACTION_TIMING => string ' BEFORE ' (length = 8 )
ACTION_REFERENCE_OLD_TABL A => NULL (length = 0 )
ACTION_REFERENCE_NEW_TABL A => NULL (length = 0 )
ACTION_REFERENCE_OLD_ROW => string 'OLD' (length = 5 )
ACTION_REFERENCE_NEW_ROW => string 'NEW' (length= 5 )
CREATED => NULL (length = 0 )
in SQL_MO => string 'NO_AUTO_CREATE_US is, NO_ENGINE_SUBSTITUTIO the' (length = 44 )
DEFINER => string 'root @ localhost' (length = 16 )
character_set_client => string 'UTF-8' (length = 6 )
COLLATION_CONNECTION => string 'utf8_general_ci' (length = 17 )
DATABASE_COLLATION => string 'utf8_general_ci' (length = 17 )

 

 

# Exists ( ZN >= 4.3.4 )


Checks for triggers.

Parameters
String $ name = NULL Trigger name.
return this
Use of
output(DBTrigger::exists('exampleTrigger'));
one