ODBC Server Reference Manual

Stored Procedures
HP NonStop ODBC Server Reference Manual429151-002
5-17
Developing a Stored Procedure in C
--------------------------------------------------- */
sdan21 = allocate_SQLDA ( SPE_21_max_entries, FALSE);
colnames21 = (arrayptr) malloc (500);
strncpy (sdan21->eye_catcher, SQLDA_EYE_CATCHER, 2);
sdan21->num_entries = SPE_21_max_entries;
/* ------------------------------------------------------
Separate SQLDA for column definitions needs to be
allocated. This area is used by ENCODE_ROW_DATA.
---------------------------------------------------- */
sdao21 = allocate_SQLDA ( SPE_21_max_entries, FALSE);
strncpy (sdao21->eye_catcher, SQLDA_EYE_CATCHER, 2);
sdao21->num_entries = SPE_21_max_entries;
2. Create the stored procedure routine
This is the routine for the actual stored procedure. There are four basic operations
that must be performed:
a. Get the input parameters, if any.
b. Call the encode initialization routine
c. Execute the main logic and for each result set to be returned encode a row
descriptor, then encode the row data. After executing each SQL statement,
encode an “end statement” message.
d. Encode an “end procedure” message to indicate that the procedure execution
is completed.
The following example uses the code for the routine SELECT_INPUT_DEPT to
illustrate the preceding steps:
a. Get the input parameters.
/* ------------------------------------------------------
Get the input param values
---------------------------------------------------- */
rc = get_input_params( env
, reply_err
, max_len
, output_buffer
, sdai21
);
/* --retrieve input value and copy into host variable--*/
len=get_data_len(&(sdai21->sqlvar[0]));
ptr = (char *)&(input_value);
memcpy (ptr,((long int *)
(sdai21->sqlvar[0].var_ptr)),len);