Browse mode

Browse mode provides a means for browsing through database rows and updating their values a row at a time. From the standpoint of the program, the process involves several steps, because each row must be transferred from the database into program variables before it can be browsed and updated.

Since a row being browsed is not the actual row residing in the database, but is instead a copy residing in program variables, the program must be able to ensure that changes to the variables’ values can be reliably used to update the original database row. In particular, in multiuser situations, the program needs to ensure that updates made to the database by one user do not unwittingly overwrite updates recently made by another user. This can be a problem because the application typically selects a number of rows from the database at one time, but the application’s users browse and update the database one row at a time. A timestamp column in browsable database tables provides the information necessary to regulate this type of multiuser updating.

Browse mode routines also allow an application to handle ad hoc queries. Several routines return information that an application can use to examine the structure of a complicated ad hoc query to update the underlying database tables.

Conceptually, browse mode involves three steps:

  1. Select result rows containing columns derived from one or more database tables.

  2. Where appropriate, change values in columns of the result rows (not the actual database rows), one row at a time.

  3. Update the original database tables, one row at a time, using the new values in the result rows.

These steps are implemented in a program as follows:

  1. Execute a select command, generating result rows containing result columns. The select command must include the for browse option.

  2. Copy the result column values into program variables, one row at a time.

  3. If appropriate, change the values of the variables (possibly in response to user input).

  4. If appropriate, execute an update command that updates the database row corresponding to the current result row. To handle multiuser updates, the where clause of the update command must reference the timestamp column. Such a where clause can be obtained through the dbqual function.

  5. Repeat steps 2, 3, and 4 for each result row.

To use browse mode, the following conditions must be true:

For examples of browse-mode programming, see the sample programs, example6.c and example7.c, included with DB-Library. For more information of DB-Library sample programs, see “Sample programs”.

The following constitute the browse-mode routines: