Главная страница | назад





Article #20179: How do I execute a stored procedure with TIBSQL?

QUESTION:

How do I execute a stored procedure with TIBSQL?

ANSWER:

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)
as
begin
newkey = gen_id(vote_pui_gen, 1);
end
For more information on creating stored procedures refer to the InterBase "Data Definition Guide", and "Programmer's Guide".
procedure TForm1.Button1Click(Sender: TObject);
begin
IBSQL1.SQL.Clear;
IBSQL1.SQL.Add('execute procedure new_key');
IBSQL1.ExecQuery;
Form1.Caption := IBSQL1.Current.Vars[0].AsString;
end;
If the procedure returns multiple parameters, you can iterate through the Vars array to extract all of the parameters.

Last Modified: 18-JAN-00