At 10:42 PM -0600 12/11/99, Brian O'Grady wrote:
>What is a good way to find a record in a database by something other then
>the index, say a person's ID? I am a novice at C and the DmFindSortPosition
>has me baffled.
If you know the unique ID that Palm OS assigned to the record, you can use
DmFindRecordByID to find the record. This function does a linear scan of the records,
but it does it more efficiently than you could. If you put your own ID field in each
record (say an employee number), you could do your own linear scan to find the record.
Or you could keep the database sorted by this ID and use DmFindSortPosition to do a
binary search for you. Again, you could do your own binary search but not as
efficiently as DmFindSortPosition. You need to define a callback function to use
DmFindSortPosition, so you probably don't want to do that until you're comfortable
with C. Stick with the slower linear scan for now.
Note that the term "database" in Palm OS just means an array of records which are just
variable-size chunks of data. These aren't the "databases" we learned about in school!
<Advanced side topic> There has been some debate as to whether the unique IDs assigned
to records by Palm OS are preserved across a hard reset & recover. The answer may
depend on the version of HotSync; I know unique IDs were not preserved on the original
Mac HotSync. If you want to store references to records in other records (say to build
a relational database), you may want to include your own ID field in each of your
records rather than relying on Palm OS's unique IDs.
-
Danny Epstein, Applied Thought Corporation
Have friends with Palm organizers? Get BeamBooks!
http://www.appliedthought.com/beambooks