FireDAC.Comp.Client.TFDCustomQuery.SQL

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

property SQL: TStrings read GetSQL write SetSQL;

C++

__property System::Classes::TStrings* SQL = {read=GetSQL, write=SetSQL};

Properties

Type Visibility Source Unit Parent
property public
FireDAC.Comp.Client.pas
FireDAC.Comp.Client.hpp
FireDAC.Comp.Client TFDCustomQuery

Description

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

Use the 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 the FireDAC Query Editor dialog. For this, double-click the TFDCustomQuery component. The dialog offers a syntax highlighting editor, a query builder, an ability to test the query and other. 

The SQL property can contain an SQL command or a "batch" SQL command, consisting of several SQL commands or a block of code written in the server side programming language. To execute a full featured SQL script, use the TFDScript component. 

The SQL statement in the SQL property can also contain:

  • Parameter markers, following standard SQL-92 syntax conventions. Parameters are created automatically and stored in the Params property, if ResourceOptions.ParamCreate is True. If ParamBindMode is pbByName, then for all occurrences of the same marker a single item is created in Params. If ParamBindMode is pbByNumber, then one item is created 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 you to expand an SQL command conditionally, depending on the application defined attributes.

For details, see Preprocessing Command Text

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

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

Example

FDQuery1.SQL.BeginUpdate;
try
  FDQuery1.SQL.Add('SELECT ...');
  FDQuery1.SQL.Add('...');
  FDQuery1.SQL.Add('...');
  FDQuery1.SQL.Add('WHERE ID = :ID');
finally
  FDQuery1.SQL.EndUpdate;
end;
FDQuery1.ParamByName('ID').AsInteger := 100;
FDQuery1.Open;

See Also