PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WINDEV 2024 → [WD8] HFilter() problem
[WD8] HFilter() problem
Débuté par Peter Holemans, 23 mar. 2005 00:30 - 13 réponses
Posté le 23 mars 2005 - 00:30
Hi all,
I have a multifile outer join query over 3 files: say "Qry_X".
So far no problem, the query executes correctly.
IF hExecuteQuery(Qry_X,hWithFilter+hQueryDefault) THEN...
However, applying a filter on e.g. the boolean 'Valid' field isn't working anymore. As a matter of fact it doesn't work on any field anymore. It always returns "" and I am sure it has worked for a very long time. Has anyone experienced a similar problem, and does anyone know what caused the issue? The only thing I have changed (at least what I recall) is some cardinalities in the data model.
After the hExecuteQuery i set the filter uwing teh following syntax:
sBrowsedItem= hFilter(Qry_X,"Valid=1")
IF sBrowsedItem ~= "" THEN
__Info("The filter could not be set.")
ELSE
...
Thank you in advance for any useful feedback.
Regards,
P.
Posté le 23 mars 2005 - 00:34
Hi all,
I have a multifile outer join query over 3 files: say "Qry_X".
So far no problem, the query executes correctly.
IF hExecuteQuery(Qry_X,hWithFilter+hQueryDefault) THEN...
However, applying a filter on e.g. the boolean 'Valid' field isn't working anymore. As a matter of fact it doesn't work on any field anymore. It always returns "" and I am sure it has worked for a very long time. Has anyone experienced a similar problem, and does anyone know what caused the issue? The only thing I have changed (at least what I recall) is some cardinalities in the data model.
After the hExecuteQuery i set the filter uwing teh following syntax:
sBrowsedItem= hFilter(Qry_X,"Valid=1")
IF sBrowsedItem ~= "" THEN
__Info("The filter could not be set.")
ELSE
...
Thank you in advance for any useful feedback.
Regards,
P.

As an add-on to the above message I would like to mention that hError() returns '0' when looking at any error message from the HyperFile subsystem.
Although the online help states that this should provide you with an error number describing the issue.
Anyway... Thanks again.
Regards,
P.
Posté le 23 mars 2005 - 01:26
Hi all,
I have a multifile outer join query over 3 files: say "Qry_X".
So far no problem, the query executes correctly.
IF hExecuteQuery(Qry_X,hWithFilter+hQueryDefault) THEN...
However, applying a filter on e.g. the boolean 'Valid' field isn't working anymore. As a matter of fact it doesn't work on any field anymore. It always returns "" and I am sure it has worked for a very long time. Has anyone experienced a similar problem, and does anyone know what caused the issue? The only thing I have changed (at least what I recall) is some cardinalities in the data model.
After the hExecuteQuery i set the filter uwing teh following syntax:
sBrowsedItem= hFilter(Qry_X,"Valid=1")
IF sBrowsedItem ~= "" THEN
__Info("The filter could not be set.")
ELSE
...
Thank you in advance for any useful feedback.
Regards,
P.


Hi Peter,
I don't quite understand the use of the hWithFilter parameter in your query. Are you sure you need it? Apart from that I also had some problems with HFilter giving back the browse item, so I don't check it any longer and it works all the same when using the query result as data source for a table field or report and browsing the result with a loop FOR ALL myQuery ON myItem. My filters on query results are much the same as yours (see my reply to Jonathan Flietstra). I don't always understand why certain things work in Windev despite the fact that they shouldn't. But as long as they consistently work, I can live with it.
Best regards
Mat
Posté le 23 mars 2005 - 10:08
Hi Peter,
I don't quite understand the use of the hWithFilter parameter in your query. Are you sure you need it? Apart from that I also had some problems with HFilter giving back the browse item, so I don't check it any longer and it works all the same when using the query result as data source for a table field or report and browsing the result with a loop FOR ALL myQuery ON myItem. My filters on query results are much the same as yours (see my reply to Jonathan Flietstra). I don't always understand why certain things work in Windev despite the fact that they shouldn't. But as long as they consistently work, I can live with it.
Best regards
Mat

