开发者

Add a last-updated timestamp to a FoxPro table

I'm synchronizing data between FoxPro and a remote SQL Server. Everything is working great, but on the FoxPro side, it would be much faster if I could detect records that don't need to be considered for sync. I calculate a hash off values to compare against the last-known hash, so with loaded records it's easy enough. What I would like to do 开发者_JAVA技巧is filter out records prior to even loading them by checking an updated column against the start time of the last sync.

How do I add an updated column to a VFP 9 table that gets filled in with the current date and time whenever a change is made to the row?


Assuming the table is in a VFP database (that is, is not a free table), add a datetime column to the table and set up a table rule to populate the field. Assuming you have VFP available, you can do this in the Table Designer or with code.

ALTER TABLE YourTable ADD tUpdated T
ALTER TABLE YourTable SET CHECK YourFunction()

As the syntax indicates, you need to define a function (or a stored procedure in the VFP database) to actually run when the rule fires. You want it to return true. The code in the function can be as simple as:

REPLACE tUpdated WITH DATETIME()
RETURN .T.

Tamar

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