A database must be opened before it can be accessed. You open a database with the db_open() or dp4_db_open() functions. In DP4 C applications you will often only need the call to db_open() that LIBMAKE generates for you.
When you have finished using a database, you must close it to ensure that it is shut down properly. Another C function, db_close(), is available for closing a database. In C programs LIBMAKE generates a call to close the database in the finish() function, which is always called when the application is terminating.
The Example Code Generated by LIBMAKE contains the lines shown here:
37 38 39 40 41 42 43 44 45 46 |
void init()
{
df_libtype = 1;
db_open("SALESORD",0,SHARED+PRIVATE_DB);
map_load("TEMPLATE");
}
void finish()
{
db_close();
} |
When any DP4 C program using the standard main() function is run, the function init() is called before process(). It contains the following call to db_open on line 40:
db_open("SALESORD",0,SHARED+PRIVATE_DB);
When a DP4 C program finishes, the function finish is called last. Therefore, the call to db_close() shown in line 45 closes the SALESORD database. You can open and close databases at any point in your program.