At 11:44 AM 5/10/2000, Eric Sun wrote:
>Each record in the table has fields of information. And the foreign key is
>basically a field in the table (i.e. part of the record's data).  Since the
>index is assigned internally (correct me if I am wrong), this is not part of
>the data so I do not really have control over  this.  Hence I cannot search
>a database base on their ID or Index.  Therefore,  probably the search will
>have to be linear.  Or sort out the database and have it use quick sort or
>something.

I'm probably going to offend you by stating the obvious, but I want to be clear, so 
please don't take offense...

Each record in a PalmOS database has both an index and a unique ID in addition to the 
actual data provided by the application. If you always add records to the database at 
the end, the first record will have index 0, the second will have index 1, and so on. 
You can also add records in the middle, shifting up existing records as necessary to 
maintain a chosen sort order. In this case, a record can move from one index to 
another. Accessing records by index is fast, much like accessing an element of an 
array. When you create a database record, it gets assigned a unique ID. This ID is 
independent of both the data in the record and the position of the record in the 
database. Inserting records in the middle to maintain a sort order will not change the 
unique IDs of the records. Accessing records by unique ID is slow. It just looks at 
each record in turn until it finds the one with the unique ID specified. You can 
include space in one database's record format for a foreign key reference using either 
of these or using some other key that you use to search for the corresponding record.

 From your response to another poster on the list, it sounds like these databases are 
static. If they truly never change, then there is no problem with using the index to 
refer to records in one database from another. If that works, it's faster than a 
binary search, and you don't have to sort the database.
--
Peter Epstein
Palm Inc. Developer


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

Reply via email to