SQL/MX Programming Manual for Java

SQL/MX Programming Considerations
HP NonStop SQL/MX Programming Manual for Java523726-003
4-17
DECLARE Statements for Static SQL
Line Order Scope of the DECLARE Statements
DECLARE statements have line order scope for a particular connection context. That
is, the scope of a DECLARE statement is based on the order of the SQL statements in
the SQLJ program. A DECLARE statement affects only those static SQL statements
with the same connection context that appear immediately after the DECLARE
statement in the program, and the DECLARE statement stays in effect until it is
replaced by another DECLARE statement with the same connection context.
Example
Suppose that the SQLJ program was successfully customized with
-missingSQLObject set to false. In this example, the first static DECLARE
CATALOG statement sets the catalog name to CAT1 for static SQL statements 1 to 3.
The second DECLARE CATALOG statement sets the catalog name to CAT2 for static
SQL statements 4 to 6. Note that these DECLARE statements affect only the static
SQL statements with the same ctx connection context.
try {
#sql [ctx] {DECLARE CATALOG 'CAT1'};
#sql [ctx] { /* Static SQL statement 1 */ };
#sql [ctx] { /* Static SQL statement 2 */ };
#sql [ctx] { /* Static SQL statement 3 */ };
#sql [ctx] {DECLARE CATALOG 'CAT2'};
#sql [ctx] { /* Static SQL statement 4 */ };
#sql [ctx] { /* Static SQL statement 5 */ };
#sql [ctx] { /* Static SQL statement 6 */ };
}
Connection Context of the DECLARE Statements
DECLARE statements affect only the static SQL statements with the same connection
context class because SQL statements with the same connection context class are
stored in the same profile.
Example
In this example, the DECLARE NAMETYPE statement does not affect static SQL
statement 2 because this statement is not associated with the same connection
context class and hence not stored in the same profile:
ctx1 = SQLMXCtx1.getDefaultContext();
#sql [ctx1] {DECLARE NAMETYPE 'NSK'};
#sql [ctx1] { /* Static SQL statement 1 */ };
ctx1.close();
ctx2 = SQLMXCtx2.getDefaultContext();