ClearDeletesChanges method: Rowset class

Syntax

ClearDeletesChanges()

Description

Use the ClearDeletesChanges method to clear deleted rows and changed from a standalone rowset.

Note:

This method works only with standalone rowsets, that is, rowsets created using the CreateRowset function.

This method differs from Flush in a number of ways:

  • it does not remove all rows from the rowset, only deleted rows

  • it only applies to standalone rowsets

This method first clears the deleted rows, that is, all rows that have been deleted using DeleteRow are removed from the rowset and their associated buffers are freed.

This method then clears changed rows. That means any changes done on a row (such as field values changed) or newly inserted rows are now propagated into their original state and the changed buffers, if any, are freed.

After executing this method on a standalone rowset, any row that was previously new or changed no longer has that state. The IsNew and IsChanged properties of a row return false.

This method does not do any database updates.

How would you use this method? Suppose you use a standalone rowset to track changes you need to make to some business process or object. After doing the appropriate database updates to reflect changes recorded in the rowset (that is, inserts or deletes or changes), you call this method to clean up the rowset in preparation for further processing. Without this method, newly inserted rows and changed rows preserve their IsNew and IsChanged status indefinitely, complicating program logic and potentially leading to duplicate inserts or deletes.

Parameters

None.

Returns

None.

Example

REM +--------------------------------------------------+;
REM | Function to Update the DB for a Standalone Rowset|;
REM +--------------------------------------------------+;
Function ProcessDatabaseUpdateforRowset(&rsIn As Rowset)

   For &i = 1 To &rsIn.RowCount

      &rwTMP = &rsIn.GetRow(&i);
      If &rwIn.IsDeleted And
            Not &rwIn.IsNew Then
         &rTMP = &rwIn.GetRecord(1);
         &rTMP.Delete();
      End-If;

      If &rwTMP.IsNew And
            &rwTMP.IsChanged And
            Not &rwTMP.IsDeleted Then

         &rTMP = &rwTMP.GetRecord(1);
         &rTMP.Insert()
      End-If;

      If Not &rwTMP.IsNew And
            &rwTMP.IsChanged And
            Not &rwTMP.IsDeleted Then

         &rTMP = &rwTMP.GetRecord(1);
         &rTMP.Update();
      End-If;

   End-For;

   REM +-----------------------------------------------+;
   REM | Now we need to reset the Rowset flags and     |;
   REM | remove deleted rows                           |;
   REM +-----------------------------------------------+;
   &rsIn.ClearDeletesChanges();

End-Function;