Setting parameters

From InterBase
Jump to: navigation, search

Go Up to Working with Queries


A parameterized SQL statement contains parameters, or variables, the values of which can be varied at design time or runtime. Parameters can replace data values, such as those used in a WHERE clause for comparisons, that appear in a SQL statement. Ordinarily, parameters stand in for data values passed to the statement. For example, in the following INSERT statement, values to insert are passed as parameters:

INSERT INTO Country (Name, Capital, Population)
VALUES (:Name, :Capital, :Population)

In this SQL statement, <:name>, <:capital>, and <:population> are placeholders for actual values supplied to the statement at runtime by your application. Before a parameterized query is executed for the first time, your application should call the Prepare method to bind the current values for the parameters to the SQL statement. Binding means that the server allocates resources for the statement and its parameters that improve the execution speed of the query.

with IBQuery1 do begin
  Close;
  Unprepare;
  ParamByName(‘Name’).AsString := ‘Belize’;
  ParamByName(‘Capital’).AsString := ‘Belmopan’;
  ParamByName(‘Population’).AsInteger := ‘240000’;
  Prepare;
  Open;
end;

Topics