Using Find First

crunchy1

New Member
Are there any (significant or otherwise) performance increases or decreases in using a "find first" versus a find when the where clause contains all and only the fields that exist in the primary unique index for the table. Here's an example:

Progress Database Table: customer
Fields: companyNumber, customerNumber, name, address, zipcd, phone
Index (Primary Unique): companyNumber, customerNumber

Code:
find customer where customer.companyNumber = inputCompany 
and customer.customerNumber = inputCust no-lock no-error.

Code:
find first customer where customer.companyNumber = inputCompany 
and customer.customerNumber = input Cust no-lock no-error.

Is there any difference between the two statements?
 
In your case, there is no difference to the statements .....

The only difference between a 'FIND FIRST' and a 'FIND' is that the FIND (without 'First') is looking for a unique match whereas the 'FIND FIRST' will look for the first occurrance of the where clause. And, in your case, they will both be the same ..... since your undex is unique.

But, for clarity of code I'd go with just the FIND.

Later,
Gordon
 
Warning: One does have to be careful with just the FIND, though, because if the fields supplied do NOT comprise a complete unique index, the FIND without the FIRST can fail, EVEN IF THERE IS A MATCH. This will happen when there are multiple records meeting the requirements. I tend to use FIND FIRST because of that, though of course, if one is not sure about the nature of the index, perhaps one should research it first :)
 
Hello,
For me programmer have to know when he must use find first. The programmer have to know if he can have one record or more. Then Use always find to fetch a unique record (see index) and find first for other goal.

I've never understand the use of find first for a search on a unique key. Each time i see that on a program, i'm affraid. What the author have thought when he wrote the code ?
 
Agreed, but for those who don't realize it (I should have mentioned this earlier), there are legitimate reasons for using FIND without the FIRST against a non-unique index. Hm.... I'll make it a trivia question Why indeed? :)
 
Well it's sunday here but to me it seems you would want do that to find out if there is none, one or more records to be found.

e.g.
Code:
find something no-lock no-error.
if not available something and ambiguous something
then do:
   /* stuff you want to do if there are more then one */
end.
else if not available something
then do:
  /* stuff you wan t to do if there's no record at all */
end.
else do:
  /*  stuff you want to do if there's only one */
end.

Was that what you meant?

regards,

Casper
 
:-)

Ah, real collectors item, always wanted to have some. I hope it's OE toiletpaper with a bit of OO in it:D

Casper.
 
Back
Top