Databases - Delphi Parameterized Queries

Parameterized queries serve the following purposes

Basic Details | Executing the query | Code Error


Basic Details

Parameters are identified in the sql statements by initial semicolons. This example writes 2 parameters to a table. These methods add parameters to the query component In general, you should test for the existance of a parameter before creating one (with the same name). The following method is based on the Delphi help.


Executing the query

When ParamCheck = true (the default value), writing an sql string to the component causes parameters to be added and/or removed. However, the existing parameters referenced in the string are not deleted or modified. If ParamCheck = false and the sql string contains parameters, then there is an
xsqlda index out of range
error - even if the number of parameters in the sql string matches the number of defined parameters.

Note: In methods, I frequently use self (which is never required) because it tells the IDE to display a list of properties and methods after you type the period. (Use Ctrl-Space to display the list if the period is already typed.)


Code Error

At one time, I tried code of the form What a disaster I discovered the error by turning on Debug DCU's and stepping through the code.


Author: Robert Clemenzi - clemenzi@cpcug.org
URL: http:// cpcug.org / user / clemenzi / technical / Databases / Delphi / QueryParameters.html