AnyDAC
ContentsIndexHome
PreviousUpNext
TADCustomQuery.SQL Property

Contains the text of the SQL statement to execute for the query.

Group
Links

Use SQL property to specify the SQL command that a query will Execute / ExecSQL / Open. 

At design time the SQL property can be edited by invoking AnyDAC Query Editor dialog. For that double click on TADCustomQuery component. The dialog offers syntax hilighting editor, query builder, ability to test query and other. 

The SQL property may contain one SQL command or "batch" SQL command, consisting from few SQL command or server side programming language block of code. To execute full featured SQL script use the TADScript component. 

The SQL statement in the SQL property may contain also:

  • parameter markers, following standard SQL-92 syntax conventions. Parameters are created automatically and stored in the Params property, if ResourceOptions.ParamCreate is True. If ParamBindModeis pbByName, then for all occurrences of the same marker will be created single item in Params. If pbByNumber, then - one item per each marker.
  • substitution variable markers. Macros are created automatically and stored in the Macros property, if ResourceOptions.MacroCreate is True.
  • escape sequences. They allow writing DBMS independent SQL commands.
  • conditional substitutions. They allow expand SQL command conditionally, depending on application defined attributes

For details see Preprocessing Command Text

To improove performance on adding big SQL queries to the property using TStringList methods, surround this code into SQL.BeginUpdate / SQL.EndUpdate. 

After filling this property value the Param collection will be filled automatically, if ResourceOptions.ParamCreate is True.

property SQL: TStrings;
ADQuery1.SQL.BeginUpdate;
try
  ADQuery1.SQL.Add('SELECT ...');
  ADQuery1.SQL.Add('...');
  ADQuery1.SQL.Add('...');
  ADQuery1.SQL.Add('WHERE ID = :ID');
finally
  ADQuery1.SQL.EndUpdate;
end;
ADQuery1.ParamByName('ID').AsInteger := 100;
ADQuery1.Open;
What do you think about this topic? Send feedback!