Dynamic Sql Sample Programs; Basic Dynamic Sql Program - HP NonStop SQL/MP Programming Manual

For c
Table of Contents

Advertisement

Dynamic SQL Operations
If possible, avoid having fields in your requester or server messages that contain an
odd number of bytes. There are some subtle differences in the way SCREEN COBOL
and C generate fields in records when fields contain an odd number of bytes. Also,
some C functions generate a null byte terminator for character strings. If your server
contains a message with null terminators, the message will not match the one sent
from the SCREEN COBOL requester. Therefore, to avoid these problems, follow these
guidelines:
Use DDL to describe the request and reply messages and then use the C form of
the structures derived from the DDL compiler. The DDL compiler does not append
a null terminator to C character strings.
In the SCREEN COBOL requester, avoid constructing messages by listing several
data items in the SEND statement. Instead, send a single structure to the C server.
Ensure that the C server does not use logic that expects to find null terminators in
the request message. For example, the printf, strcpy, and strlen functions
expect the null byte. Consider moving the request data to another location that
allows room for the null byte and processing the data from the new location.

Dynamic SQL Sample Programs

These pages contain two complete dynamic SQL programs in C. The first program
processes a SELECT statement that is partially coded into the program; the user
supplies the WHERE clause. The second program allows the user to enter any SQL
statement.

Basic Dynamic SQL Program

The basic sample program contains a SELECT statement to find the average salary for
a selection of rows in the employee table. The program prompts the user for the
selection criteria and constructs the statement by adding a WHERE clause.
This program is an elementary one because there are no input parameters and there is
only one output variable (the salary column is the only column described in the output
SQLDA, and the average salary is the only value output to the user). Because no
parameter names or column headings are required, names buffers are not necessary.
This program allocates memory at compile time by using INCLUDE SQLDA and
specifying 1 output variable. You can specify 1 output variable because you know you
are only reporting data for one column. You must still assign the memory location of
the value to be output (in this case, the average) to the var_ptr field.
To run this program, you need a DEFINE that points to the employee table in the
sample database. A complete set of DEFINEs might look like this:
SET DEFMODE ON
ALTER DEFINE =_DEFAULTS, CATALOG \SYS1.$VOL1.TESTCAT
ALTER DEFINE =_DEFAULTS, VOLUME \SYS1.$VOL1.TESTVOL
HP NonStop SQL/MP Programming Manual for C—429847-008
10-37
Dynamic SQL Sample Programs

Advertisement

Table of Contents
loading

Table of Contents