Skip to main content
Common Reference

foreignkeychecks.js Filter

The foreignkeychecks filter switches off foreign key checks for statements using the following statements:

CREATE TABLE
DROP TABLE
ALTER TABLE
RENAME TABLE
Pre-configured filter nameforeignkeychecks
JavaScript Filter Filetungsten-replicator/support/filters-javascript/foreignkeychecks.js
Property prefixreplicator.filter.foreignkeychecks
Stage compatibilitybinlog-to-q, q-to-dbms
tpm Option compatibilitysvc-extractor-filters, svc-applier-filters
Data compatibilityAny event

The process checks the statement data and parses the content of the SQL statement by first trimming any extraneous space, and then converting the statement to upper case:

upCaseQuery = d.getQuery().trim().toUpperCase();

Then comparing the string for the corresponding statement types:

if(upCaseQuery.startsWith("CREATE TABLE") ||
upCaseQuery.startsWith("DROP TABLE") ||
upCaseQuery.startsWith("ALTER TABLE") ||
upCaseQuery.startsWith("RENAME TABLE"))
{

If they match, a new statement is inserted into the event that disables foreign key checks:

query = "SET foreign_key_checks=0";
newStatement = new com.continuent.tungsten.replicator.dbms.StatementData(
d.getDefaultSchema(),
null,
query
);
data.add(0, newStatement);
i++;

The use of 0 in the add() method inserts the new statement before the others within the current event.