Partager via


TABLEREVERT( ) Function

Discards changes made to a buffered row or a buffered table or cursor and restores the OLDVAL( ) data for remote cursors and the current disk values for local tables and cursors.

TABLEREVERT([lAllRows [, cTableAlias | nWorkArea]])

Return Values

Numeric

Parameters

  • lAllRows
    Determines whether all changes made to the table or cursor are discarded. If lAllRows is true (.T.) and table buffering is enabled, changes made to all records are discarded in the table or cursor. If lAllRows is false (.F.) and table buffering is enabled, only changes made to the current record in the table or cursor are discarded.

    If row buffering is enabled, the value of lAllRows is ignored and the changes made to the current record in the table or cursor are discarded.

    The default value for lAllRows is false (.F.).

  • cTableAlias
    Specifies the alias of the table or cursor in which the changes are discarded.

  • nWorkArea
    Specifies the work area of the table or cursor in which the changes are discarded.

Remarks

TABLEREVERT( ) returns the number of records for which changes were discarded.

Note   On a network, the data currently on disk may differ from the data on disk when the table was opened or the cursor was created. Other users on the network may have changed the data after the table was opened or the cursor was created.

TABLEREVERT( ) cannot discard changes made to a table or cursor that does not have row or table buffering enabled. If you issue TABLEREVERT( ) and row or table buffering is not enabled, Visual FoxPro generates an error message. Use CURSORSETPROP( ) to enable or disable row and table buffering.

Changes are discarded in the table or cursor open in the currently selected work area if TABLEREVERT( ) is issued without the optional cTableAlias or nWorkArea arguments.

TABLEREVERT( ) does not return the record pointer to its original position.

Example

The following example demonstrates how you can use TABLEREVERT( ) to discard changes made to a buffered table. MULTILOCKS is set to ON, a requirement for table buffering. The customer table in the testdata database is opened, and CURSORSETPROP( ) is then used to set the buffering mode to optimistic table buffering (5).

The value of the cust_id field is displayed and then the cust_id field is modified with REPLACE. The new value of the cust_id field is displayed. TABLEREVERT( ) is then used to return the table to its original state (TABLEUPDATE( ) could be issued instead to commit the changes). The reverted value of the cust_id field is then displayed.

CLOSE DATABASES
SET MULTILOCKS ON  && Must be on for table buffering
SET PATH TO (HOME(2) + 'data\')     && Sets path to database
OPEN DATABASE testdata  && Open testdata database
USE Customer     && Open customer table
= CURSORSETPROP('Buffering', 5, 'customer')  && Enable table buffering

CLEAR
? 'Original cust_id value: '
?? cust_id  && Displays current cust_id value
REPLACE cust_id    WITH '***'  && Changes field contents
? 'New cust_id value: '
?? cust_id  && Displays new cust_id value
= TABLEREVERT(.T.)  && Discard all table changes
? 'Reverted cust_id value: '
?? cust_id  && Displays reverted cust_id value

See Also

CURSORSETPROP( ) | CURVAL( ) | OLDVAL( ) | TABLEUPDATE( )