> Err DmFindRecordByID(DmOpenRef dbP, UInt32 uniqueID, UInt16* indexP);
>
> I am trying to use the above api to query the database. However my app
> ID actually defined as a C string/char[]. I have tried to cast or
> without cast my id string to be UInt32, either works. I was wondering
> that I might misuse/misunderstand this api.
The uniqueID is NOT the application type/id. It IS the unique ID for a
given record in the database.
Records in a database are usually referred to by their "index" or "record
number" (different words for the same thing). The index is a 0-based index
of the record. The first record is at index 0, the second is at index 1,
etc. This index can change as records are added or removed from the
database, or as it is resorted. That is, the record at index 2 is moved to
index 3 when a new record is added at index 0.
The uniqueID of a given record, on the other hand, does not change as
insertions, removals, and sorts are performed. So, the uniqueID of the
record at index 2 is the same, even after a new record is added at index 0.
Use the uniqueID if you need to keep track of a given record and know that
there will be insertions and removals or changes in the sort. Then use
DmFindRecordByID() to get the index to that record when you need to access
it.
> How to make it work? Do I need to sort the database or define a compare
> function prior to calling the above api ?
No.
> If not, is it the same as loop through all the record and do the
comparison myself from
> performance's perspective?
When an appropriate API is available, use it rather than write your own.
You don't say what you're trying to do, but if you are trying to find a
specific record in the database that matches some criteria, then you will
need to search it yourself. You can do a linear search (starting at record
0 and incrementing), or sort the database and use a smarter search
algorithm. In the latter case, you would need a comparison function.
Hope this helps,
Jeff
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/