How do I execute a stored procedure with TIBSQL?

By: Gardner Bickford

Abstract: Executing a stored procedure with TIBSQL.


How do I execute a stored procedure with TIBSQL?


To take advantage of the light weight TIBSQL component for executing stored procedures, execute the procedure with the SQL statement 'execute procedure procedure_name'. The results are passed back through a TIBXSQLDA object. A TIBXSQLDA is an object which encapsulates an InterBase API data type and contains all of the return parameters for the stored procedure. TIBSQL.Current returns the current TIBXSQLDA object associated with the TIBSQL.

The following code example executes a stored procedure, new_key, that does not take any parameters but does return a value. The 'new_key' procedure is defined as follows:
create procedure new_key returns (newkey integer)
  newkey = gen_id(vote_pui_gen, 1);
For more information on creating stored procedures refer to the InterBase "Data Definition Guide", and "Programmer's Guide".
procedure TForm1.Button1Click(Sender: TObject);
  IBSQL1.SQL.Add('execute procedure new_key');
  Form1.Caption := IBSQL1.Current.Vars[0].AsString;
If the procedure returns multiple parameters, you can iterate through the Vars array to extract all of the parameters.

Server Response from: ETNASC04