FireDAC.Comp.DataSet.TFDDataSet.OpenOrExecute

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

function OpenOrExecute: Boolean;

C++

bool __fastcall OpenOrExecute();

Properties

Type Visibility Source Unit Parent
function public
FireDAC.Comp.DataSet.pas
FireDAC.Comp.DataSet.hpp
FireDAC.Comp.DataSet TFDDataSet

Description

Executes an SQL command and optionally opens the dataset.

Use the OpenOrExecute method if you do not know whether the command will return a result set or not. The most common case for that is the execution of an ad-hoc query. 

The OpenOrExecute method executes an SQL command. If the command returns any result set, then OpenOrExecute opens the dataset. The method supplements the Open and Execute, ExecSQL, or ExecProc method:

  • The Open method raises an exception ("[FireDAC][Phys]-308. Command must return row set") if a command does not return the result set like the INSERT command.
  • The Execute, ExecSQL, and ExecProc methods raise an exception ("[FireDAC][Phys]-310. Cannot execute command returning results set") if a command returns result the result set like the SELECT command.

When calling OpenOrExecute, a "[FireDAC][Phys]-308" exception might be raised, but it is not propagated out of the method.

Example

FDQuery1.Disconnect(True);
FDQuery1.SQL.Assign(Memo1.Lines);
if FDQuery1.OpenOrExecute then begin
  PageControl1.ActivePage := DataGridPage;
  DataGridPage.TabVisible := True;
end
else
  DataGridPage.TabVisible := False;

See Also