ODBC Server Reference Manual
Stored Procedures
HP NonStop ODBC Server Reference Manual—429151-002
5-19
Developing a Stored Procedure in C
Fetch the data and encode the resulting rows:
/* ------------------------------------------------------
SQL FETCH loop
---------------------------------------------------- */
do
{
EXEC SQL FETCH emp21_cursor
into :emp_rec.empnum,
:emp_rec.first_name,
:emp_rec.last_name,
:emp_rec.deptnum;
if ((sqlcode >= SQL_OK) && (sqlcode !=
SQL_NOT_FOUND))
{
num_rows++;
/* ------------------------------------------------------
Call ENCODE_ROW_DATA to set up the IPC message with
each
row of data being returned.
---------------------------------------------------- */
rc = encode_row_data( env
, max_len
, sdao21
, output_buffer
, reply_err
);
if (rc != SPELIB_OK)
{
EXEC SQL CLOSE emp21_cursor;
strncpy(errtext, "Unable to encode Row Data",
goto LIBERR;
}
}
}
while ((sqlcode >= SQL_OK) && (sqlcode !=
SQL_NOT_FOUND));
/*------------- end SQL fetch --------------------------*/
d. “End statement” and “end proc.” After all rows have been returned, the stored
procedure must encode an “end statement” notification to indicate that the SQL
statement has been completed. As this is also the end of the stored procedure,
an “end proc” notification must also be encoded.
/* ------------------------------------------------------
Every SQL statement should end with an END_STATEMENT
msg.
----------------------------------------------------- */
rc = encode_end_statement( env, &sqlca);
if (rc != SPELIB_OK)
return (rc);