RowVersion and ModTime Field Types

Advantage Concepts

The RowVersion and ModTime field types are field types that are automatically updated by the Advantage Database Server. For simplicity's sake, these field types are not read-only, however, values written to these fields by the client will not be stored in the table. Rather, the Advantage Database Server will create new values when a record is updated just before the record is written to the table.

RowVersion

The RowVersion field type is a 64-bit unsigned auto-incrementing integer that is incremented each time a record is updated. The RowVersion field value is unique to the entire table with the last updated record containing the largest RowVersion value. The primary purpose of the RowVersion field type is for use with optimistic concurrency. Optimistic concurrency is a mechanism used to guarantee record updates are not overwritten in a multi-user environment. Take for example, two users of a database:

User1 and User2 are viewing the same record of a table. User1 updates the record. If User2 updates the same record, User1's updates will be lost.

To implement optimistic concurrency using the RowVersion field type, User2 would first verify that the current RowVersion value in the record is the same as the value in the record it is viewing before performing the update. This is usually implemented using an SQL update statement. An example update statement might be:

UPDATE customers SET acctBalance = :newbalance WHERE rowver = :oldRowVersion

where the oldRowVersion parameter is the RowVersion value in the record that the user is viewing. If the RowVersion values don't match, no update is performed. The application can then tell no update was performed by checking number of affected rows of the update statement and act accordingly.

ModTime

The ModTime field type is a timestamp type field which is automatically updated with the current date and time when a record is updated.

Development Notes