Am Mittwoch, 29. Oktober 2003 06:19 schrieb Jefferson Samuel:
> Hello All,
>
> Could anybody help me with my problem?
>
> Is there any direct Data Manager API function to
> return an index of the record, searching for a value
> in the DB?
>
> Eg:
>
> Have a DB with 1000 rows & 2 columns. 500th rows
> contain a value "Hello" in the 2nd column. Are they�re
> any functions that would return me this record index
> faster. So that I need not loop with all the records
> in the DB.
>
> I can�t use
>
> DmFindSortPosition:
>
> b�coz , I don�t have an record that is unattached from
> the db.
>
> DmFindSortPosition() is not intended to find the index
> of an existing record, rather, it is intended to tell
> you where to insert a new record.

That's right, but it can easily be used to find a certain record, too, 
assuming the records are sorted as you need it.

You need a sorting function with which the records are sorted and which 
includes the field combination you search for.

Heres a piece of pseudo code:

------------------------------------------------------------------------
YourRecordType record = {"Field 1", "Hello"};
UInt16 pos;

pos = DmFindSortPosition(dbRef, &record, NULL, SortFunction, 0);
if (pos > 0) pos--;
if (Compare(record, foundRecord) == 0) Record_is_found;
-----------------------------------------------------------------------

Since DmFindSortPosition returns the insertion position, you have to subtract 
one to get the position of an equal record. Eventually you have to get the 
record and look if it is actually the right one; if not, the searched record 
is not in the database.

See the Palm OS Reference for more information.

BTW: You should create the reference record with e.g. MemPtrNew if it's big to 
save stack space.

If you haven't sorted the database with the fields you need there's only one 
possibility: you have too loop through any record to find what you want. If 
there would be a OS call to do that it only could do the same (and would be 
slow, too).

-- 
Mit freundlichen Gr��en
Helmut A. Bender
Helmut Bender GmbH

-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/

Reply via email to