Welcome! Log In Create A New Profile

Advanced

Query question.

Posted by AadG 
Query question.
December 07, 2020 11:06AM
Hi all,

First, I'm a newbie to the use of queries. I always use hFilter, but run into some dificulties lately. So I want to replace
some hFilters with queries.

I want to filter a table and use parameter to change the value of the search. This works OK. How can I present the full table first,
before a change the value of the parameter ?? When I open the window with the table, it's empty until I put in a value
in the parameter. What I want is to see the full table first (all records) and then activate a search with the query.

I hope my question is a bit clear.

Best regards,

Aad
Re: Query question.
December 07, 2020 11:53AM
Hi Aad,

If a query parameter is Null then it will be ignored, the easiest way to do that is in the table initialization code like this:
IF chk_Filter1 then myQueryName.Param_1=Value1
IF chk_Filter2 then myQueryName.Param_2=Value2
hExecuteQuery(myQueryName,hQueryDefault)
Best regards,
Piet
Re: Query question.
December 07, 2020 12:38PM
Thanks Piet,

I use:

Kl_tab_vvCleunik_Query.ParamVVCLEUNIK = Null
HExecuteQuery(Kl_tab_vvCleunik_Query,hQueryDefault)

and the table is filled with al the records. I must say significantly slower then normal. Problem now is that if I pass a new value
to the parameter, the table is not refreshed with the new query. Am I forgetting something ?

Best regards,

Aad
Nick
Re: Query question.
December 07, 2020 01:41PM
Why displaying all the records first...and then filter ???
Re: Query question.
December 07, 2020 01:53PM
Because the table is a sub of another table. So when a record is choosen in the first table (file), the second table (file) shows all the related records. This only needs to be done if the users choose for a filter. So normally when the windows opens, all the records are shown in table2 and then gives the user the opportunity to filter table2 via table1.
Argus
Re: Query question.
December 07, 2020 02:08PM
> and the table is filled with al the records. I
> must say significantly slower then normal. Problem

It's not slower than normal, it's slower than a table linked to the file with a hfilter... the reason is that the query is READING (on the server) and SENDING (to the client) ALL the records matching the condition, then the table needs to create ALL the lines and fill them

With the direct to file+hfilter, the table is reading and displaying ONLY the record for the visible records, and will read the rest ONLY if the user scrolls... So the difference in speed in directly linked to your choice of switching to a query.

> now is that if I pass a new value
> to the parameter, the table is not refreshed with
> the new query. Am I forgetting something ?
>
Yep, you need to add a tabledisplay instruction to tell the table it needs to refresh
Re: Query question.
December 07, 2020 02:18PM
Thank you, that makes sense. Tabledisplay() is ued so that's not the probleem. Null seems to "kill" the query. I used hFreequery() before calling it again, but no luck.
Re: Query question.
December 07, 2020 09:32PM
Hi Aad,

You don't need to assign null to the parameters since they are initially Null and automatically reset to Null again after the query has executed.
So if your code is in the table initialization code as I stated, a TableDisplay,taInit will do.
So outside the tablecode you do e.g.:
chk_Filter_1=True
chk_Filter_2=False
Tabledisplay(MyTable,taInit)
Where chk_Filter can be a checkbox or a variable.
Set the parameter flags as needed in the global declarations.

Remember that on first load of the window or page it will display all the records first if you do nothing, which will of course slow down the process. .
That's why I often set an impossible value for a parameter (e.g. -1 for an identifier) during initialization.


Best regards,
Piet
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: