FireDAC.Comp.Client.TFDCustomConnection.ExecSQL

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

function ExecSQL(const ASQL: String; AIgnoreObjNotExists: Boolean = False): LongInt; overload;
function ExecSQL(const ASQL: String; const AParams: array of Variant): LongInt; overload;
function ExecSQL(const ASQL: String; const AParams: array of Variant;  const ATypes: array of TFieldType): LongInt; overload;
function ExecSQL(const ASQL: String; AParams: TFDParams): LongInt; overload;
function ExecSQL(const ASQL: String; AParams: TFDParams; var AResultSet: TDataSet): LongInt; overload;

C++

int __fastcall ExecSQL(const System::UnicodeString ASQL, bool AIgnoreObjNotExists = false)/* overload */;
int __fastcall ExecSQL(const System::UnicodeString ASQL, System::Variant const *AParams, const int AParams_High)/* overload */;
int __fastcall ExecSQL(const System::UnicodeString ASQL, System::Variant const *AParams, const int AParams_High, Data::Db::TFieldType const *ATypes, const int ATypes_High)/* overload */;
int __fastcall ExecSQL(const System::UnicodeString ASQL, Firedac::Stan::Param::TFDParams* AParams)/* overload */;
int __fastcall ExecSQL(const System::UnicodeString ASQL, Firedac::Stan::Param::TFDParams* AParams, Data::Db::TDataSet* &AResultSet)/* overload */;

Properties

Type Visibility Source Unit Parent
function public
FireDAC.Comp.Client.pas
FireDAC.Comp.Client.hpp
FireDAC.Comp.Client TFDCustomConnection

Description

Executes a SQL command and returns the number of affected rows.

The ExecSQL method is overloaded:

  • The first overloaded method executes a SQL command without any parameters. The ASQL parameter represents the SQL command to execute.
    • When AIgnoreObjNotExists is True, then the method ignores (hides) "object does not exist" exceptions. This is at first useful at calling "DROP ... " SQL commands, when a DBMS does not support "DROP IF EXISTS ..." syntax. By default, the method propagates all exceptions.
  • The second overloaded method executes a SQL command with parameters. All the returned cursors are discarded. The AParams parameter represents an open array of parameter values.
  • The third overloaded method executes a SQL command with parameters. All the returned cursors are discarded. The method allows to explicitly specify parameter types. If a parameter type is not needed to be specified, then the corresponding item in ATypes must be ftUnknown.

Example

FDConnection1.ExecSQL('truncate table tab1');
FDConnection1.ExecSQL('drop table tab2', True);
FDConnection1.ExecSQL('delete from mytab where id > :p1', [1000]);
FDConnection1.ExecSQL('update mytab where id = :p1 set blobfld = :blb',
  [1000, StringOfChar('x', 100000)], [ftInteger, ftBLOB]);

See Also