12.6.1.4.3. StatementData Objects

The StatementData class contains information about data that has been replicated as an SQL statement, as opposed to information that is replicated as row-based data.

Processing and filtering statement information relies on editing the original SQL query statement, or the metadata recorded with it in the THL, such as the schema name or character set. Care should be taken when modifying SQL statement data to ensure that you are modifying the right part of the original statement. For example, a search and replace on an SQL statement should be made with care to ensure that embedded data is not altered by the process.

The key methods used for interacting with a StatementData object are listed below:

Method Description
getQuery() Returns the SQL statement
setQuery() Updates the SQL statement
appendToQuery() Appends a string to an existing query
getDefaultSchema() Returns the default schema in which the statement was executed. The schema may be null for explicit or multi-schema queries.
setDefaultSchema() Set the default schema for the SQL statement
getTimestamp() Gets the timestamp of the query. This is required if data must be applied with a relative value by combining the timestamp with the relative value

Updating the SQL

The primary method of processing statement based data is to load and identify the original SQL statement (using getQuery(), update or modify the SQL statement string, and then update the statement within the THL again using setQuery(). For example:

sqlOriginal = d.getQuery();
sqlNew = sqlOriginal.replaceAll('NOTEPAD','notepad');
d.setQuery(sqlNew);

The above replaces the uppercase 'NOTEPAD' with a lowercase version in the query before updating the stored query in the object.

Changing the Schema Name

Some schema and other information is also provided in this structure. For example, the schema name is provided within the statement data and can be explicitly updated. In the example below, the schema products is updated to nyc_products:

if (change.getDefaultSchema().compareTo("products") == 0)
{
  change.setDefaultSchema("nyc_products");
}

A similar operation should be performed for any row-based changes. A more complete example can be found in Section 12.4.8, “dbrename.js Filter”.