Database Access Summary

To access DP4 databases at all you have to call three functions: srv_load_srv(), srv_connect() or srv_get_process(), and srv_enable(). For C programs these functions are normally for you by the supplied main() function.

These functions are directed to the database server. With the exception of the System database, to access a database you must first open it with a call to db_open() or open_database() if your program can work with any database and the user should choose the database to work on. Both functions allow you to specify various modes to control how the database is opened.

To fetch records from the database, use rec_fetch() on the main index or on the secondary index or for reading data sequentially use bf_fetch() . The same functions are also used to LOCK records.

To add or update records to the database, use the rec_post() function, and to delete records use use rec_kill() function. You can get DP4 to generate keys for new records automatically for auto-increment tables using rec_autoinc()

To write the records to the database, make a call to db_commit(), db_checkpoint() or db_update().

When a program has finished with a database it should close it with db_close().

If a program wants to access more than one database it needs to save and restore the db_nr and db_generation variables associated with each database. Failure to do this correctly can cause data to be corrupted./p>