Thank you for your input Mat. Unfortunately it doesn't help me since the filter doesn't apply to the data query upon executing the hFilter command. This means the filtering isn't executed if I read through the filtered data source.
Could this be some sort of corruption or am I missing something? If I can't find an answer on this forum (there is so much experience out here), I'll guess I'll post a call with PCSoft Tech Support.
Anyway... Thanks again !
Peter
Posté le 23 mars 2005 - 16:21
Thank you for your input Mat. Unfortunately it doesn't help me since the filter doesn't apply to the data query upon executing the hFilter command. This means the filtering isn't executed if I read through the filtered data source.
Could this be some sort of corruption or am I missing something? If I can't find an answer on this forum (there is so much experience out here), I'll guess I'll post a call with PCSoft Tech Support.


Good afternoon Peter,
Difficult to understand why the same thing should work for me and not for you in the same WD version... You didn't specify how you access the data but I assume you took into account the hKeepFilter parameter. Help about HReadFirst/HReadSeekFirst:
"HKeepFilter: The browse action will take into account the filter defined using HFilter, even if the browse key is not optimized for the filter. Reminder: the HFilter function returns the optimized browse key for the filter."
One other thing you might check is if the way you want to use the filter, the filter item ("Valid" in this case) needs to be a key.
Best regards
Mat
Posté le 23 mars 2005 - 16:27
...
>One other thing you might check is if the way you want to use the filter, the filter item ("Valid" in this case) needs to be a key.
...
Another is that the item "Valid" hasn't been renamed in the query. Things like that do happen occasionally :-)
Posté le 24 mars 2005 - 00:45
...
One other thing you might check is if the way you want to use the filter, the filter item ("Valid" in this case) needs to be a key.
...

Another is that the item "Valid" hasn't been renamed in the query. Things like that do happen occasionally :-)

Hi Mat and all others,
I'm still struggling and tested it further.
Apparently, I came to the following conclusion:
- Hfilter works perfectly when using a direct data file
- Hfilter always (!!!) fails when the data source is a query
Should I reinstall WinDev or am I missing something else here?
This example doesn't work (Only one file in the query: customer)

HExecuteQuery(Qry_Test_Customer_Select,hQueryDefault+hWithFilter)
IF HFilter(Qry_Test_Customer_Select,"Valid=0") ~= "" THEN
Trace("Filter Failed")
END
HReadFirst(Qry_Test_Customer_Select)
WHILE HFound
Trace(Qry_Test_Customer_Select.LastName)
HReadNext(Qry_Test_Customer_Select)
END

This however works (Directly on the customer file) splendid:

IF HFilter(Customer,"Valid=0") ~= "" THEN
Trace("Filter Failed")
END
HReadFirst(Customer)
WHILE HFound
Trace(Customer.LastName)
HReadNext(Customer)
END

What's the difference?
Thank you for any feedback...
Regards,
Peter
Posté le 24 mars 2005 - 08:23
G'day Peter

If there is a "Where" clause in the query it will only return matching records so what purpose does the HWithFilter option serve ? According to the help, if you use this option "the query result is a selection of filter type records if the Hyper File engine allows it. "
What is a filter type record ?
Could the use of this option be the cause of the problem as it seems to limit the option available on the data returned ?
Regards
Al
Posté le 24 mars 2005 - 10:05
Hi Al,
Thx for your feedback.
I've tried it with hWithFilter option and without.
Well even without any option and the problem remains:
The filter works perfect on HF files directly, but it never seems to work anymore on queries.
It is really getting annoying.
I was thinking about submitting the issue to PCSoft Tech Support, but you guys might be able to help me first.
Regards,
Peter
Posté le 24 mars 2005 - 17:23
Peter,
What if you execute the filter statement before you execute the query?
hth
Clive
Posté le 24 mars 2005 - 23:31
Peter,
What if you execute the filter statement before you execute the query?
hth
Clive

