Condividi tramite


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.

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

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

Parameters

  • lAllRows
    Determines whether all changes made to the table or cursor are discarded. The following table describes the values for lAllRows.

    lAllRows Description
    False (.F.) If table buffering is enabled, only changes made to the current record in the table or cursor are discarded. (Default)
    True (.T.) If table buffering is enabled, changes made to all records are discarded in the table or cursor.

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

  • 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.

Return Values

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

Remarks

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.

TABLEREVERT( ) operates on CursorAdapter objects in the same way as other buffered cursors.

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( )