public ianywhere.ml.script.DownloadTableData
封装用于 MobiLink 直接下载的表操作。使用此接口可设置将下载到客户端的数据操作。要获取当前同步的 DownloadTableData 实例,请使用 DownloadData 接口。可以分别使用 DownloadTableData.getUpsertPreparedStatement 和 getDeletePreparedStatement 方法来获取用于插入和更新操作以及删除操作的 Java 预准备语句。java.sql.PreparedStatement.executeUpdate 方法可以注册要下载的操作。
对于插入和更新预准备语句,必须设置所有列值。对于删除操作,则需设置主键值。
delete 和 upsert 预准备语句不能同时打开。
有关 java.sql.PreparedStatement 的详细信息,请参考 Java SDK 文档。
ianywhere.ml.script.DownloadTableData 的所有成员,包括所有继承的成员。
假定使用 MobiLink 客户端数据库中名为 remoteOrders 的表。
CREATE TABLE remoteOrders ( pk INT NOT NULL, col1 VARCHAR(200), PRIMARY KEY (pk) ); |
以下示例使用 DownloadData.getDownloadTableByName 方法返回表示 remoteOrders 表的 DownloadTableData 实例。
此示例假定您拥有一个名为 _cc 的 DBConnectionContext 实例。
// The method used for the handle_DownloadData event public void handleDownload() throws SQLException { // Get the DownloadData for the current synchronization. DownloadData my_dd = _cc.getDownloadData(); // Get the DownloadTableData for the remoteOrders table. DownloadTableData td = my_dd.getDownloadTableByName("remoteOrders"); // User defined-methods to set download operations. setDownloadInserts(td); setDownloadDeletes(td); // ... } |
在本例中,setDownloadInserts 方法使用 DownloadTableData.getUpsertPreparedStatement 来为想要插入或更新的行获取预准备语句。PreparedStatement.setInt 和 PreparedStatement.setString 方法会设置要插入远程数据库中的列值。
void setDownloadInserts(DownloadTableData td) { java.sql.PreparedStatement insert_ps = td.getUpsertPreparedStatement(); // The following method calls are the same as the following SQL statement: // INSERT INTO remoteOrders(pk, col1) values(2300, "truck"); insert_ps.setInt(1, 2300); insert_ps.setString(2, "truck"); int update_result = insert_ps.executeUpdate(); if (update_result == 0) { // Insert was filtered because it was uploaded // in the same synchronization. } else { // Insert was not filtered. } } |
setDownloadDeletes 方法使用 DownloadTableData.getDeletePreparedStatement 来为想要删除的行获取预准备语句。java.sql.PreparedStatement.setInt 方法用于设置要在远程数据库中删除的行的主键值,java.sql.PreparedStatement.executeUpdate 方法用于注册要下载的行值。
void setDownloadDeletes(DownloadTableData td) { java.sql.PreparedStatement delete_ps = td.getDeletePreparedStatement(); // The following method calls are the same as the following SQL statement: // DELETE FROM remoteOrders where pk=2300; delete_ps.setInt(1, 2300); delete_ps.executeUpdate(); } |
getDeletePreparedStatement 方法
getUpsertPreparedStatement 方法
getName 方法
getMetaData 方法
getLastDownloadTime 方法
Copyright © 2009, iAnywhere Solutions, Inc. - SQL Anywhere 11.0.1 |