FireDAC.Comp.Script.TFDScript.ExecuteAll

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

function ExecuteAll(AParser: TFDScriptParser): Boolean; overload;
function ExecuteAll: Boolean; overload;

C++

bool __fastcall ExecuteAll(TFDScriptParser* AParser)/* overload */;
bool __fastcall ExecuteAll(void)/* overload */;

Properties

Type Visibility Source Unit Parent
function public
FireDAC.Comp.Script.pas
FireDAC.Comp.Script.hpp
FireDAC.Comp.Script TFDScript

Description

Executes an SQL script.

Call the ExecuteAll method to execute the SQL script.

TFDScript allows you to execute a script from a file pointed by SQLScriptFileName, if it is specified. Otherwise, it allows you to execute a script from the SQL property of the item with a zero index from the SQLScripts collection.

The script is executed entirely, including all nested script calls. The script execution is stopped, if one of the following happens:

  • All script commands are processed.
  • The AbortJob method is called.
  • The Finished property is set to True.
  • The EXIT | QUIT | STOP command is found and processed in the script.
  • An exception is raised by one of the script commands, the IgnoreError option is False, and the BreakOnError option is True.

The exceptions raised at the script command executions are not propagated outside the ExecuteAll method. To check the script completion status, use:

  • The result value of the method. If it is True, then there were no errors. If it is False, then there was at least one error.
  • The TotalErrors property. It returns the total number of errors at script execution.
  • The Status property. It has the ssFinishWithErrors value, if there was any error, which stopped the script execution.

Before the execution, the BeforeExecute event handler is called. After the execution is finished, the AfterExecute event handler is called. A script execution may be nested. The BeforeScript event handler is called before the start up of every script. After a script is finished, the AfterScript event handler is called.

Alternatively, a script can be executed by the ExecuteFile or ExecuteScript methods.

Example 1

FDScript1.SQLScriptFileName := 'c:\temp\createdb.sql';
FDScript1.ExecuteAll;

Example 2

The following code shows how to wrap the script execution into a transaction:

FDConnection1.StartTransaction;
try
  FDScript1.ExecuteAll;
finally
  if FDScript1.TotalErrors > 0 then
    FDConnection1.Rollback
  else
    FDConnection1.Commit;
end;

See Also