Subject Re: SEEKER
From Mervyn Bick <invalid@invalid.invald>
Date Sat, 5 Jan 2019 12:09:28 +0200
Newsgroups dbase.getting-started

On 2019-01-03 1:50 PM, Akshat Kapoor wrote:

> This is only required if number of rows is greater than 10K or data is
> to be sent over network and is causing slow response due to frequent
> requery()
> I use a very similar form with the following additions
> In form_onOpen event
> form.twait = false
> form.timer = new timer()
> form.timer.parent = form
> form.timer.interval = 0.75
> form.timer.ontimer = {;form.twait = false ; form.timer.enabled = false;
> form.searchcode_onkey2()}
> (beware of word wrap in above line)
> Replace searchcode with entryfield1
> function SEARCHCODE_onKey(nChar, nPosition,bShift,bControl)
>      if form.twait
> //        //do nothing
> //        //We are waiting for additional key strokes
>      else
>          form.twait = true
>          form.timer.enabled = true
>      endif
>        return
> function SEARCHCODE_onKey2(nChar, nPosition,bShift,bControl)
>      if sc <> alltrim(upper(form.searchcode.value))
>         sc = alltrim(upper(form.searchcode.value))
>             form.invedatamodule1.inve.params["SC"] = "%"+sc+"%"
>             form.invedatamodule1.inve.requery()
>         form.rowset.first()
>      endif
>      form.mun_grid1.refresh()
>        return
> I have a habit of using upper() to make search case insensitive.
> Using this code I wait for 0.75 seconds for additional key strokes
> before requery().
> This may speed up the process.
> Regards
> Akshat

As you point out, using a parameter driven query to refine a large
rowset selection character by character with a slow network can
introduce delays which have to be dealt with.

I did point out in my initial message that this code is not efficient.
It's just a thought but one can reduce the load on the network and the
search time by not doing the requery() after every keystroke.

Cornelius is looking for, say, SILVER somewhere in a field.  A requery()
after S is probably going to fetch most of the records in the table.
Another requery() after I is going to fetch a good number of the same
records again.   Each time fewer and fewer records are retrieved but
this can still represent a LOT of network traffic.  There's actually a
very good change that after SIL the remaining characters are going to
fetch the exact same rows over and over anyway.

By only doing the requery() after all the characters for the search
string have been entered the search time, and network load, can be
reduced significantly.

    function ENTRYFIELD1_onKey(nChar, nPosition,bShift,bControl)
       form.queryname.params['whatever'] = '%'+lower(this.value)+'%'
       if nChar = 13 //Enter key