Rogue Wave banner
Previous fileTop of DocumentContentsIndexNext file

2.6 Stored Procedures

This DBTools.h++ access library includes full support for SQL Server stored procedures, including support for creating and dropping stored procedures, retrieving stored procedure text and parameter definitions, executing stored procedures, processing multiple result sets, processing output parameters, and processing return values.

Stored procedures are encapsulated by class RWDBStoredProc. The implementation uses the dbrpcxxx() family of DB-Library calls, which allows parameters to be passed as native datatypes, rather than as text. The DB-Library documentation indicates that passing parameters as native datatypes is the most efficient way to handle stored procedures.

2.6.1 Creating a Stored Procedure

Stored procedures can be created by calling the createProcedure() method of RWDBDatabase. DBTools.h++ will create the parameter list from a schema you supply, while the body of the stored procedure is supplied by the application. Here is a simple example, which looks up a royalty percentage and returns the royalty schedule based on title and sales level:

2.6.2 Executing Stored Procedures

DB-Library stored procedures are quite complete, compared to other database vendors. An application has the option of processing return parameters, a return status, and/or the results of selects performed by the stored procedure. It is very important that the application perform the correct sequence of processing in order to successfully process each part of a stored procedure as it is returned from the SQL server.

Because of the way that DB-Library handles result sets and return values, your applications must always process the result set before they call RWDBStoredProc::returnValue(). Calling the function before processing the result set will generate an empty reader.

The following code is an example of properly processing the different parts of the stored procedure. We'll use the procedure shown in Section 2.6.1, "Creating a Stored Procedure."

2.6.3 Fetching Stored Procedure Parameters

Please note that when retrieving stored procedures from the Sybase DB-Library database, you won't be able to determine if a parameter is an input, an output, or an inout parameter. The system table does not carry this information.

2.6.4 Instantiating an RWDBStoredProcedure Using Schema Data

The member function:

increases the performance of stored procedures by eliminating the usual parameter fetch required for instantiation. The schema must include the name and type of each parameter in the stored procedure. For example, the code in Section 2.6.1 uses the schema params to create the stored procedure; params could be used to instantiate an RWDBStoredProc. The paramType field is not necessary, but the name of each column /parameter in the schema must match the stored procedure parameter name exactly.


Previous fileTop of DocumentContentsIndexNext file

©Copyright 1999, Rogue Wave Software, Inc.
Contact Rogue Wave about documentation or support issues.