IBM DB2 Manual page 134

Table of Contents

Advertisement

Iterators as passed variables for positioned UPDATE or DELETE
operations in an SQLJ application
SQLJ allows iterators to be passed between methods as variables.
An iterator that is used for a positioned UPDATE or DELETE statement can be
identified only at runtime. The same SQLJ positioned UPDATE or DELETE
statement can be used with different iterators at runtime. If you specify a value of
YES for -staticpositioned when you customize your SQLJ application as part of the
program preparation process, the SQLJ customizer prepares positioned UPDATE or
DELETE statements to execute statically. In this case, the customizer must
determine which iterators belong with which positioned UPDATE or DELETE
statements. The SQLJ customizer does this by matching iterator data types to data
types in the UPDATE or DELETE statements. However, if there is not a unique
mapping of tables in UPDATE or DELETE statements to iterator classes, the SQLJ
customizer cannot determine exactly which iterators and UPDATE or DELETE
statements go together. The SQLJ customizer must arbitrarily pair iterators with
UPDATE or DELETE statements, which can sometimes result in SQL errors. The
following code fragments illustrate this point.
#sql iterator GeneralIter implements sqlj.runtime.ForUpdate
...
...
Figure 36. Static positioned UPDATE that fails
In this example, only one iterator is defined. Two instances of that iterator are
defined, and each is associated with a different SELECT statement that retrieves
data from a different table. During customization and binding with
-staticpositioned YES, SQLJ creates two DECLARE CURSOR statements, one for
each SELECT statement, and attempts to bind an UPDATE statement for each
cursor. However, the bind process fails with SQLCODE -509 when UPDATE TABLE1
... WHERE CURRENT OF :iter is bound for the cursor for SELECT CHAR_COL2 FROM
TABLE2 because the table for the UPDATE does not match the table for the cursor.
118
Application Programming Guide and Reference for Java
"Using a named iterator in an SQLJ application" on page 124
"Using a positioned iterator in an SQLJ application" on page 126
Related reference
"SQLJ implements-clause" on page 282
"SQLJ with-clause" on page 283
"sqlj.runtime.ForUpdate interface" on page 298
( String );
public static void main ( String args[] )
{
GeneralIter iter1 = null;
#sql [ctxt] iter1 = { SELECT CHAR_COL1 FROM TABLE1 };
GeneralIter iter2 = null;
#sql [ctxt] iter2 = { SELECT CHAR_COL2 FROM TABLE2 };
doUpdate ( iter1 );
}
public static void doUpdate ( GeneralIter iter )
{
#sql [ctxt] { UPDATE TABLE1 ... WHERE CURRENT OF :iter };
}

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents