Using Browse mode

Conceptually, using Browse mode involves two steps:

  1. Select 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, and use the new values to update the original database tables.

These steps are implemented in a program as follows:

  1. Set a connection’s CS_HIDDEN_KEYS property to CS_TRUE. This ensures that Client-Library returns a table’s timestamp column as part of a result set. In browse-mode updates, the timestamp column is used to regulate multiuser updates.

  2. Execute a select...for browse language command. This command generates a regular row result set. This result set contains hidden key columns (one of which is the timestamp column) in addition to explicitly selected columns.

  3. After ct_results indicates regular row results, call ct_describe to get CS_DATAFMT descriptions of the result columns:

    • To indicate the timestamp column, ct_describe sets the CS_TIMESTAMP and CS_HIDDEN bits in the *datafmt−>status field.

    • To indicate an ordinary hidden key column, ct_describe sets the CS_HIDDEN bit in the *datafmt−>status field. If the CS_HIDDEN bit is not set, the column is an explicitly selected column.

  4. Call ct_bind to bind the result columns of interest. An application must bind all hidden columns because it requires these column values to build a where clause at update time.

  5. Call ct_br_table, if necessary, to retrieve information about the database tables that underlie the result set. Call ct_br_column, if necessary, to retrieve information about a specific result set column. Both of these types of information are useful when building a language command to update the database.

  6. Call ct_fetch in a loop to fetch rows. When a row is fetched that contains values that need to be changed, update the database table(s) with the new values. To do this:

    • Construct a language command containing a Transact-SQL update statement with a where clause that uses the row’s hidden columns (including the timestamp column).

    • Send the language command to the server and process the results of the command.

      A language command containing a browse-mode update statement generates a result set of type CS_PARAM_RESULT. This result set contains a single result item, the new timestamp for the row.

      If the application plans to update this same row again, it must save the new timestamp for later use.

After one browse-mode row has been updated, the application fetches and process the next row.