SQL Programming Manual for TAL

Dynamic NonStop SQL Operations
HP NonStop SQL Programming Manual for TAL527887-001
7-13
Overview of a Dynamic SQL Program
2. Begin a TMF transaction (for both SELECT and non-SELECT statements):
EXEC SQL BEGIN WORK;
3. Open the cursor:
! Using a cursor name:
EXEC SQL OPEN c1
USING DESCRIPTOR :isqlda^ptr;
! Using a cursor host variable:
EXEC SQL OPEN :cursor^hostvar
USING DESCRIPTOR :isqlda^ptr;
4. Execute a loop to fetch the values and display them.
! Using a cursor name:
EXEC SQL FETCH c1
USING DESCRIPTOR :osqlda^ptr;
! Using a cursor host variable:
EXEC SQL FETCH :cursor^hostvar
USING DESCRIPTOR :osqlda^ptr;
Display the values in a format according to data type. (For a repetitive display of
column names, use the output names buffer at this point and omit the last step
under Step 4.)
Handle null values as follows:
If NULL^INFO is -1, then check the indicator variable pointed to by IND^PTR. If
the indicator variable is also -1, display something representing a null value
(perhaps blanks or zeroes); otherwise, display the value pointed to by
VAR^PTR.
If NULL^INFO is 0, display the value pointed to by VAR^PTR.
5. Close the cursor:
! Using a cursor name:
EXEC SQL CLOSE c1;
! Using a cursor host variable:
EXEC SQL CLOSE :cursor^hostvar;
6. If the statement was not a SELECT statement, execute the statement:
If there were input parameters:
! Using a statement name:
EXEC SQL EXECUTE s1
USING DESCRIPTOR :isqlda^ptr;
! Using a statement host variable:
EXEC SQL EXECUTE :statement^hostvar
USING DESCRIPTOR :isqlda^ptr;