Context threaded optimization

allows developers to specify the runtime context that is used for a set of statements. A runtime context holds all the thread-specific data that must maintain including connections and their current states, cursors, and their current states.

This feature allows programmers to improve the performance of their MESQL/C applications. By using the SQLCONTEXT definitions and directives, the number of thread-specific data block lookups is reduced.

The following embedded SQL statements support the definition and usage of runtime contexts:
SQLCONTEXT context_var;
PARAMETER SQLCONTEXT param_context_var;
BEGIN SQLCONTEXT OPTIMIZATION;
END SQLCONTEXT OPTIMIZATION;

The SQLCONTEXT definition and statements are only recognized when the esql-thread option is used. If the -thread option is not specified, the statements are ignored.

The use of the SQLCONTEXT statements causes the ESQL/C preprocessor to generate code in the .c file that differs from the generated code when no SQLCONTEXT statements are present.

The following SQLCONTEXT definition generates code to define and set the value of the SQLCONTEXT to the handle of the runtime context:
SQLCONTEXT context_var;
The following SQLCONTEXT is used to generate code to define a parameter that contains the handle of the runtime context:
PARAMETER SQLCONTEXT param_context_var;
The following BEGIN SQLCONTEXT directive causes all statements positionally following it in the source file to use the indicated runtime context until the END CONTEXT directive is seen:
BEGIN SQLCONTEXT OPTIMIZATION;
...
END SQLCONTEXT OPTIMIZATION;

The END SQLCONTEXT directive appears before the end of the scope of the SQLTCONTEXT definition currently used, or compile-time errors occur for “undefined symbol sql_context_var.”