Determining Updates in Visual FoxPro (VFP)

The update status of each field can be determined with the GETFLDSTATE( fieldname ) function that returns the status of each field in the current record of a buffered cursor:

1 - No Changes.
2 - Field Updated.
3 - Field Added in a new record but not modified.
4 - Field Modified in a new record.

The GETFLDSTATE(-1) function is used to return the update status of the current record where buffering has been enabled. The first character of the returned value indicates the delete status of the current record and the remaining characters indicate individual field status.

If the returned string contains only the character 1 then no changes have been made to the current record. 2,3, or 4 indicates that a change has been made or the record added or deleted. The following expression will check for changes to the current record in the current buffered cursor:

LOCAL m.lc_getfld
m.lc_getfld = GETFLDSTATE(-1)
IF '2' $ m.lc_getfld ;
   OR '3' $ m.lc_getfld ;
   OR '4' $ m.lc_getfld
   * Changes have been made

The SETFLDSTATE() function  can be used to alter these settings.

Only one record at a time is updated with Record Level Buffering. Several records are changed on the local workstation cursor with table level buffering and in some cases it is useful to determine which records have been changed before updating.

The GETNEXTMODIFIED function returns the next record number of the cursor that has been modified on the workstation and not updated onto the server. The function requires a parameter to indicate the record number to search from:

? GETNEXTMODIFIED(0) will return the first record that has been modified. If record 5 is returned, the record number of the next modified record is obtained with the following command:


Records appended with table buffering have negative record numbers.
Additional functions exist to help resolve update difficulties. The record pointer must be positioned on the required record for these functions to work.

The current value in the local workstation cursor is determined by using the alias and field name in the normal way. For the STORE_ID field in the SALESVIEW cursor for example:

m.lc_Local = salesview.store_id

The original value determined when the snapshot of the original data was copied onto the workstation is determined by a function called OLDVAL(). 

m.lc_Snapshot = OLDVAL( 'store_id' )

The current value on the server will be the same as the OLDVAL() unless the server data has been changed by another user since the snapshot of the cursor data was taken. It can be determined with the CURVAL() function:

m.lc_Server = CURVAL('store_id')

These three functions may be used in combination to check which fields have been changed by the current user or another user and then use application logic to set values that are acceptable to the server.

Tidak ada komentar:

Posting Komentar