Search Criteria Items Array
Hi,
From RAP and not a pass-thru, I need to modify the SQL that my application
sets for the report. Using SQLBuilder, I attempt to iterate through the
SearchCriteria.Items array, but the only objects available seem to be Value
and Operator. If I do the same for the Available array, I can access
FieldName, TableName, etc. so I am wondering if there is another method for
the Items array?
For example, while the first statement is valid, the second is not.
SqlBldr.SearchCriteria.Available[i].FieldName
SqlBldr.SearchCriteria.Items[i].FieldName
SearchCriteria.Exists is available so I can use this to iterate through the
Available array to see which of the possible fields in the dataview are
specified as search criteria and this is messy.
Also, because TdaCriteriaOperatorType is not enumerated, how do I determine
what the operator is using SQLBuilder? I can work around this using
Report.AutoSearchFields[i].SearchOperator as TppSearchOperatorType is
enumerated, but it seem odd to be mixing this with SQLBuilder.
--
Bob
From RAP and not a pass-thru, I need to modify the SQL that my application
sets for the report. Using SQLBuilder, I attempt to iterate through the
SearchCriteria.Items array, but the only objects available seem to be Value
and Operator. If I do the same for the Available array, I can access
FieldName, TableName, etc. so I am wondering if there is another method for
the Items array?
For example, while the first statement is valid, the second is not.
SqlBldr.SearchCriteria.Available[i].FieldName
SqlBldr.SearchCriteria.Items[i].FieldName
SearchCriteria.Exists is available so I can use this to iterate through the
Available array to see which of the possible fields in the dataview are
specified as search criteria and this is messy.
Also, because TdaCriteriaOperatorType is not enumerated, how do I determine
what the operator is using SQLBuilder? I can work around this using
Report.AutoSearchFields[i].SearchOperator as TppSearchOperatorType is
enumerated, but it seem odd to be mixing this with SQLBuilder.
--
Bob
This discussion has been closed.
Comments
Correct. As a visaul example, try using the Query Designer to add search
criteria. You will see a list of available fields from which to choose. Once
you choose a field, you can specify the search operator and value. If you
wish to search on a different field, you must remove the selected field and
choose another field.
SQLBuilder works in the same manner as the Query Designer - they both
manipulate TdaSQL
example:
mySQLBuilder.SearchCriteria.Clear;
mySQLBuilder.SearchCriteria.Add(....);
We can register TdaCriteriaOperatorType with RAP for the next release. You
can easily register enums with RAP.
example:
uses
ppEnum,
daSQL;
initialization
raRegisterEnum('TdaCriteriaOperatorType',
TypeInfo(TdaCriteriaOperatorType));
--
Nard Moseley
Digital Metaphors
www.digital-metaphors.com
Best regards,
Nard Moseley
Digital Metaphors
www.digital-metaphors.com
Adding or removing criteria is not a problem, my problem is reading the
existing criteria.
Using SearchCriteria.Exists is OK in specific situations, but
SearchCriteria.Items[i].FieldName would provide a general robust solution.
Is there a reason why the TdaField properties are surfaced through the
Available array, but not the Items array?
--
Bob
Ok, I understand better now.
For the next maintenance release, we will add RAP RTTI for TdaCriteria. Here
is the code that you need to make this work in the version you are using
now.
uses
ppRTTI,
ppRelatv,
daSQL;
type
TraTdaCriteriaRTTI = class(TraTppRelativeRTTI)
public
class procedure GetPropList(aClass: TClass; aPropList: TraPropList);
override;
class function GetPropRec(aClass: TClass; const aPropName: String; var
aPropRec: TraPropRec): Boolean; override;
class function GetPropValue(aObject: TObject; const aPropName: String;
var aValue): Boolean; override;
class function RefClass: TClass; override;
class function SetPropValue(aObject: TObject; const aPropName: String;
var aValue): Boolean; override;
end;
implementation
{******************************************************************************
*
** C R I T E R I A R T T I
*
{******************************************************************************}
{------------------------------------------------------------------------------}
{ TraTdaCriteriaRTTI.GetPropList }
class procedure TraTdaCriteriaRTTI.GetPropList(aClass: TClass; aPropList:
TraPropList);
begin
inherited;
aPropList.AddProp('Field');
aPropList.AddProp('AutoSearch');
aPropList.AddProp('Mandatory');
aPropList.AddProp('ShowAllValues');
end;
{------------------------------------------------------------------------------}
{ TraTdaCriteriaRTTI.GetPropRec }
class function TraTdaCriteriaRTTI.GetPropRec(aClass: TClass; const
aPropName: String; var aPropRec: TraPropRec): Boolean;
begin
Result := True;
if (CompareText(aPropName, 'Field') = 0) then
ClassPropToRec(aPropName, TdaField, True, aPropRec)
else if (CompareText(aPropName, 'AutoSearch') = 0) then
PropToRec(aPropName, daBoolean, False, aPropRec)
else if (CompareText(aPropName, 'Mandatory') = 0) then
PropToRec(aPropName, daBoolean, False, aPropRec)
else if (CompareText(aPropName, 'ShowAllValues') = 0) then
PropToRec(aPropName, daBoolean, False, aPropRec)
else
Result := inherited GetPropRec(aClass, aPropName, aPropRec);
end;
{------------------------------------------------------------------------------}
{ TraTdaCriteriaRTTI.GetPropValue }
class function TraTdaCriteriaRTTI.GetPropValue(aObject: TObject; const
aPropName: String; var aValue): Boolean;
begin
Result := True;
if (CompareText(aPropName, 'Field') = 0) then
Integer(aValue) := Integer(TdaCriteria(aObject).Field)
else if (CompareText(aPropName, 'AutoSearch') = 0) then
Boolean(aValue) := TdaCriteria(aObject).AutoSearch
else if (CompareText(aPropName, 'Mandatory') = 0) then
Boolean(aValue) := TdaCriteria(aObject).Mandatory
else if (CompareText(aPropName, 'ShowAllValues') = 0) then
Boolean(aValue) := TdaCriteria(aObject).ShowAllValues
else
Result := inherited GetPropValue(aObject, aPropName, aValue);
end; {class function, GetPropValue}
{------------------------------------------------------------------------------}
{ TraTdaCriteriaRTTI.RefClass }
class function TraTdaCriteriaRTTI.RefClass: TClass;
begin
Result := TdaCriteria;
end;
{------------------------------------------------------------------------------}
{ TraTdaCriteriaRTTI.SetPropValue }
class function TraTdaCriteriaRTTI.SetPropValue(aObject: TObject; const
aPropName: String; var aValue): Boolean;
begin
Result := True;
if CompareText(aPropName, 'AutoSearch') = 0 then
TdaCriteria(aObject).AutoSearch := Boolean(aValue)
else if CompareText(aPropName, 'Mandatory') = 0 then
TdaCriteria(aObject).Mandatory := Boolean(aValue)
else if CompareText(aPropName, 'ShowAllValues') = 0 then
TdaCriteria(aObject).ShowAllValues := Boolean(aValue)
else
Result := inherited SetPropValue(aObject, aPropName, aValue);
end; {class function, SetPropValue}
initialization
raRegisterRTTI(TraTdaCriteriaRTTI);
raRegisterEnum('TdaCalcType', TypeInfo(TdaCalcType));
raRegisterEnum('TdaCriteriaOperatorType',
TypeInfo(TdaCriteriaOperatorType));
raRegisterEnum('TdaCriteriaType', TypeInfo(TdaCriteriaType));
raRegisterEnum('TdaJoinOperatorType', TypeInfo(TdaJoinOperatorType));
raRegisterEnum('TdaJoinType', TypeInfo(TdaJoinType));
--
Nard Moseley
Digital Metaphors
www.digital-metaphors.com
Best regards,
Nard Moseley
Digital Metaphors
www.digital-metaphors.com