Preprocessing and Run Time Databases

From InterBase

Go Up to Declaring a Database


Normally, each SET DATABASE statement specifies a single database file to associate with a handle. When a program is preprocessed, gpre uses the specified file to validate the program’s table and column references. Later, when a user runs the program, the same database file is accessed. Different databases can be specified for preprocessing and run time when necessary.

Using the COMPILETIME Clause

A program can be designed to run against any one of several identically structured databases. In other cases, the actual database that a program will use at runtime is not available when a program is preprocessed and compiled. In such cases, SET DATABASE can include a COMPILETIME clause to specify a database for gpre to test against during preprocessing. For example, the following SET DATABASE statement declares that employee.ib is to be used by gpre during preprocessing:

EXEC SQL
SET DATABASE EMP = COMPILETIME 'employee.ib';
Important:
The file specification that follows the COMPILETIME keyword must always be a hard-coded, quoted string.

When SET DATABASE uses the COMPILETIME clause, but no RUNTIME clause, and does not specify a different database file specification in a subsequent CONNECT statement, the same database file is used both for preprocessing and run time. To specify different preprocessing and runtime databases with SET DATABASE, use both the COMPILETIME and RUNTIME clauses.

Using the RUNTIME Clause

When a database file is specified for use during preprocessing, SET DATABASE can specify a different database to use at run time by including the RUNTIME keyword and a runtime file specification:

EXEC SQL
SET DATABASE EMP = COMPILETIME 'employee.ib'
RUNTIME 'employee2.ib';

The file specification that follows the RUNTIME keyword can be either a hard-coded, quoted string, or a host-language variable. For example, the following C code fragment prompts the user for a database name, and stores the name in a variable that is used later in SET DATABASE:

. . .
char db_name[125];
. . .
printf("Enter the desired database name, including node
and path):\n");
gets(db_name);
EXEC SQL
SET DATABASE EMP = COMPILETIME 'employee.ib' RUNTIME :db_name;
. . .
Note:
Host-language variables in SET DATABASE must be preceded, as always, by a colon.

Advance To: