SQL/MP Programming Manual for C

Dynamic SQL Operations
HP NonStop SQL/MP Programming Manual for C429847-008
10-36
Developing a Dynamic SQL Pathway Server
Developing a Dynamic SQL Pathway Server
Follow these guidelines to develop a C server that interfaces with Pathway and uses
dynamic SQL statements. Except for constructing the SQL statement, these steps are
not unique to servers using NonStop SQL/MP. You perform these steps in addition to
the tasks you would perform for any dynamic SQL program.
1. Use the #include directive to copy the declarations in the cextdecs file for the
FILE_OPEN_, READUPDATE, and REPLY procedures.
2. Define storage for the messages the server will receive from the SCREEN COBOL
requester.
3. Define a character string to contain the dynamic SQL statement the program will
construct from the input.
4. Call the FILE_OPEN_ and READUPDATE procedures to open and read
$RECEIVE. For information about reading $RECEIVE, see the Guardian
Programmer’s Guide.
5. Construct the dynamic SQL statement. Check the values passed from the
requester in the buffer to determine the syntax of the statement. As you process
each value, concatenate the corresponding text to form the statement.
For example, suppose that the screen describes a personnel record. If any column
does not have a value, the user can enter an N. The request message you define
is named list_msg. This example checks the empnum field in list_msg and, if
required, concatenates the text “empnum” to the dynamic SQL statement:
char statement[200];
...
strcpy (statement, "SELECT");
if (list_msg.empnum != 'N') strcat (statement, " empnum");
...
The SQL statement now contains the string “SELECT empnum”. You continue to
construct the entire statement based on values entered by the user.
6. After you construct the statement, pad the remainder of the buffer, including the
null terminator position, with blanks.
7. Compile and run the SQL statement using either the PREPARE and EXECUTE
statements or the EXECUTE IMMEDIATE statement.
8. Construct the reply message to return information to the SCREEN COBOL
requester. The first field in the reply message must contain the reply code to
communicate with the SCREEN COBOL requester. The remaining fields in the
message contain data returned by the SQL statement.
9. Call the REPLY procedure to send the reply message to the SCREEN COBOL
requester.