Partager via


GETNEXTMODIFIED( ) Function

Returns the record number for the next modified record in a buffered table or cursor.

GETNEXTMODIFIED(nRecordNumber [, cTableAlias | nWorkArea] [, lNoFire])

Parameters

  • nRecordNumber
    Specifies the record number after which GETNEXTMODIFIED( ) searches for the next modified record. Specify 0 for nRecordNumber to determine the first record in the table or cursor that has been modified.

  • cTableAlias
    Specifies the alias of the table or cursor for which GETNEXTMODIFIED( ) returns the number of the next modified record.

  • nWorkArea
    Specifies the work area of the table or cursor for which GETNEXTMODIFIED( ) returns the number of the next modified record.

    If you do not specify an alias or work area, GETNEXTMODIFIED( ) returns the record number for the next modified record in the currently selected table or cursor.

  • lNoFire
    Specifies that all firing of rules are suppressed.

Return Value

Numeric

Remarks

GETNEXTMODIFIED( ) returns 0 if there are no modified records after the record you specify. Because of this, if you modify only one record, to verify its modification you must first use the GO TOP command to position the cursor before the changed record. A record is considered modified if the contents of any of its fields are changed in any way (even if the original field contents are restored) or the record's deletion status is changed.

GETNEXTMODIFIED( ) can operate only on tables and cursors for which table buffering is enabled. Table buffering is enabled with CURSORSETPROP( ).

Since triggers are unaffected by GETNEXTMODIFIED( ), lNoFire suppresses only field and record rules, and the "Uniqueness of index ID is violated" error. lNoFire prevents the flushing of temporary data, such as data stored in controls or updates made to the current record, to the underlying cursor.

Example

The following code example uses the GETNEXTMODIFIED( ) Function to examine changes to records in a buffered table. Typically, changes are made through user interaction with a form. For the purposes of this example, the data is updated using the SQL UPDATE command. As preparation to demonstrate the GetNextModified method, the example code opens a table in the sample database, sets optimistic row buffering, and the updates the table.

The GetNextModified( ) function is called with 0 as the parameter to get the record number of the first record updated in the buffer. A loop processes the updated records based on the the value of MaxOrdAmt. Changes are discarded if the value of MaxOrdAmt is greater than 8500. GetNextModified( ) is called again, this time with the current record number, to get the next modified record in the buffer. If GetNextModified( ) returns 0, there are no more modified records to process and the loop ends. TableRevert(.t.) is called to discard all changes and restore the sample data to it's original state.

LOCAL lnCurRec
CLEAR
CLOSE DATABASES
OPEN DATABASE (HOME(2) + 'data\testdata')
USE Customer

* Enable table buffering.
SET MULTILOCKS ON     
=CURSORSETPROP("Buffering", 5, "customer") 

* Increase MAXORDAMT by 10% for customers in Mexico.
UPDATE Customer SET MaxOrdAmt=MaxOrdAmt * 1.1 WHERE Country = "Mexico"

* Start with the first modified record.
lnCurRec = GETNEXTMODIFIED(0)

* DO until all modified records are processed.
DO WHILE .T.

   * Move to the current modified record.
   GOTO (m.lnCurRec)

   * Process modified row here.
   ? Customer.Company, Customer.MaxOrdAmt
   IF Customer.MaxOrdAmt > 8500
      =TABLEREVERT(.F.)
   ENDIF
   ?? Customer.MaxOrdAmt

   * Get the next modified record from here.
   lnCurRec = GETNEXTMODIFIED(m.lnCurRec)

   IF m.lnCurRec = 0 && No more modified records.
      EXIT
   ENDIF

ENDDO

=TABLEREVERT(.T.)  && Restore sample data and discard all changes.

See Also

Reference

CURSORSETPROP( ) Function

CURVAL( ) Function

GETFLDSTATE( ) Function

OLDVAL( ) Function

SETFLDSTATE( ) Function

TABLEUPDATE( ) Function

TABLEREVERT( ) Function

Other Resources

Functions

Language Reference (Visual FoxPro)