SQL Programming Manual for Pascal
Using Dynamic SQL
HP NonStop SQL Programming Manual for Pascal—528614-001
7-23
Dynamically Allocating Memory
columns (output variables). The following description shows how to handle input
parameters.
The program uses the DESCRIBE INPUT statement to fill in the SQLDA and names
buffer with the descriptions of the input parameters in the SQL statement. If you specify
NAMES INTO, the names of the parameters are also returned in the names buffer.
For a statement whose name was stored in a statement host variable, the DESCRIBE
INPUT statement is:
EXEC SQL
DESCRIBE INPUT :STATEMENT_HOSTVAR
INTO :INPUT_SQLDA_PTR^
NAMES INTO :INPUT_NAMESBUF_PTR^;
The DESCRIBE INPUT statement places the descriptions for the parameters into the
input SQLDA, and the names of the parameters into the location pointed to by
INPUT_NAMESBUF_PTR. After DESCRIBE INPUT executes, SQLVAR.VAR_PTR
points to the first entry in the names buffer.
The program can now prompt the user for the input parameter values, set the pointer
to the first SQLVAR element in the input SQLDA, and read through the SQLVAR array,
storing each value the user inputs into the appropriate position in memory.
Handling Scale. If your program must handle numeric values with scale, you will need
to read scale information from the input SQLDA structure. The DESCRIBE INPUT
statement places this information in bits 0 through 7 of the DATA_LEN field in the
SQLVAR array.
For handling input parameters, the following possibilities exist:
•
The program can ignore scale entirely: set bits 0 through 7 of SQLVAR.DATA_LEN
to 0 and send integers to SQL.
•
The program can ignore scale but accept scaled values from the user: set bits 0
through 7 of SQLVAR.DATA_LEN to 0, truncate digits to the right of the decimal
point in the user-entered value, and send the resulting integers to SQL.
•
The program can handle scale: write a procedure that scales the user-entered
value to match the value in bits 0 through 7 of SQLVAR.DATA_LEN.
Similar considerations apply if your program must handle precision for date-time,
INTERVAL, FLOAT, or binary numeric values. The precision information is in the
PRECISION field of the SQLVAR entry.
Literal Declarations. Your program must check the data type of:
•
The values input to the program, before using them
•
The values output by the database, before reporting them