TDASQLMacroProcessor

Overview

The TDASQLMacroProcessor provides the base for classes that can process macros in SQL queries for different databases. It is part of the Macro Processor conception.

This class allows to use the following macros in SQL queries: * Date * DateTime * AddTime * FormatDateTime * FormatDate * Length * LowerCase * UpperCase * TrimLeft * TrimRight * Copy * NoLock

If you want to process an unknown macro, use the OnUnknownMacroVariable event of the TDAConnectionManager class.

procedure TServerDataModule.ConnectionManagerUnknownMacroVariable(
  Sender: TObject; const Name: string; var Value: string);
var ConnectionType:String;
begin
  ConnectionType := ConnectionManager.Connections.ConnectionByName(ConnectionManager.GetDefaultConnectionName).ConnectionType;
  if (ConnectionType = 'Interbase') then
  begin
    if (Name = 'MyUpperCase') then Value := 'Upper';
  end;
end;

Location

 

constructor Create  overload

Creates a new instance.

constructor Create

constructor Create (string, string, boolean, string)  overload

Creates a new instance with given parameters.

constructor Create(const aDateFormat: string; const aDateTimeFormat: string; aDoubleQuoteStrings: boolean; const aStoredProcParamsPrefix: string)

Parameters:

  • aDateFormat:
  • aDateTimeFormat:
  • aDoubleQuoteStrings:
  • aStoredProcParamsPrefix:

AddTime  protected virtual abstract

In the descendant, this method should process the AddTime macro.

function AddTime(Sender: TObject; const Parameters: array of string): string

Parameters:

  • Sender:
  • Parameters:

AddVariable    (declared in TROMacroParser)

Adds a variable.

function AddVariable(const Name: string): TROMacroVar

Parameters:

  • Name: variable name.

ClearProcs    (declared in TROMacroParser)

Clear all procedures.

procedure ClearProcs

ClearVariables    (declared in TROMacroParser)

Clear all variables.

procedure ClearVariables

Copy  protected virtual abstract

In the descendant, this method should process the Copy macro.

function Copy(Sender: TObject; const Parameters: array of string): string

Parameters:

  • Sender:
  • Parameters:

Date  protected virtual

In the descendant, this method should process the Date macro.

function Date(Sender: TObject; const Parameters: array of string): string

Parameters:

  • Sender:
  • Parameters:

DateFormat

Gets the date format for the current database.

property DateFormat: string read write

DateTime  protected virtual abstract

In the descendant, this method should process the DateTime macro.

function DateTime(Sender: TObject; const Parameters: array of string): string

Parameters:

  • Sender:
  • Parameters:

DateTimeFormat

Gets the datetime format for the current database.

property DateTimeFormat: string read write

DeleteVariable (Integer)  overload    (declared in TROMacroParser)

procedure DeleteVariable(I: Integer)

Parameters:

  • I:

DeleteVariable (TROMacroVar)  overload    (declared in TROMacroParser)

procedure DeleteVariable(aVariable: TROMacroVar)

Parameters:

  • aVariable:

DoubleQuoteStrings

Gets the quote string for the date and datetime formats for the current database. If this property is true, the datetime format is represented as "datetime", otherwise as 'datetime'.

property DoubleQuoteStrings: boolean read write

DoUnknownIdentifier  protected virtual

Fires OnUnknownIdentifier and OnDAServiceUnknownIdentifier events.

function DoUnknownIdentifier(Sender: TObject; const Name: string; const OrgName: string; var Value: string): Boolean

Parameters:

  • Sender: Sender
  • Name: name of variable
  • OrgName: original name of variable
  • Value: value

Eval    (declared in TROMacroParser)

Evaluates the given text.

function Eval(const Text: string; TextDelimiter: char): string

Parameters:

  • Text:
  • TextDelimiter:

EvalToken    (declared in TROMacroParser)

Evaluates a token.

function EvalToken(const Text: string): string

Parameters:

  • Text:

FormatDate  protected virtual

Returns the formatted date according to the DoubleQuoteStrings and DateFormat properties.

function FormatDate(Sender: TObject; const Parameters: array of string): string

Parameters:

  • Sender:
  • Parameters:

FormatDateTime  protected virtual

Returns the formatted date and time according to the DoubleQuoteStrings and DateFormat properties.

function FormatDateTime(Sender: TObject; const Parameters: array of string): string

Parameters:

  • Sender:
  • Parameters:

IndexOfName    (declared in TROMacroParser)

Returns the position of the first name-value pair with the specified name.

function IndexOfName(const aName: string): integer

Parameters:

  • aName: specified name

Length  protected virtual abstract

In the descendant, this method should process the Length macro.

function Length(Sender: TObject; const Parameters: array of string): string

