The ALLOCATE SQLCONTEXT statement identifies to the SQL precompiler which SQL Context is in scope for subsequent embedded SQL statements.
Embedded Mode P |
Dynamic Mode |
Interactive Mode |
host_variable_identifier |
A valid single host variable identifier. It must resolve to the address of an SQL Context (a SAGContext structure). |
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 Adabas SQL Gateway Embedded SQL; it is a programmatic directive to the SQL precompiler only.
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.
The ALLOCATE SQLCONTEXT statement is not part of the Standard.
See also the related Adabas SQL Gateway Embedded SQL statement: DEALLOCATE SQLCONTEXT.
Example
An SQL context can be identified as follows:
exec sql begin declare section;
SAGContext sqlCtx;
exec sql end declare section;
exec sql allocate sqlcontext as :&sqlCtx