Processes statements related to a specific table just before fetching a list of rows to be inserted or updated in the specified table in the remote database.
In the following table, the description provides the SQL data type. If you are writing your script in Java or .NET, you should use the appropriate corresponding data type. See SQL-Java data types and SQL-.NET data types.
In SQL scripts, you can specify event parameters by name or with a question mark, but you cannot mix names and question marks within a script. If you use question marks, the parameters must be in the order shown below and are optional only if no subsequent parameters are specified (for example, you must use parameter 1 if you want to use parameter 2). If you use named parameters, you can specify any subset of the parameters in any order.
Parameter name for SQL scripts | Description | Order |
---|---|---|
s.last_table_download | TIMESTAMP. The last download time for the table. | 1 |
s.remote_id | VARCHAR(128). The MobiLink remote ID. You can only reference the remote ID if you are using named parameters. | Not applicable |
s.username | VARCHAR (128). The MobiLink user name. | 2 |
s.table | VARCHAR (128). The table name. | 3 |
None.
This event is executed immediately before fetching the stream of rows to be inserted or updated in the named table in the remote database.
You can have one begin_download_rows script for each table in the remote database.
You can use the begin_download_rows table event to flag rows that you no longer want to download for this table. The following example archives sales leads that are over seven days old.
The following call to a MobiLink system procedure registers the BeginDownloadRows stored procedure for the begin_download_rows event.
CALL ml_add_table_script( 'version1', 'Leads', 'begin_download_rows', 'CALL BeginDownloadRows ( {ml s.last_table_download}, {ml s.username}, {ml s.table})' ); ) |
The following SQL statement creates the BeginDowloadRows stored procedure.
CREATE PROCEDURE BeginDownloadRows ( LastDownload timestamp, MLUser varchar(128), TableName varchar(128) ) BEGIN execute immediate 'update ' || TableName || ' set download_flag = 0 where days(creation_time, CURRENT DATE) > 7 and Owner = ' || MLUser; END; |
The following call to a MobiLink system procedure registers a Java method called beginDownloadRows as the script for the begin_download_rows table event when synchronizing the script version ver1. This syntax is for SQL Anywhere consolidated databases.
CALL ml_add_java_table_script( 'ver1', 'table1', 'begin_download_rows', 'ExamplePackage.ExampleClass.beginDownloadRows' ) |
Following is the sample Java method beginDownloadRows. It generates an UPDATE statement using the table and user for MobiLink to execute.
public String beginDownloadRows( Timestamp ts, String user, String table ) { return( "update " + table + " set download_flag = 0 " + " where days(creation_time, CURRENT DATE) > 7 " + " and Owner = '" + user + "'" ); } |
The following call to a MobiLink system procedure registers a .NET method called BeginDownloadRows as the script for the begin_download_rows table event when synchronizing the script version ver1 and the table table1.
CALL ml_add_dnet_table_script( 'ver1', 'table1', 'begin_download_rows', 'TestScripts.Test.BeginDownloadRows' ) |
Following is the sample .NET method BeginDownloadRows. It generates an UPDATE statement using the table and user for MobiLink to execute.
public string BeginDownloadRows( DateTime timestamp, string user, string table ) { return( "update " + table + " set download_flag = 0 " + " where days(creation_time, CURRENT DATE) > 7 " + " and Owner = '" + user + "'" ); } |
Send feedback about this page via email or DocCommentXchange | Copyright © 2008, iAnywhere Solutions, Inc. - SQL Anywhere 11.0.0 |