FireDAC.Comp.Client.TFDCustomConnection.ExecSQLScalar
| [–] Properties | |
|---|---|
| Type: function | |
| Visibility: public | |
| Source: FireDAC.Comp.Client.pas FireDAC.Comp.Client.hpp | |
| Unit: FireDAC.Comp.Client | |
| Parent: TFDCustomConnection | |
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, const System::Variant *AParams, const System::NativeInt AParams_High)/* overload */;
System::Variant __fastcall ExecSQLScalar(const System::UnicodeString ASQL, const System::Variant *AParams, const System::NativeInt AParams_High, const Data::Db::TFieldType *ATypes, const System::NativeInt ATypes_High)/* overload */;
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 ASQLparameter represents the SQL command to execute.
- The second overloaded method executes a SQL command with parameters. All the other cursors are discarded. The AParamsparameter 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 ATypesmust beftUnknown.
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]);