Accessing Databases

From InterBase

Go Up to DSQL API Limitations

The InterBase API permits applications to attach to multiple databases simultaneously using database handles. Database handles must be declared and initialized when an application is compiled. Separate database handles should be supplied and initialized for each database accessed simultaneously. For example, the following code creates a single handle, db1, and initializes it to zero:

#include <ibase.h>
isc_db_handle db1;
. . .
db1 = 0L;

Once declared and initialized, a database handle can be assigned dynamically to a database at runtime as follows:

#include <ibase.h>
. . .
char dbname[129];
ISC_STATUS status_vector[20];
. . .
prompt_user("Name of database to open: ");
isc_attach_database(status_vector, 0, dbname, &db1, NULL, NULL);

A database handle can be used to attach to different databases as long as a previously attached database is first detached with isc_detach_database(), which automatically sets database handles to NULL. The following statements detach from a database, set the database handle to zero, and attach to a new database:

isc_detach_database(status_vector, &db1);
isc_attach_database(status_vector, 0, "employee.ib", &db1, NULL, NULL);

For more information about API function calls for databases, see Working with Databases.

Advance To: