iTP Active Transaction Pages (iTP ATP) Programmer's Guide
ATP Objects, Properties, and Methods
iTP Active Transaction Pages (iTP ATP) Programmer’s Guide—522292-002
4-21
atp.SQL Object
Parameters in SQL Statements
Parameterize SQL statements to maximize cache efficiency and script performance.
In the following example, the constructor specifies the SQL statement with the
parameter first; the execute() method invocation provides the value Roger:
s=new atp.SQL("select * from =cust where first_name =
?first browse access");
s.execute("Roger");
s.next();
The following example is functionally the same but not as efficient:
name = "Roger";
s=new atp.SQL("select * from =cust where first_name = '" +
name + "' browse access");
s.execute();
s.next();
Updateable Cursors
You can use the cursor_name property to refer to an updateable cursor in SQL Data
Management Language (DML) statements. For example:
tran = new atp.transaction();
var s1 = new atp.SQL ("select * from =cust for update of last_name");
s1.execute (tran);
while (s1.next(tran))
{
var s2 = new atp.SQL ("update =cust set last_name = ?last"+
"where current of " + s1.cursor_name);
s2.execute ("Smith", tran);
}
tran.commit();
Using SQL Null
In server-side JavaScript, the keyword null (not the string “null”) indicates a null
value. The following example illustrates the syntax to use in update statements for
setting columns to SQL null. The execute() method considers the two variables to be
one variable. This first example shows incorrect usage:
tran = new atp.transaction();
var s1 = new atp.SQL ("update =table set mycolumn = ?x
indicator ?y for stable access");
s1.execute (null, tran);
tran.commit();
To set multiple columns to SQL null, use a different indicator variable for each column.
This example shows correct usage:
update =table
set col1= ?x1 indicator ?ind1
set col2= ?x2 indicator ?ind2
s1.execute(gCol1_val, gCol2_val, tran);