FireDAC.Comp.Client.TFDCustomConnection.ExecSQLScalar

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

function ExecSQLScalar(const ASQL: String): Variant; overload;
function ExecSQLScalar(const ASQL: String; const AParams: array of Variant): Variant; overload;
function ExecSQLScalar(const ASQL: String; const AParams: array of Variant;  const ATypes: array of TFieldType): Variant; overload;

C++

System::Variant __fastcall ExecSQLScalar(const System::UnicodeString ASQL)/* overload */;
System::Variant __fastcall ExecSQLScalar(const System::UnicodeString ASQL, System::Variant const *AParams, const int AParams_High)/* overload */;
System::Variant __fastcall ExecSQLScalar(const System::UnicodeString ASQL, System::Variant const *AParams, const int AParams_High, Data::Db::TFieldType const *ATypes, const int ATypes_High)/* 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.

ExecSQLScalar returns the value of the first column in the first row of the first result set.

The ExecSQL method is overloaded:

  • The first overloaded method executes a SQL command without any parameters. All the other cursors are discarded. The ASQL parameter represents the SQL command to execute.
  • The second overloaded method executes a SQL command with parameters. All the other 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 other cursors are discarded. The method allows to explicitly specify parameter types. If the type of a parameter is not needed to be specified, then the corresponding item in ATypes must be ftUnknown.

Example

var
  sVersion: String;
  sName: String;
  sName2: String;
...
  sVersion := FDConnection1.ExecSQLScalar('select @@version');
  sName := FDConnection1.ExecSQLScalar('select name from {id Employees} where id = :id', [100]);
  sName2 := FDConnection1.ExecSQLScalar('select name from {id Employees} where id = :id', [100], [ftLargeInt]);

See Also