|Product:||Syniti Data Replication, DBMoto|
|Summary:||VB.NET script example of a filter to truncate tables on certain conditions|
Refresh replications initially remove all values in the target table before starting replication. In cases where you do not want the values removed at all, you can use the Refresh_onBeforeTruncate event and set CancelTruncate to true. In cases where you want deletion to occur under specific conditions, you can use the Refresh_onBeforeTruncate event, set CancelTruncate to true and then specify the SQL operations to perform.
The script below defines the Refresh_onBeforeTruncate event, sets CancelTruncate to true, then creates a connection to perform a SQL operation which deletes only certain records from the target table.
Note that if you attempt to perform a refresh operation which includes inserting records which have not been truncated, the replication will generate errors.
Public Class ReplicationScript : Inherits IReplicationScript
Public Overrides Sub Refresh_onBeforeTruncate(ByRef CancelTruncate As System.Boolean, ByRef Filter As System.String)
CancelTruncate = True
Dim delcmd As IDbCommand = TargetConnection.CreateCommand
delcmd.CommandText = "delete from emplo where hire_date > #01/01/1993 00:00:000#"