Subject Re: [IBO] Re: Query.Locate -with OrderingItems & OrderingLinks
Author Paul Vinkenoog
Hello Michael, Jason,

>> * I have a dataset with fields "Salesperson", "ID"
>> * "Salesperson" has many repeats, "ID" is unique
>> * With OrderingItems of "salesperson, id; salesperson desc,
>> id desc"
>> * I want to issue some command that will take me to the
>> first occurrence of a "salesperson"
>> * I thought "query.locate(('salesperson', 'GARY', [lopPartialKey,
>> lopFindNearest]);

Careful with lopFindNearest! If there is no 'GARY' in the set, it
will locate e.g. a 'GARZON' and still return true! (As a customer
of mine discovered when I introduced lopFindNearest in a Locate.
BTW: I did this because I had the same problem as you, see below.)

And lopPartialKey will return true if 'GARY' ain't there but 'GARYLLA'
is.

>> * Would do so, but even though it takes me to a record
>> with "GARY", it is not the first.

I can confirm this behaviour: set well ordered, called First, called
Locate, and landed on the third or fourth matching record instead of
the first one.

This hasn't always been the case: I originally built that app with
IBO 3.x and it worked fine. Somewhere after an IBO upgrade the
Locate behaviour seems to have changed.

Interesting thing: most Locates *did* take me to the first match. But
the ones that didn't always took me to the same record as long as the
underlying table hadn't changed. I.e. if a certain Locate took me to
the third matching record, it would *always* do that. Nothing random
about it.

My first (bad) idea was to use lopFindNearest, but that caused me the
problem I described above.

Later I spend some time in the IBO sources, but quite a number of
functions are involved. I didn't have time to fully analyze and test
all that, so I changed my app instead - kicked out the troublesome
Locates. (I *did* notice however that Locate sometimes takes big
steps when looking for matches. Maybe it has to do with that: taking
giant steps and not always backstepping when a match is found?)

>> * I only want to position to the first record with "GARY"
>> not step to the next from where I am.

>> Is there some other command I should be using? Do
>> I need to write some code that will cycle through the
>> records until it finds the right one (I can, I just
>> thought Locate was suppose to do that)?

My solution/workaround was to replace the Locates with Master-Detail
sets and/or parameterized sets. WhereItems can also be used. So now I
work with sets that only contain the records I want to step through.
In my case this was a cleaner and safer approach anyway.

I now only use Locates:

a) if I know that the search value, if it is found, is unique; or
b) if I don't care about the record itself, but just want to know if
a certain value exists in the column.


Greetings,
Paul Vinkenoog