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
- Unit: uDASQLMacroProcessor.pas
- Ancestry: TInterfacedObject | TROMacroParser | TDASQLMacroProcessor
constructor Create overload
Creates a new instance.
constructor Create
constructor Create (string, string, Boolean, string, string) overload
constructor Create(const aDateFormat: string; const aDateTimeFormat: string; aDoubleQuoteStrings: Boolean; const aStoredProcParamsPrefix: string; const aModFormat: string)
Parameters:
- aDateFormat:
- aDateTimeFormat:
- aDoubleQuoteStrings:
- aStoredProcParamsPrefix:
- aModFormat:
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.
AllowComplexIdent protected (declared in TROMacroParser)
property AllowComplexIdent: Boolean read write
AllowDoubleQuotedIdent protected (declared in TROMacroParser)
property AllowDoubleQuotedIdent: Boolean read write
ClearProcs (declared in TROMacroParser)
Clear all procedures.
procedure ClearProcs
ClearVariables (declared in TROMacroParser)
Clear all variables.
procedure ClearVariables
ComposeMacroCall
function ComposeMacroCall(aMacroKind: MacroKind; Parameters: array of string): string
Parameters:
- aMacroKind:
- Parameters:
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
DatePart protected virtual abstract
In the descendant, this method should process the DatePart macro.
function DatePart(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:
DateTimeFormat
Gets the datetime format for the current database.
property DateTimeFormat: string read
DeleteVariable (TROMacroVar) overload (declared in TROMacroParser)
procedure DeleteVariable(aVariable: TROMacroVar)
Parameters:
- aVariable:
DeleteVariable (Integer) overload (declared in TROMacroParser)
procedure DeleteVariable(I: Integer)
Parameters:
- I:
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
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:
ModFormat
property ModFormat: string read
Modulo protected
function Modulo(Sender: TObject; const Parameters: array of string): string
Parameters:
- Sender:
- Parameters:
NoLock protected virtual
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
OpenBlockEscape protected (declared in TROMacroParser)
property OpenBlockEscape: Boolean read write
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
In the descendant, this method should process the Session macro.
it allows to read value of variable stored inside session
usage:
{SESSION(variablename)}
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
StoredProcParamPrefix
Gets the prefix for stored procedure params for the current database.
property StoredProcParamPrefix: string read
Time protected virtual
In the descendant, this method should process the Time macro.
function Time(Sender: TObject; const Parameters: array of string): string
Parameters:
- Sender:
- Parameters:
Trim protected virtual abstract
In the descendant, this method should process the Trim macro.
function Trim(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:
Variable (declared in TROMacroParser)
Returns the registered variable.
property Variable[I: Integer]: TROMacroVar read
VariableCount (declared in TROMacroParser)
Returns the count of variables.
property VariableCount: Integer read
AllowComplexIdent protected (declared in TROMacroParser)
property AllowComplexIdent: Boolean read write
AllowDoubleQuotedIdent protected (declared in TROMacroParser)
property AllowDoubleQuotedIdent: Boolean read write
DateFormat
Gets the date format for the current database.
property DateFormat: string read
DateTimeFormat
Gets the datetime format for the current database.
property DateTimeFormat: string read
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
ModFormat
property ModFormat: string read
OpenBlockEscape protected (declared in TROMacroParser)
property OpenBlockEscape: Boolean read write
StoredProcedurePrefix
Gets the prefix for stored procedures for the current database.
property StoredProcedurePrefix: string read
StoredProcParamPrefix
Gets the prefix for stored procedure params for the current database.
property StoredProcParamPrefix: string read
Variable (declared in TROMacroParser)
Returns the registered variable.
property Variable[I: Integer]: TROMacroVar read
VariableCount (declared in TROMacroParser)
Returns the count of variables.
property VariableCount: Integer read
constructor Create overload
Creates a new instance.
constructor Create
constructor Create (string, string, Boolean, string, string) overload
constructor Create(const aDateFormat: string; const aDateTimeFormat: string; aDoubleQuoteStrings: Boolean; const aStoredProcParamsPrefix: string; const aModFormat: string)
Parameters:
- aDateFormat:
- aDateTimeFormat:
- aDoubleQuoteStrings:
- aStoredProcParamsPrefix:
- aModFormat:
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
ComposeMacroCall
function ComposeMacroCall(aMacroKind: MacroKind; Parameters: array of string): string
Parameters:
- aMacroKind:
- Parameters:
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:
DatePart protected virtual abstract
In the descendant, this method should process the DatePart macro.
function DatePart(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 (TROMacroVar) overload (declared in TROMacroParser)
procedure DeleteVariable(aVariable: TROMacroVar)
Parameters:
- aVariable:
DeleteVariable (Integer) overload (declared in TROMacroParser)
procedure DeleteVariable(I: Integer)
Parameters:
- I:
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:
Modulo protected
function Modulo(Sender: TObject; const Parameters: array of string): string
Parameters:
- Sender:
- Parameters:
NoLock protected virtual
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
In the descendant, this method should process the Session macro.
it allows to read value of variable stored inside session
usage:
{SESSION(variablename)}
function Session(Sender: TObject; const Parameters: array of string): string
Parameters:
- Sender:
- Parameters:
Time protected virtual
In the descendant, this method should process the Time macro.
function Time(Sender: TObject; const Parameters: array of string): string
Parameters:
- Sender:
- Parameters:
Trim protected virtual abstract
In the descendant, this method should process the Trim macro.
function Trim(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