TDAWhere
Overview
The TDAWhere class is used to dynamically build WHERE statements.
Location
- Unit: uDAPlainWhere.pas
- Ancestry: TDAWhere
constructor Create
Creates a new instance.
constructor Create(const aFields: TDACustomFieldCollection; aClientFields: Boolean)
Parameters:
- aFields: Field collection.
- aClientFields: see ClientFields
AddCondition (string, TDASQLCondition): Boolean overload
Adds a new condition to the WHERE clause. If no Operator was added previously, the new condition will be connected to the existing clause (if any) using the DefaultOperator.
function AddCondition(const FieldName: string; Condition: TDASQLCondition): Boolean
Parameters:
- FieldName: field name.
- Condition: condition.
AddCondition (string, TDASQLCondition, Variant, Boolean): Boolean overload
Adds a new condition to the WHERE clause. If no Operator was added previously, the new condition will be connected to the existing clause (if any) using the DefaultOperator.
function AddCondition(const FieldName: string; Condition: TDASQLCondition; const Value: Variant; SkipIfEmptyValue: Boolean): Boolean
Parameters:
- FieldName: field name.
- Condition: condition.
- Value: value.
- SkipIfEmptyValue: allows to skip adding condition if value is empty.
AddConditions
Adds a number of new conditions to the WHERE clause. If no Operator was added previously, the new condition will be connected to the existing clause (if any) using the DefaultOperator.
function AddConditions(const FieldNames: array of string; const Conditions: array of TDASQLCondition; const Values: array of Variant; const Operator: TDASQLOperator): Integer
Parameters:
- FieldNames: array of field names.
- Conditions: array of conditions.
- Values: array of values.
- Operator: operator.
AddOperator
Adds a new operator to the WHERE clause, to connect the previous condition with the next one.
procedure AddOperator(aOperator: TDASQLOperator)
Parameters:
- aOperator: operator.
AddSpaces
Adds specific number of spaces
procedure AddSpaces(Count: Integer)
Parameters:
- Count: count of spaces.
AddText
Adds a plain text SQL to the WHERE clause. If no Operator was added previously, the new condition will be connected to the existing clause (if any) using the DefaultOperator.
procedure AddText(const someText: string; MapClientFields: Boolean)
Parameters:
- someText: SQL
- MapClientFields: allows to perform remap field names in SQL
AddValueGroup
Adds an SQL "IN" condition to the WHERE clause. If no Operator was added previously, the new condition will be connected to the existing clause (if any) using the DefaultOperator.
procedure AddValueGroup(const FieldName: string; const Values: array of Variant)
Parameters:
- FieldName: field name.
- Values: values.
Changed
Returns true if the WHERE clause has been changed. This property will not reset to false automatically, but code using the TDAWhere class may set it to false externally after reacting to changes, to keep track of whether the clause changes again. For example, the IDASQLCommand implementations will set this to false when preparing the command with the back-end database, and then use the Changed flag to determine if the command needs to be re-prepared at a later time.
property Changed: Boolean read write
Clause
Holds the text representation of the current WHERE clause.
property Clause: string read
Clear
Clears the WHERE clause and removes all previously added conditions.
procedure Clear
ClientFields
Indicates whether the field names used when adding condition to the WHERE clause are client side field names (ie field names as defined in the data table), or server side field names (ie field names from the back-end database). When set to true, markers will be stored in the where clause to notify the server side that field names need to be mapped over to the names in the physical database using the column mapping.
property ClientFields: Boolean read
CloseBracket
Adds a closing bracket (parenthesis) to the WHERE clause, to close a group of conditions previously started with OpenBracket.
procedure CloseBracket
DefaultOperator
Specifies the default operator that should be used of two conditions are subsequently added to the clause without an explicit call to AddOperator.
property DefaultOperator: TDADefaultOperator read write
Empty
Returns True if the where clause is empty, i.e. does not contain any conditions.
property Empty: Boolean read
Fields
Fields collection
property Fields: TDACustomFieldCollection read write
LastWasCondition
Returns condition state.
property LastWasCondition: Boolean read write
NotEmpty
Returns True if the where clause is not empty, i.e. contains any conditions.
property NotEmpty: Boolean read
OnChange
Fires whenever the where clause has changed by adding new conditions to it.
property OnChange: TNotifyEvent read write
OpenBracket
Adds an opening bracket (parenthesis) to the WHERE clause, to group the following conditions.
procedure OpenBracket
Changed
Returns true if the WHERE clause has been changed. This property will not reset to false automatically, but code using the TDAWhere class may set it to false externally after reacting to changes, to keep track of whether the clause changes again. For example, the IDASQLCommand implementations will set this to false when preparing the command with the back-end database, and then use the Changed flag to determine if the command needs to be re-prepared at a later time.
property Changed: Boolean read write
Clause
Holds the text representation of the current WHERE clause.
property Clause: string read
ClientFields
Indicates whether the field names used when adding condition to the WHERE clause are client side field names (ie field names as defined in the data table), or server side field names (ie field names from the back-end database). When set to true, markers will be stored in the where clause to notify the server side that field names need to be mapped over to the names in the physical database using the column mapping.
property ClientFields: Boolean read
DefaultOperator
Specifies the default operator that should be used of two conditions are subsequently added to the clause without an explicit call to AddOperator.
property DefaultOperator: TDADefaultOperator read write
Empty
Returns True if the where clause is empty, i.e. does not contain any conditions.
property Empty: Boolean read
Fields
Fields collection
property Fields: TDACustomFieldCollection read write
LastWasCondition
Returns condition state.
property LastWasCondition: Boolean read write
NotEmpty
Returns True if the where clause is not empty, i.e. contains any conditions.
property NotEmpty: Boolean read
constructor Create
Creates a new instance.
constructor Create(const aFields: TDACustomFieldCollection; aClientFields: Boolean)
Parameters:
- aFields: Field collection.
- aClientFields: see ClientFields
AddCondition (string, TDASQLCondition): Boolean overload
Adds a new condition to the WHERE clause. If no Operator was added previously, the new condition will be connected to the existing clause (if any) using the DefaultOperator.
function AddCondition(const FieldName: string; Condition: TDASQLCondition): Boolean
Parameters:
- FieldName: field name.
- Condition: condition.
AddCondition (string, TDASQLCondition, Variant, Boolean): Boolean overload
Adds a new condition to the WHERE clause. If no Operator was added previously, the new condition will be connected to the existing clause (if any) using the DefaultOperator.
function AddCondition(const FieldName: string; Condition: TDASQLCondition; const Value: Variant; SkipIfEmptyValue: Boolean): Boolean
Parameters:
- FieldName: field name.
- Condition: condition.
- Value: value.
- SkipIfEmptyValue: allows to skip adding condition if value is empty.
AddConditions
Adds a number of new conditions to the WHERE clause. If no Operator was added previously, the new condition will be connected to the existing clause (if any) using the DefaultOperator.
function AddConditions(const FieldNames: array of string; const Conditions: array of TDASQLCondition; const Values: array of Variant; const Operator: TDASQLOperator): Integer
Parameters:
- FieldNames: array of field names.
- Conditions: array of conditions.
- Values: array of values.
- Operator: operator.
AddOperator
Adds a new operator to the WHERE clause, to connect the previous condition with the next one.
procedure AddOperator(aOperator: TDASQLOperator)
Parameters:
- aOperator: operator.
AddSpaces
Adds specific number of spaces
procedure AddSpaces(Count: Integer)
Parameters:
- Count: count of spaces.
AddText
Adds a plain text SQL to the WHERE clause. If no Operator was added previously, the new condition will be connected to the existing clause (if any) using the DefaultOperator.
procedure AddText(const someText: string; MapClientFields: Boolean)
Parameters:
- someText: SQL
- MapClientFields: allows to perform remap field names in SQL
AddValueGroup
Adds an SQL "IN" condition to the WHERE clause. If no Operator was added previously, the new condition will be connected to the existing clause (if any) using the DefaultOperator.
procedure AddValueGroup(const FieldName: string; const Values: array of Variant)
Parameters:
- FieldName: field name.
- Values: values.
Clear
Clears the WHERE clause and removes all previously added conditions.
procedure Clear
CloseBracket
Adds a closing bracket (parenthesis) to the WHERE clause, to close a group of conditions previously started with OpenBracket.
procedure CloseBracket
OpenBracket
Adds an opening bracket (parenthesis) to the WHERE clause, to group the following conditions.
procedure OpenBracket
OnChange
Fires whenever the where clause has changed by adding new conditions to it.
property OnChange: TNotifyEvent read write