Preparing and Executing a Stored Procedure
From InterBase
Go Up to Using a Stored Procedure
To use a stored procedure, you can optionally prepare it, and then execute it.
You can prepare a stored procedure at:
- Design time, by choosing OK in the Parameters editor.
- Runtime, by calling the
Prepare
method of the stored procedure component.
For example, the following code prepares a stored procedure for execution:
IBStoredProc1.Prepare;
Note:
If your application changes parameter information at runtime, you should prepare the procedure again.
If your application changes parameter information at runtime, you should prepare the procedure again.
To execute a prepared stored procedure, call the ExecProc method for the stored procedure component. The following code illustrates code that prepares and executes a stored procedure:
IBStoredProc1.Params[0].AsString := Edit1.Text; IBStoredProc1.Prepare; IBStoredProc1.ExecProc;
Note:
If you attempt to execute a stored procedure before preparing it, the stored procedure component automatically prepares it for you, and then unprepares it after it executes. If you plan to execute a stored procedure a number of times, it is more efficient to call
If you attempt to execute a stored procedure before preparing it, the stored procedure component automatically prepares it for you, and then unprepares it after it executes. If you plan to execute a stored procedure a number of times, it is more efficient to call
Prepare
yourself, and then only call UnPrepare
once, when you no longer need to execute the procedure.When you execute a stored procedure, it can return all or some of these items:
- A dataset consisting of one or more records that can be viewed in data-aware controls associated with the stored procedure through a data source component.
- Output parameters.
- A result parameter that contains status information about the stored procedure’s execution.