ODBC Server Reference Manual

Stored Procedures
HP NonStop ODBC Server Reference Manual429151-002
5-13
Developing a Stored Procedure in C
Each of the major functions in Figure 5-3 are described as follows:
main
The main() routine is very simple and uses a function named REGISTER_SPE for
registering all of the stored procedures included within the server. The
REGISTER_SPE function is called once for each stored procedure included within
the server. The function PROCESS_EVENT_QUEUE is then called for handling
any event received from $RECEIVE.
register_spe
This function is called to register a stored procedure within the server program.
The registration process allows each stored procedure to provide the following:
the address of a function to be called when the server program is first started
the address of a function to be called when the stored procedure is to be
executed
the address of a function to be called when the server program terminates
process_event_queue
This is the main function of the stored procedure server. It is responsible for
initializing the server by calling the initialization functions provided for each of the
stored procedures. After initialization is completed, this function handles all system
messages received on $RECEIVE, then calls the function PROCESS_REQUEST
to handle any stored procedure request received from an NonStop ODBC Server.
When the number of openers reaches zero, this function calls the termination
functions provided for each of the stored procedures; it then stops the server
program.
process_request, process_service
These functions are responsible for processing a stored procedure request from an
NonStop ODBC Server and for invoking the relevant stored procedure function.
Developing a Stored Procedure in C
The basic programming paradigm used for stored procedures is the same as that used
for developing NonStop SQL/MP applications. The system uses SQLDA structures for
handling input parameters and for returning results to the client application. The
sample stored procedures provided give examples of how the SQLDA structures are
used. The remainder of this subsection describes the steps involved in the
development and installation of a stored procedure using the sample files provided.
The stored procedure SELECT_INPUT_DEPT and its source files SP21C and SP21H
are used as examples.