ALLOCATE SQLCONTEXT
Function
The ALLOCATE SQLCONTEXT statement identifies to the SQL precompiler which SQL Context is in scope for subsequent embedded SQL statements.
Invocation
Embedded Mode P Dynamic Mode Interactive Mode
Syntax
host_variable_identifier | A valid single host variable identifier. It must resolve to the address of an SQL Context (a SAGContext structure). |
Description
The ALLOCATE SQLCONTEXT statement is provided to facilitate the writing of multi-threaded SQL client applications. This is a programmatic mechanism to allow the SQL application to maintain multiple SQL contexts, each corresponding to a logical SQL user, in a multi-threaded application. The ALLOCATE SQLCONTEXT statement identifies to the SQL precompiler which SQL Context is active for subsequent embedded SQL statements. At runtime, the host variable specified in the statement must resolve to the address of a valid SQL Context.
The address in the host variable can be changed, with the effect that the new address identifies that another SQL Context is now active. No actual memory is allocated by this statement. Instead, the address in the host variable must point to an already allocated SAGContext structure. This statement does not result in a call to the CONNX Embedded SQL; it is a programmatic directive to the SQL precompiler only.
Limitations:
An instance of an ALLOCATE SQLCONTEXT statement is in scope from the point in the embedded-SQL source module at which the statement appears until one of the following:
Another ALLOCATE SQLCONTEXT statement is encountered.
Any DEALLOCATE SQLCONTEXT statement is encountered.
The end of the source module.
ANSI Specifics:
The ALLOCATE SQLCONTEXT statement is not part of the Standard.
CONNX Embedded SQL Specifics:
See also the related CONNX Embedded SQL statement:
DEALLOCATE SQLCONTEXT.
Here is an example on how to identify an SQL context:
exec sql begin declare section;
SAGContext sqlCtx;
exec sql end declare section;
exec sql allocate sqlcontext as :&sqlCtx