Hi Clive,
Nope... Not a solution since the query as a data source needs to exist before you can apply hFilter() to it. Otherwise this will result in an HF engine error.
Anyway, I've sent my issue to Tech Support.
Thank you all for your contributions.
Regards,
Peter
Posté le 29 mars 2005 - 20:24
Hi Mat and all others,
I'm still struggling and tested it further.
Apparently, I came to the following conclusion:
- Hfilter works perfectly when using a direct data file
- Hfilter always (!!!) fails when the data source is a query
Should I reinstall WinDev or am I missing something else here?
This example doesn't work (Only one file in the query: customer)

HExecuteQuery(Qry_Test_Customer_Select,hQueryDefault+hWithFilter)
IF HFilter(Qry_Test_Customer_Select,"Valid=0") ~= "" THEN
Trace("Filter Failed")
END
HReadFirst(Qry_Test_Customer_Select)
WHILE HFound
Trace(Qry_Test_Customer_Select.LastName)
HReadNext(Qry_Test_Customer_Select)
END

This however works (Directly on the customer file) splendid:

IF HFilter(Customer,"Valid=0") ~= "" THEN
Trace("Filter Failed")
END
HReadFirst(Customer)
WHILE HFound
Trace(Customer.LastName)
HReadNext(Customer)
END

What's the difference?


Good afternoon Peter,
Unfortunately, you don't say whether
1) the query item name "Valid" exists (i.e. hasn't been given another name)
2) whether you tried the code without testing the filter. As given in my example code, I never test the filter and the result is always right (obviously checked extensively to make sure it works)
3) I agree with Al, the parameter hWithFilter doesn't make sense.
There is nothing else I can add given the fact that I have no problems whatsoever filtering queries exactly the way you want to do.
Best regards
Mat
Posté le 29 mars 2005 - 21:57
I forgot to add that according to the online help, you should also be using the parameter hKeepFilter in the HReadFirst command. It would't be the first time that Windev allows using a function in some cases incorrectly without complaining.
If the filter fails, the difference between accessing the query and the file the way you do it is that HReadFirst on the file succeeds anyway if it contains at least one record, whereas if the query is "empty", i.e. no records returned, HReadFirst fails, respectively the code in the WHILE HFound loop will not be executed.
Posté le 30 mars 2005 - 00:59
Hi Mat and all others helping me out on the hFilter problem.
In the end, I was able to resolve the issue.
I placed a call as well with PCsoft Tech Support and they answered as usual speedily and accurately. This is what PCSoft Tech Support answered:
=>QUOTE<=
Dear Sir,
When you want to use a filter on a query, first you must not use the hWithFilter parameter and second you must use the key returned by Hfilter.
This is an example that can be tested in CRM :

Mykey is string
IF HExecuteQuery(Query1,hQueryDefault) THEN
Mykey = HFilter(Query1,"zipcode='43926'")
IF Mykey ~= "" THEN
Error("Error", HErrorInfo(hErrAll))
END
HReadFirst(Query1, Mykey)
Info(Query1.Zipcode)
ELSE
Error("Error")
END

Best regards,
Patrick Philipot.
WinDev Hot line
PCSOFT France
=>END QUOTE<=
Unfortunately this didn't resolve the issue.
I was able to resolve it in the following fairly drastic way which I also mentionned to TechSupport in case someone else encounters something similar.
=>QUOTE<=

Hello Patrick,
Thank you for your quick answer.
I refined my coding to match your suggestion.
Unfortuneately this didn't work.
What I then did was, create a new minimal project (to send to you) and tested it again.
This worked.
What I then did to the original project, was to delete all HyperFile files and regenerate them all with hCreation.
After setting up again a lot of the data, the filters worked again.
My conclusion: One way or another, the data files seemed to have become corrupted which caused that no single filter was working anymore on queries.
The project is still in development with a lot of data model changes.
Maybe the continuous generation of the analysis and resetting the version back to 1 several times caused the issue in the data files. this must have caused the filtering mechanism in the HyperFile engine on queries to malfunction. Remember, the hError() return was always '0' meaning no error code was returned.
Anyway, thank you for your support !
You may close the call...
Kind regards,
Peter

=>END QUOTE<=