Subject Re: [IBO] Locating
Author Svein Erling Tysvær
Welcome Ryan!

>Coming from a BDE background, I think I'm still having some
>conceptual issues.

You're probably right, but being aware of it is a great start!

>I have a table with 2000 records.
>When I do a T_IBQuery.Locate, locating the last record in the table,
>it seems to take some time, as it "Fetches" all records.

Well, my first question would be: "Why do you need to retrieve 2000
records?" Sure, sometimes that may be necessary, like when doing reports or
printing things for handling by different persons, but since you have a BDE
background I suspect you to retrieve records you are not really interested
in. Rule of thumb: Only retrieve 2000 records if you need to do some work
with all of them and that work cannot be done on the server.

>A dialog pops up with,
>"Fetching Query Results"
>(taking around 8 secs)
>until the last record is reached.

8 seconds for 2000 rows? Sounds pretty slow, but maybe you are using some
slow line or use long fields.

>What am I not understanding? Do I close the query, make the WHERE
>clause reflect the record I want then re-open it?

You could do, what I normally do is write something like

SELECT <requiredcolumns>
FROM <atable>
WHERE <afield> = :<parametername>

Then I prepare the TIB_Query (or TIB_Cursor), set the parameter and open.
Whenever the record of interest changes, close the TIB_Query, change the
parameter value and reopen.

Another option if it is done online, is to use search mode.

>I guess I just don't understand why all records are fetched when
>doing a locate.

Simply because indexes are unidirectional and nothing is stored in any
particular order in the database itself. To speed up a call to the "last"
record ("last" being relative to your order by clause), create a DESC index.