Parameters:

  • Sender:
  • Parameters:

LowerCase  protected virtual abstract

In the descendant, this method should process the LowerCase macro.

function LowerCase(Sender: TObject; const Parameters: array of string): string

Parameters:

  • Sender:
  • Parameters:

NoLock  protected virtual abstract

In the descendant, this method should process the Nolock macro.

function NoLock(Sender: TObject; const Parameters: array of string): string

Parameters:

  • Sender:
  • Parameters:

OnDAServiceUnknownIdentifier

This event is fired when an unknown variable is detected. TDataAbstractService sets this events.

property OnDAServiceUnknownIdentifier: TOnUnknownIdentifier read write
delegate: function OnDAServiceUnknownIdentifier(Sender: TObject; const Name: string; const OrgName: string; var Value: string): Boolean

OnUnknownIdentifier

This event is fired when an unknown variable is detected.

property OnUnknownIdentifier: TOnUnknownIdentifier read write
delegate: function OnUnknownIdentifier(Sender: TObject; const Name: string; const OrgName: string; var Value: string): Boolean

RegisterMacros  protected virtual

Registers the existing standard macros: * Date * DateTime * AddTime * FormatDateTime * FormatDate * Length * LowerCase * UpperCase * TrimLeft * TrimRight * Copy * NoLock

procedure RegisterMacros

RegisterProc    (declared in TROMacroParser)

Registers a procedure.

procedure RegisterProc(const Name: string; ExProc: TExternalProc; aParamCount: integer)

Parameters:

  • Name:
  • ExProc:
  • aParamCount:

Session  protected

function Session(Sender: TObject; const Parameters: array of string): string

Parameters:

  • Sender:
  • Parameters:

StoredProcedurePrefix

Gets the prefix for stored procedures for the current database.

property StoredProcedurePrefix: string read write

StoredProcParamPrefix

Gets the prefix for stored procedure params for the current database.

property StoredProcParamPrefix: string read write

TrimLeft  protected virtual abstract

In the descendant, this method should process the TrimLeft macro.

function TrimLeft(Sender: TObject; const Parameters: array of string): string

Parameters:

  • Sender:
  • Parameters:

TrimRight  protected virtual abstract

In the descendant, this method should process the TrimRight macro.

function TrimRight(Sender: TObject; const Parameters: array of string): string

Parameters:

  • Sender:
  • Parameters:

UpperCase  protected virtual abstract

In the descendant, this method should process the UpperCase macro.

function UpperCase(Sender: TObject; const Parameters: array of string): string

Parameters:

  • Sender:
  • Parameters:

Variable    (declared in TROMacroParser)

Returns the registered variable.

property Variable[I: Integer]: TROMacroVar read write

VariableCount    (declared in TROMacroParser)

Returns the count of variables.

property VariableCount: Integer read write

 

DateFormat

Gets the date format for the current database.

property DateFormat: string read write

DateTimeFormat

Gets the datetime format for the current database.

property DateTimeFormat: string read write

DoubleQuoteStrings

Gets the quote string for the date and datetime formats for the current database. If this property is true, the datetime format is represented as "datetime", otherwise as 'datetime'.

property DoubleQuoteStrings: boolean read write

StoredProcedurePrefix

Gets the prefix for stored procedures for the current database.

property StoredProcedurePrefix: string read write

StoredProcParamPrefix

Gets the prefix for stored procedure params for the current database.

property StoredProcParamPrefix: string read write

Variable    (declared in TROMacroParser)

Returns the registered variable.

property Variable[I: Integer]: TROMacroVar read write

VariableCount    (declared in TROMacroParser)

Returns the count of variables.

property VariableCount: Integer read write

 

constructor Create  overload

Creates a new instance.

constructor Create

constructor Create (string, string, boolean, string)  overload

Creates a new instance with given parameters.

constructor Create(const aDateFormat: string; const aDateTimeFormat: string; aDoubleQuoteStrings: boolean; const aStoredProcParamsPrefix: string)

Parameters:

  • aDateFormat:
  • aDateTimeFormat:
  • aDoubleQuoteStrings:
  • aStoredProcParamsPrefix:

AddTime  protected virtual abstract

In the descendant, this method should process the AddTime macro.

function AddTime(Sender: TObject; const Parameters: array of string): string

Parameters:

  • Sender:
  • Parameters:

AddVariable    (declared in TROMacroParser)

Adds a variable.

function AddVariable(const Name: string): TROMacroVar

Parameters:

  • Name: variable name.

ClearProcs    (declared in TROMacroParser)

Clear all procedures.

procedure ClearProcs

ClearVariables    (declared in TROMacroParser)

Clear all variables.

procedure ClearVariables

