Controlling SET DATABASE Scope
Go Up to Declaring a Database
By default, SET DATABASE creates a handle that is global to all modules in an application. A global handle is one that may be referenced in all host-language modules comprising the program. SET DATABASE provides two optional keywords to change the scope of a declaration:
STATIClimits declaration scope to the module containing theSET DATABASEstatement. No other program modules can see or use a database handle declaredSTATIC.EXTERNnotifiesgprethat aSET DATABASEstatement in a module duplicates a globally-declared database in another module. If theEXTERNkeyword is used, then another module must contain the actualSET DATABASEstatement, or an error occurs during compilation.
The STATIC keyword is used in a multi-module program to restrict database handle access to the single module where it is declared. The following example illustrates the use of the STATIC keyword:
EXEC SQL SET DATABASE EMP = STATIC 'employee.ib';
The EXTERN keyword is used in a multi-module program to signal that SET DATABASE in one module is not an actual declaration, but refers to a declaration made in a different module. gpre uses this information during preprocessing. The following example illustrates the use of the EXTERN keyword:
EXEC SQL SET DATABASE EMP = EXTERN 'employee.ib';
If an application contains an EXTERN reference, then when it is used at run time, the actual SET DATABASE declaration must be processed first, and the database connected before other modules can access it.
A single SET DATABASE statement can contain either the STATIC or EXTERN keyword, but not both. A scope declaration in SET DATABASE applies to both
COMPILETIME and RUNTIME databases.