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:
Select result rows containing columns derived from one or more database tables.
Where appropriate, change values in columns of the result rows (not the actual database rows), one row at a time.
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:
Execute a select command, generating result rows containing result columns. The select command must include the for browse option.
Copy the result column values into program variables, one row at a time.
If appropriate, change the values of the variables (possibly in response to user input).
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.
Repeat steps 2, 3, and 4 for each result row.
To use browse mode, the following conditions must be true:
The select command must end with the key words for browse.
The table(s) to be updated must be “browsable” (that is, each must have a unique index and a timestamp column). Note that because a browse mode table has unique rows, the keyword distinct has no effect in a select against a browse-mode table.
The result columns to be used in the updates must be “updatable”—they must be derived from browsable tables and cannot be the result of SQL expressions, 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 usually requires two connections (DBPROCESS pointers)—one for selecting the data and another for performing updates based on the selected data.
For examples of browse-mode programming, see the sample programs, example6.c and example7.c, included with DB-Library. See “Sample programs”.
The following constitute the browse-mode routines:
dbqual – returns a pointer to a where clause suitable for use in updating the current row in a browsable table.
dbfreequal – frees the memory allocated by dbqual.
dbtsnewval – returns the new value of the timestamp column after a browse-mode update.
dbtsnewlen – returns the length of the new value of the timestamp column after a browse-mode update.
dbtsput – puts the new value of the timestamp column into the given table’s current row in the DBPROCESS.
dbcolbrowse – indicates whether the source of a result column is updatable through browse mode.
dbcolsource – returns a pointer to the name of the database column from which the specified result column was derived.
dbtabbrowse – indicates whether a particular table is updatable using browse mode.
dbtabcount – returns the number of tables involved in the current select command.
dbtabname – returns the name of a table based on its number.
dbtabsource – returns the name and number of the table from which a particular result column was derived.