Partager via


Updating Data in the Client/Server Sample Application

When you edit data in the table and the buffering is No Buffering (CURSORSETPROP("Buffering", 1)), the changes are made directly to the table data. You cannot choose Update or Revert.

When you choose any other buffering option, you have the option to update or revert changes made to the data.

When you are updating buffered data, locally or remotely, use the TABLEUPDATE( ) function. The arguments in this function make it possible for you to determine the update scope and whether or not to force updates. For example, the following lines of code are executed in the Click event of the Update button in the SampleApp form:

lnUpdateType = THIS.Parent.opgUpdate.Value - 1
llForce = THIS.Parent.chkForce.Value
llUpdate = TABLEUPDATE(lnUpdateType, llForce)

The lnUpdateType value is determined by the option button chosen in the Update Scope area.

There are three options for the update scope.

Row Update

When the first argument in the TABLEUPDATE( ) function is 0, only the current row is updated, regardless of whether table or row buffering is enabled. Changes made in any other rows are not written to the data source.

Table Update

When the first argument in the TABLEUPDATE( ) function is 1, the rows in the table that have been changed are updated, beginning with the first updated row. If a data conflict is encountered, that is, if the CURVAL( ) for a field in the row is different from the OLDVAL( ) for that field, table updating is stopped on the row that generated the conflict.

Table Update All

When the first argument in the TABLEUPDATE( ) function is 2, the rows in the table that have been changed are updated, beginning with the first updated row. All rows without a data conflict are updated.

Other options are specified in the Update Options area.

Forcing Updates

The second argument in the TABLEUPDATE( ) function specifies whether or not to force updates. If you choose Force in the Update Options area, the second argument in the TABLEUPDATE( ) function is True (.T.) and your changes will automatically override any changes that might have been made to the data after you began editing. There cannot be any conflicts to resolve if you force updates.

Note   If the user has changed the primary key of a record, the row cannot be updated and is deleted in you local cursor.

Resolving Conflicts

If Resolve Conflicts is selected, the Client/Server sample application finds conflicts when they occur and makes it possible for you to see the conflicting data and decide to override the existing changes or discard your own changes. If Resolve Conflicts is not selected, your data will not be updated if a conflict is detected:

IF THIS.parent.chkConflicts.Value
   THISFORM.ResolveConflicts
ELSE
   WAIT WINDOW 'Update failed' NOWAIT TIMEOUT 5
ENDIF

For more information about resolving conflicts, see Managing Data Conflicts in the Client/Server Sample Application later in this section.

Business Rules

If Business Rules is selected, the Client/Server sample application enforces the business rules established for this application. For information about the Business Rules option, see Implementing Business Rules in the Client/Server Sample Application later in this section.

Upsizing the Employee Table

The code for upsizing the database is associated with the Click event of cmdUpsize in the Client/Server Application form. The code performs these actions:

  1. Connects to the backend data source.
  2. Drops the table if it already exists.
  3. Creates a character string that includes the SQL CREATE TABLE command.
  4. Executes the SQL command by calling SQLEXEC( ) with the character string as an argument.
  5. Opens the employee table.
  6. Opens the remote view in the database.
  7. Appends the records from the local table to the remote view.
  8. Updates the remote view with TABLEUPDATE( ).

Creating an Offline View

The code to create or drop the offline view is associated with the Offline method of the SampleApp form.

IF lcMode = 'create'
   =CREATEOFFLINE(lcView)
ELSE
   =DROPOFFLINE(lcView)
ENDIF

See Also

Solutions Samples | CURSORSETPROP | SQLEXEC( ) | Client/Server Sample | Client/Server Sample Application Classes | Client/Server Sample Application Database | Managing Data Conflicts in the Client/Server Sample Application | Implementing Business Rules in the Client/Server Sample Application