Copy  protected virtual abstract

In the descendant, this method should process the Copy macro.

function Copy(Sender: TObject; const Parameters: array of string): string

Parameters:

  • Sender:
  • Parameters:

Date  protected virtual

In the descendant, this method should process the Date macro.

function Date(Sender: TObject; const Parameters: array of string): string

Parameters:

  • Sender:
  • Parameters:

DateTime  protected virtual abstract

In the descendant, this method should process the DateTime macro.

function DateTime(Sender: TObject; const Parameters: array of string): string

Parameters:

  • Sender:
  • Parameters:

DeleteVariable (Integer)  overload    (declared in TROMacroParser)

procedure DeleteVariable(I: Integer)

Parameters:

  • I:

DeleteVariable (TROMacroVar)  overload    (declared in TROMacroParser)

procedure DeleteVariable(aVariable: TROMacroVar)

Parameters:

  • aVariable:

DoUnknownIdentifier  protected virtual

Fires OnUnknownIdentifier and OnDAServiceUnknownIdentifier events.

function DoUnknownIdentifier(Sender: TObject; const Name: string; const OrgName: string; var Value: string): Boolean

Parameters:

  • Sender: Sender
  • Name: name of variable
  • OrgName: original name of variable
  • Value: value

Eval    (declared in TROMacroParser)

Evaluates the given text.

function Eval(const Text: string; TextDelimiter: char): string

Parameters:

  • Text:
  • TextDelimiter:

EvalToken    (declared in TROMacroParser)

Evaluates a token.

function EvalToken(const Text: string): string

Parameters:

  • Text:

FormatDate  protected virtual

Returns the formatted date according to the DoubleQuoteStrings and DateFormat properties.

function FormatDate(Sender: TObject; const Parameters: array of string): string

Parameters:

  • Sender:
  • Parameters:

FormatDateTime  protected virtual

Returns the formatted date and time according to the DoubleQuoteStrings and DateFormat properties.

function FormatDateTime(Sender: TObject; const Parameters: array of string): string

Parameters:

  • Sender:
  • Parameters:

IndexOfName    (declared in TROMacroParser)

Returns the position of the first name-value pair with the specified name.

function IndexOfName(const aName: string): integer

Parameters:

  • aName: specified name

Length  protected virtual abstract

In the descendant, this method should process the Length macro.

function Length(Sender: TObject; const Parameters: array of string): string

Parameters:

  • Sender:
  • Parameters:

LowerCase  protected virtual abstract

In the descendant, this method should process the LowerCase macro.

function LowerCase(Sender: TObject; const Parameters: array of string): string

Parameters:

  • Sender:
  • Parameters:

NoLock  protected virtual abstract

In the descendant, this method should process the Nolock macro.

function NoLock(Sender: TObject; const Parameters: array of string): string

Parameters:

  • Sender:
  • Parameters:

RegisterMacros  protected virtual

Registers the existing standard macros: * Date * DateTime * AddTime * FormatDateTime * FormatDate * Length * LowerCase * UpperCase * TrimLeft * TrimRight * Copy * NoLock

procedure RegisterMacros

RegisterProc    (declared in TROMacroParser)

Registers a procedure.

procedure RegisterProc(const Name: string; ExProc: TExternalProc; aParamCount: integer)

Parameters:

  • Name:
  • ExProc:
  • aParamCount:

Session  protected

function Session(Sender: TObject; const Parameters: array of string): string

Parameters:

  • Sender:
  • Parameters:

TrimLeft  protected virtual abstract

In the descendant, this method should process the TrimLeft macro.

function TrimLeft(Sender: TObject; const Parameters: array of string): string

Parameters:

  • Sender:
  • Parameters:

TrimRight  protected virtual abstract

In the descendant, this method should process the TrimRight macro.

function TrimRight(Sender: TObject; const Parameters: array of string): string

Parameters:

  • Sender:
  • Parameters:

UpperCase  protected virtual abstract

In the descendant, this method should process the UpperCase macro.

function UpperCase(Sender: TObject; const Parameters: array of string): string

Parameters:

  • Sender:
  • Parameters:

 

OnDAServiceUnknownIdentifier

This event is fired when an unknown variable is detected. TDataAbstractService sets this events.

property OnDAServiceUnknownIdentifier: TOnUnknownIdentifier read write
delegate: function OnDAServiceUnknownIdentifier(Sender: TObject; const Name: string; const OrgName: string; var Value: string): Boolean

OnUnknownIdentifier

This event is fired when an unknown variable is detected.

property OnUnknownIdentifier: TOnUnknownIdentifier read write
delegate: function OnUnknownIdentifier(Sender: TObject; const Name: string; const OrgName: string; var Value: string): Boolean

See Also