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:

 


allocate_sqlcontext.bmp


 

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 Adabas SQL Gateway 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.

 

Adabas SQL Gateway Embedded SQL Specifics:

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