Browse Mode

DB Library for C

DB Library for C

Browse Mode

By creating temporary tables, browse mode lets you scan database rows and update their values one row at a time. This feature uses optimistic concurrency control, which holds no locks while you are accessing data. Browse mode requires several steps because it transfers each row from the database into program variables before browsing and updating it.

Because a row being browsed is just a copy residing in program variables, rather than the actual row in the database, the application must ensure that changes to the variables' values reliably update the original database row. In particular, in multiuser situations, the application must ensure that updates to the database made by one user do not overwrite updates made by another. This becomes an issue whether the application selects one row or several rows at a time from the database. A timestamp column in database tables that can be browsed lets you regulate this type of multiuser updating.

Browse-mode functions also allow an application to update ad hoc queries (queries made while an application is running). Several of these functions 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 does the following:

  1. Issues a SELECT statement.

  2. Fetches rows.

  3. If any changes must be made, constructs an UPDATE statement and issues it.

In an application, implement these steps as follows:

  1. Execute a SELECT statement, generating result rows containing result columns. The SELECT statement must include the FOR BROWSE option.

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

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

  4. If appropriate, construct and execute an UPDATE statement that updates the database row corresponding to the current result row. To handle multiuser updates, the WHERE clause of the UPDATE statement must reference the timestamp column. An appropriate WHERE clause can be constructed with the dbqual function.

  5. Repeat steps 2 through 4 for each result row.

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

  • The SELECT statement must end with the keywords FOR BROWSE.

  • The table(s) to be updated must have a unique index (or primary key) and a timestamp column.

  • The result columns to be used in the updates must be derived from tables that can be browsed and cannot be the result of compute columns, such as "MAX(colname)." In other words, there must be a valid correspondence between the result column and the database column to be updated.

In addition, browse mode requires two DBPROCESS structures: one for selecting the data and another for updating based on the selected data.