datasqill enables freely definable triggers for certain functionalities. These are used to trigger specific activities in the database at certain points in time (e.g. after establishing a connection, after writing, etc.) or to enable non-standardized functionalities (e.g. Truncate Table). Multiple commands can be executed for a trigger. These are grouped in statement sets. Triggers can be defined at different levels:
Each table contains the ID of the referenced object (connection type, connection or transformation), as well as the trigger name trigger_name and the statement set name statement_set_name.
Trigger definitions per transformation override triggers per connection.
Trigger definitions per connection override triggers per connection type.
Triggers from a previous hierarchy can be deleted by specifying empty triggers (statement_set_name empty or NULL).
Each module defines in the entity vv_datasqill_module_trigger which triggers it can execute.
In addition to the triggers that are to be triggered before or after an event, "Instead of Triggers" can also be defined. These are executed when a certain functionality is required. Currently only the Instead of Truncate trigger is used. This is called when a complete table is to be cleared. If the trigger is not present, the table is completely cleared with the SQL DELETE command.
Trigger definitions per connection or connection type are saved with "Export of Connections" in the GUI and transferred to the datasqill target environment during deployment.
Trigger definitions per action are saved with the respective worksheet (Sheet) and transferred to the datasqill target environment during deployment of the sheet.
A statement set contains one or more individual commands that are executed in the database. It is stored in the repository in the entity vv_datasqill_statement_set. The combination of the name statement_set_name and the order sorting results in the complete set that can be executed for a trigger.
For the execution of the statement command, 3 different methods method can be selected. In the ignore_errors column, it is specified per executing command whether occurring errors should be ignored.
The specified command statement is executed as a Java Statement with the executeUpdate method.
The specified command statement is executed as a Java CallableStatement with the execute method. A call corresponding to the database must be used. Many databases support the escape syntax:
{call procedure_xy()}
Otherwise, the native procedure of the target database must be used.
The specified command statement is a Select statement. For each row returned from this statement, an entry is inserted in sqts_request_result. This method is used to obtain statistical information about the database or the executed commands. The following column names from the Select statement must be used:
The following variables can be used in the specified commands:
datasqill uses Freemarker for variable substitution. Freemarker is configured such that symbols are specified in square brackets rather than angle brackets. Variables are specified in curly brackets with a leading dollar sign.
Examples of commands:
Truncate a table for Postgres
TRUNCATE TABLE ONLY ${target} RESTART IDENTITY
Vacuum a table for Postgres
BEGIN; END WORK; VACUUM ANALYSE ${target}; END
Call a grant function with read rights for each source database object (sqtsObjectTypeId=1) in an Oracle database and a grant function with write rights for the target table
BEGIN
[#list sources as src][#if "${src.sqtsObjectTypeId}" == "1" && "${src.serverId}" == "${connection_id}"]
dsrt_grant_object('${src.objectOwner}', '${src.objectName}', 'SELECT');[/#if][/#list][#if target_table?has_content && "${target_connection_id}" == "${connection_id}"]
dsrt_grant_object('${target_schema}', '${target_table}', 'SELECT,INSERT,UPDATE,DELETE');[#else]NULL;[/#if]
END;
Reading the statistics of the used temp space and the unique session number for Oracle (Method select statistics)
SELECT 'tempspace' stat_name
, MAX(ses_hist.temp_space_allocated) stat_value_numeric
, NULL stat_value_character
FROM (SELECT NVL(qc_session_id, session_id) session_id
, NVL(qc_session_serial#, session_serial#) session_serial#
, sample_id
, SUM(temp_space_allocated) temp_space_allocated
FROM v$active_session_history
GROUP BY NVL(qc_session_id, session_id)
, NVL(qc_session_serial#, session_serial#)
, sample_id
) ses_hist
, v$session ses
WHERE ses.sid = ses_hist.session_id(+)
AND ses.serial# = ses_hist.session_serial#(+)
AND ses.audsid = SYS_CONTEXT('USERENV', 'SESSIONID')
UNION ALL
SELECT 'session_id' stat_name
, TO_NUMBER(SYS_CONTEXT('USERENV', 'SESSIONID')) stat_value_numeric
, NULL stat_value_character
FROM dual
Reading the unique session number for Exasol (Method select statistics)
SELECT 'session_id' stat_name
, CURRENT_SESSION stat_value_numeric
, NULL stat_value_character
Logging of the statistic in sqts_request_result must be enabled for this
INSERT INTO vv_sqts_result_type(result_type_id, result_type_name, result_type_desc, data_type, log_enabled)
SELECT NVL(result_type_id, max_result_type_id + 1) result_type_id
, 'session_id' result_type_name
, 'Database Session or Transaction ID' result_type_desc
, 'N' data_type
, 'Y' log_enabled
FROM (SELECT COUNT(*) cnt
, MAX(result_type_id) result_type_id
FROM vv_sqts_result_type
WHERE result_type_name = 'session_id'
)
, (SELECT MAX(result_type_id) max_result_type_id
FROM vd_sqts_result_type
WHERE result_type_id < 1000
)