iTP Active Transaction Pages (iTP ATP) Programmer's Guide

ATP Web Page and Script Structure
iTP Active Transaction Pages (iTP ATP) Programmer’s Guide522292-002
3-7
Using NonStop SQL from JavaScript
Performing the Requested Transaction
To implement an SQL statement, the script
(/examples/sql/homebank/Webpages/address.atp) must first create an
instance of the atp.SQL object. In creating the object, the script specifies the SQL
statement type, but the constructor (the call to create the object) does not implicitly
execute the statement.
Before using the execute method, the script creates an atp.transaction object
so the database update will be protected by NonStop TM/MP. (The
atp.transaction object could have been created before the SQL object; it must be
created before the script invokes the execute method. The transaction doesn’t begin
until the script supplies the atp.transaction object as a parameter to a method, in
this case the execute method.)
After the execute method call, the script checks the SQL error code, using the
sqlcode property of the atp.SQL object. According to the error code, the script
either commits or rolls back the transaction, using the commit or rollback method
of the atp.transaction object, and displays a message to the user, indicating the
outcome of the transaction.
ATP example scripts follow the convention of displaying error messages at the top of the
screen.
Example 3-4. Implementing a NonStop SQL Statement
// If we're in "POST" mode, process the transaction request...
if (atp.request.REQUEST_METHOD=="POST") {
var tdict=new atp.dictionary("=atp_HM_ddl","cust_update_request",
"cust_update_reply", "reply_header");
var treqBuf= new atp.buffer("c");
with (tdict.element.cust_update_request) {
// Set up the update request buffer ....
treqBuf.setData("addresschangeaccept",
request_header.service_name);
treqBuf.setData(globalAccessUserid, cust_record.custid);
treqBuf.setData(atp.request.LastName, cust_record.last_name);
treqBuf.setData(atp.request.FirstName, cust_record.first_name);
treqBuf.setData(atp.request.AddressLine1, cust_record.address_line_1);
treqBuf.setData(atp.request.AddressLine2, cust_record.address_line_2);
treqBuf.setData(atp.request.AddressCity , cust_record.address_city);
treqBuf.setData(atp.request.AddressState, cust_record.address_state);
treqBuf.setData(atp.request.AddressZip , cust_record.address_zip);
treqBuf.setData(atp.request.RowVersion , cust_record.row_version);
} // end of 'with' scope
// Do the update transaction ...
sendToServer ("=tandem_pathmon_name", "atp-customer", treqBuf,
tdict.element.reply_header);
trepBuf = treqBuf.reply;
// There could be a warning message...
var userMsg=
trepBuf.getData(tdict.element.cust_update_reply.reply_header.message);
if (userMsg.length == 0)
userMsg = "Customer record updated.";
print ('<strong><i>'+userMsg+'</i></strong>');
} // End of special POST method processing