Returning a Filter
Hi guys,
Im implementing a Roxie query and several filters should be applied to the query according to the options passed by the user (i.e. if a given parameter is not passed, the filter shouldnt be applied).
I was able to implement, but Im wondering a better way to do that and would like to use functions that return the filter.
Example:
I would like to know if there is someway to implement something like this. The code would be much better (at least it would be cleaner).
Thanks in advance,
- Artur Baruchi
Im implementing a Roxie query and several filters should be applied to the query according to the options passed by the user (i.e. if a given parameter is not passed, the filter shouldnt be applied).
I was able to implement, but Im wondering a better way to do that and would like to use functions that return the filter.
Example:
- Code: Select all
EXPORT myRoxieQuery () := FUNCTION
Parms := STORED($.iUserInfo);
myDataSet := DATASET('somefile', THOR);
filter01 := FilterFunc01(iParams.name);
filter02 := FilterFunc02(iParams.age);
RETURN myDataSet(filter01, filter02);
END;
I would like to know if there is someway to implement something like this. The code would be much better (at least it would be cleaner).
Thanks in advance,
- Artur Baruchi
- abaruchi
- Posts: 19
- Joined: Thu Apr 18, 2019 4:50 pm
Artur ,
HTH,
Richard
You can do it like this:abaruchi wrote:Hi guys,
Im implementing a Roxie query and several filters should be applied to the query according to the options passed by the user (i.e. if a given parameter is not passed, the filter shouldnt be applied).
I was able to implement, but Im wondering a better way to do that and would like to use functions that return the filter.
Example:
- Code: Select all
EXPORT myRoxieQuery () := FUNCTION
Parms := STORED($.iUserInfo);
myDataSet := DATASET('somefile', THOR);
filter01 := FilterFunc01(iParams.name);
filter02 := FilterFunc02(iParams.age);
RETURN myDataSet(filter01, filter02);
END;
I would like to know if there is someway to implement something like this. The code would be much better (at least it would be cleaner).
- Code: Select all
EXPORT myRoxieQuery () := FUNCTION
Parms := STORED($.iUserInfo);
myDataSet := DATASET('somefile', THOR);
filter01 := IF(iParams.name='', TRUE,FilterFunc01(iParams.name));
filter02 := IF(iParams.age=0, TRUE,FilterFunc02(iParams.age);
RETURN myDataSet(filter01, filter02);
END;
HTH,
Richard
- rtaylor
- Community Advisory Board Member
- Posts: 1619
- Joined: Wed Oct 26, 2011 7:40 pm
Hello Richard,
Thanks for your reply. I tried to apply the approach you shown, but when setting TRUE to a string or to a unsigned, an error occur, cause it should be boolean.
I tried to use something like this:
Don't know if it is the best way to do it, since I'm applying some filter (i.e. if a typo is made, and someone has a negative age, it should be returned).
Thanks,
- Artur Baruchi
Thanks for your reply. I tried to apply the approach you shown, but when setting TRUE to a string or to a unsigned, an error occur, cause it should be boolean.
- Code: Select all
Incompatible types: expected Integer, given Boolean,
I tried to use something like this:
- Code: Select all
EXPORT myRoxieQuery () := FUNCTION
Parms := STORED($.iUserInfo);
myDataSet := DATASET('somefile', THOR);
filter01 := IF(iParams.name='', name <> '', name=iParams.name);
filter02 := IF(iParams.age=0, age > 0, age=iParams.age);
RETURN myDataSet(filter01, filter02);
END
Don't know if it is the best way to do it, since I'm applying some filter (i.e. if a typo is made, and someone has a negative age, it should be returned).
Thanks,
- Artur Baruchi
- abaruchi
- Posts: 19
- Joined: Thu Apr 18, 2019 4:50 pm
Artur,
HTH,
Richard
Yes. Because a filter must always be a Boolean expression, I assumed that your FilterFunc01 and FilterFunc02 functions returned Boolean results. Replacing those functions with Boolean expressions is the appropriate thing to do, but you still need to use TRUE as your filter expression if no parameter is passed, like this:I tried to apply the approach you shown, but when setting TRUE to a string or to a unsigned, an error occur, cause it should be boolean.
- Code: Select all
EXPORT myRoxieQuery () := FUNCTION
Parms := STORED($.iUserInfo);
myDataSet := DATASET('somefile', THOR);
filter01 := IF(iParams.name='', TRUE, name=iParams.name);
//all recs if no name passed, otherwise filter for passed name
filter02 := IF(iParams.age=0, TRUE, age=iParams.age);
//all recs if no age passed, otherwise filter for passed age
RETURN myDataSet(filter01, filter02);
END
HTH,
Richard
- rtaylor
- Community Advisory Board Member
- Posts: 1619
- Joined: Wed Oct 26, 2011 7:40 pm
Hi,
Not sure If you've seen my post on 'Multi-dimensional, Multi-variable' searches.
https://hpccsystems.com/bb/viewtopic.php?f=41&t=6183
As I understand your post it seems to address your problem?
Yours
Allan
Not sure If you've seen my post on 'Multi-dimensional, Multi-variable' searches.
https://hpccsystems.com/bb/viewtopic.php?f=41&t=6183
As I understand your post it seems to address your problem?
Yours
Allan
- Allan
- Posts: 444
- Joined: Sat Oct 01, 2011 7:26 pm
5 posts
• Page 1 of 1
Who is online
Users browsing this forum: Google [Bot] and 1 guest