SQL Programming Manual for Pascal

Using Dynamic SQL
HP NonStop SQL Programming Manual for Pascal528614-001
7-3
Writing a Dynamic SQL Pathway Server
You can use the predefined constants FILE_NUMBR, CONDITION_CODE,
BYTE_COUNT, INTERNAL_FILENAME_TYPE, and OK_CONDITION to pass
information to the GUARDIAN procedures.
Except for constructing the SQL statement, the following tasks are not unique to
servers using SQL. You perform these tasks in addition to the tasks you would
perform for any dynamic SQL program:
2. Define storage for the messages to be received from the SCREEN COBOL
requester.
3. Define a character string to contain the statement that the program will construct
from the input.
4. Call the GUARDIAN_OPEN and READUPDATE procedures to read $RECEIVE.
VAR
FILENUM : FILE_NUMBR;
STATUS : CONDITION_CODE;
READCOUNT : BYTE_COUNT;
FILENAME : INTERNAL_FILENAME_TYPE
BUFFER : WORDALIGNED ARRAY[1..80] OF CHAR;
...
FILENAME.SUBVOL.VOLUME := '$RECEIVE';
FILENAME.SUBVOL.SUBVOLUME := ' ';
FILENAME.FILENAME := ' ';
STATUS := GUARDIAN_OPEN(FILENAME, FILENUM, , 1);
IF STATUS <> OK_CONDITION THEN ... { process error }
STATUS := READUPDATE(FILENUM, WADDR(BUFFER),
LENGTH(BUFFER),
READCOUNT);
IF STATUS <> OK_CONDITION THEN ... { process error }
5. Construct the SQL statement:
Check values passed from the requester in the buffer to decide what the
statement includes.
As each value is read, concatenate the corresponding text to form the
statement.
For example, suppose the screen describes a personnel record. If any column
does not have a value, the user can enter N. The request message you
defined is named LIST_MSG. The following code checks the EMPNUM field in
LIST_MSG and, if required, concatenates the text EMPNUM to the statement
you are constructing:
VAR STATEMENT : FSTRING(200);
...
STATEMENT := 'SELECT';
...
IF LIST_MSG.EMPNUM <> 'N'