ODBC Server Reference Manual

Stored Procedures
HP NonStop ODBC Server Reference Manual429151-002
5-18
Developing a Stored Procedure in C
b. Encode initialization.
/* ------------------------------------------------------
Encode_init must be called to set up each reply buffer
before writing any data into the buffer for return to
the NSODBC server.
---------------------------------------------------- */
rc = encode_init( env
, max_len
, output_buffer
, reply_err
);
if (rc != SPELIB_OK)
{
strncpy(errtext, "Error attempting encode_init", rc);
goto Liberr;
}
c. Main logic. The purpose of this stored procedure is to select employee data for
a specified department number. The steps involved are to open the cursor for
selecting the data from the table and encode a row descriptor for the rows to
be returned and then encode the row data for each row fetched from the table.
The first step is as follows:
EXEC SQL OPEN emp21_cursor;
if (sqlcode != SQL_OK)
{
strncpy(errtext, "Unable to OPEN cursor", 30);
goto SQLERR;
}
/* ------------------------------------------------------
Call ENCODE_ROW_DESCRIPTOR to set up IPC message with
column headings
---------------------------------------------------- */
rc = encode_row_descriptor( env
, max_len
, sdan21
, output_buffer
, reply_err
);