Show: Delphi C++
Display Preferences

FireDAC.Comp.Client.TFDRdbmsDataSet.Open

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

procedure Open(const ASQL: String); overload;
procedure Open(const ASQL: String; const AParams: array of Variant); overload;
procedure Open(const ASQL: String; const AParams: array of Variant;  const ATypes: array of TFieldType); overload;

C++

HIDESBASE void __fastcall Open(const System::UnicodeString ASQL)/* overload */;
HIDESBASE void __fastcall Open(const System::UnicodeString ASQL, const System::Variant *AParams, const int AParams_High)/* overload */;
HIDESBASE void __fastcall Open(const System::UnicodeString ASQL, const System::Variant *AParams, const int AParams_High, const Data::Db::TFieldType *ATypes, const int ATypes_High)/* overload */;
inline void __fastcall  Open(void){ Data::Db::TDataSet::Open(); }

Properties

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

Description

Executes the specified SQL statement.

Call Open to execute the SQL statement specified by ASQL or the one currently assigned to the internal command object if ASQL is empty.

This method is overloaded:

  • The first overloaded method executes the specified SQL statement and opens the dataset.
  • The second overloaded method executes the specified SQL statement with specified parameter values and opens the dataset.
  • The third overloaded method executes the specified SQL statement with specified parameter values and opens the dataset.

The method closes the dataset if it was active, then assigns ASQL to the command text and sets the Active property to True. When Active is True, the dataset is populated with data from a database. This method allows to specify the parameter values using positional parameter binding and exact parameter data types. If you need to leave the parameter data type unchanged, put ftUnknown into the array item corresponding to the parameter. 

When an application needs to execute the same SQL command many times, it may ordinarily set SQL property, call Prepare before calling Open for the first time, then use any Open version without specifying ASQL

Use ResourceOptions.CmdExecMode to control asynchronous execution mode and ResourceOptions.CmdExecTimeout to set the maximum command execution time. After that time, the command execution is cancelled and an exception is raised. 

To cancel the command execution, use TFDAdaptedDataSet.AbortJob.  When a DBMS returns an error, FireDAC raises an exception. See Handling Errors for details. In case of long string values and errors such as: 

 [FireDAC][Phys][ODBC]-345. Data too large for variable [P]. Max len = [8002], actual len = [18329]

  you have to specify ftMemo or ftBlob for the corresponding ('P') parameter. Alternatively, use the standard Open call and setup parameter data types and values separately.

Example

//Example 1:
FDQuery1.Open('select * from customers');

//Example 2:
FDQuery1.Open('select * from Employees where department_id = :id', [100]);
....
FDQuery1.Open('', [101]); // executes the above SQL command, but for ID = 101

//Example 3:
FDQuery1.Open('select * from Employees where department_id = :id', [100], [ftInteger]);

See Also

Personal tools
In Other Languages
Previous Versions
Assistance