Code Samples > RDBMS-Specific Examples > Sybase
 
Sybase
Stored Procedure Call
The sybproc example is a free adaptation of the Sybase example rpc.c. It is built with the files sybproc.cpp and ildutil.cpp.
*It declares a stored procedure whose arguments are all output arguments, except the first one.
*A call to that procedure is then parsed, the parameters bound, and their values supplied.
*After execution, the various result sets returned are fetched in a double loop.
*Finally, the parameters output values are printed.
This sample shows the restrictions that exist when calling stored procedures against a Sybase server:
*Despite the fact that the statement must be prepared using the function IldRequest::parse, it cannot be executed several times.
*The execute SQL reserved word is mandatory. It is used as the only indicator of a procedure call during the parsing phase. This is one of the few cases where DB Link needs to scan the query string,
If the procedure call only needs input parameters, you can simply use the IldRequest::execute function and pass the parameter values to the query string.
For example:
request->execute("sp_helpdb mydb");
Another Sybase-specific feature with regard to stored procedure calls is that the output parameter values cannot be accessed before all result sets have been completely fetched.
Error Due to Trigger Firing
The sybtrig example is built from the files sybtrig.cpp and ildutil.cpp. It illustrates how to capture an error raised in a trigger fired by a delete event.
This example creates a table with a trigger attached to the delete event and inserts a row in the table such that it is protected against deletion by the trigger.
Then, it tries to delete the row, which causes the trigger to be fired. The trigger sends a TransactSQL print statement, rolls back the transaction, and raises a user-defined error.
The print statement is received as an information message and it is turned into a warning by DB Link. The raiserror statement is actually returned as an error and is interpreted as such by DB Link.
Compute Clauses
The sybcomp example, made of the files sybcomp.cpp and ildutil.cpp, illustrates the use of the Sybase compute clause.
This example:
*Creates a table,
*Inserts a few rows in this table,
*Issues a select statement that includes two compute clauses:
*one for the minimum and maximum values of the column,
*one for the average value of the column.
The three fetch loops show that after the normal result set containing the fetched rows, there is one result set for each individual compute clause.

Version 5.8
Copyright © 2014, Rogue Wave Software, Inc. All Rights Reserved.