TADScript allows to extend the set of SQL script control execution commands.
The set of the script control execution commands may be extended by the custom commands. You can find the sources of the existing commands in the uADCompScriptCommands unit and use them as a template for your own commands. The command class must be registered at the commands registry. For example, the SPOOL command code:
type TADSpoolScriptCommand = class(TADScriptCommand) private FMode: Integer; FFileName: String; FAppend: Boolean; public class function Help(): String; override; class procedure Keywords(AKwds: TStrings); override; function Parse(const AKwd: String): Boolean; override; procedure Execute(); override; // -1 - off, 0 - show, 1 - file property Mode: Integer read FMode; property Append: Boolean read FAppend; property FileName: String read FFileName; end; {-------------------------------------------------------------------------------} class function TADSpoolScriptCommand.Help(): String; begin Result := '(SPOol | OUTput) [OFF|[APPend] <spool name>] - turns spooling off, print it status'#13#10 + ' or redirect it to the name'; end; {-------------------------------------------------------------------------------} class procedure TADSpoolScriptCommand.Keywords(AKwds: TStrings); begin AKwds.Add('SPOol'); AKwds.Add('OUTput'); end; {-------------------------------------------------------------------------------} function TADSpoolScriptCommand.Parse(const AKwd: String): Boolean; var iLastBmk: Integer; ucS: string; begin iLastBmk := Parser.GetBookmark; ucS := Parser.GetUCWord; if ucS = 'OFF' then FMode := -1 else if ucS = '' then FMode := 0 else begin FMode := 1; FAppend := ADKeyWordMatch(ucS, 'APPEND', 3); if not FAppend then Parser.SetBookmark(iLastBmk); FFileName := Parser.GetLine(); if FFileName = '' then FMode := -1; end; Result := True; end; {-------------------------------------------------------------------------------} procedure TADSpoolScriptCommand.Execute(); begin case FMode of -1: begin Engine.ScriptOptions.SpoolOutput := smNone; EngineIntf.UpdateSpool; end; 0: if Engine.ScriptOptions.SpoolOutput <> smNone then EngineIntf.ConPut('currently spooling to ' + Engine.ScriptOptions.SpoolFileName, soInfo) else EngineIntf.ConPut('not spooling currently', soInfo); 1: begin if FAppend then Engine.ScriptOptions.SpoolOutput := smOnAppend else Engine.ScriptOptions.SpoolOutput := smOnReset; Engine.ScriptOptions.SpoolFileName := EngineIntf.ExpandString(FileName); EngineIntf.UpdateSpool; end; end; end; initialization ADScriptCommandRegistry().AddCommand(TADSpoolScriptCommand);
|
What do you think about this topic? Send feedback!
|