I use UniqueID to link records within the same DB and it works fine (so
far). I use the following, admittedly inefficient, method to locate a record
by it's ID:
/************************************************************
*
* FUNCTION: PktLibGetRecordByID
*
* DESCRIPTION: Get a record from the Database by its UniqueID
*
* PARAMETERS: database pointer - open db pointer
* uniqueid - localid of record to lock
* record pointer - pointer structure
* record - MemHandle to unlock when done
*
* RETURNS: ##0 if successful, errorcode if not
*
* The record's MemHandle is locked so that the pointer to
* strings within the record remain pointing to valid chunk
* versus the record randomly moving. Unlock the MemHandle when
* PktLibDBRecord is destroyed.
*
*************************************************************/
Err PktLibGetRecordByID(DmOpenRef dbP, UInt32 id,
PktLibDBRecordPtr recordP, MemHandle *recordH)
{
UInt16 index = 0;
UInt16 num, attr;
UInt32 rid;
num = DmNumRecords(dbP);
while (index < num) {
DmRecordInfo(dbP, index, &attr, &rid, NULL);
if (id == rid && !(attr & dmRecAttrDelete))
break;
index++;
}
if (index < num)
return PktLibGetRecord(dbP, index, recordP, recordH);
else
return 1;
}
It MAY be possible to use the memory manager to get a direct handle to the
record by ID using MemLocalIDToLockedPtr, but I'm not sure, I haven't tried
it out.
"Ben A. HiLLeLi" <[EMAIL PROTECTED]> wrote in message
news:77587@palm-dev-forum...
>
> After too much deliberation I've decided on using the PalmOS assigned
> UniqueID as a "primary key" and as the lookup attribute that will "link"
two
> related databases:
> i.e. AllergyRecord.PatientIDLink=Patient.UniqueID...
>
> to get patient referenced in AllergyRecord:
> DmFindRecordByID(gPatientDB, AllergyRecord.PatientIDLink, &index_out)
> DmQueryRecord(gPatientDB, index_out)
> or something like that...
>
> I have not invested that much time in the conduit yet and want to know if
> there is sample code on importing record UniqueID's and/or the entire
record
> headers and using these as attributes in a desktop database... I think
once
> I get the UniqueID onto the PC (and into PC Endian) it won't be a problem
> assigning as a value to a dbase attribute...
>
> SideQ: When working with alphabetically sorted databases, what other
> efficient methods are there of doing a quick key lookup. Binary Searches
> would seem rather inefficient for they would require resorting by key,
then
> sorting back alphabetically. I'm looking for a backup (insurance :-O) to
the
> above method as I've heard experienced Palm developers say "USE the
> uniqueID, works for me" and "Don't Use uniqueID, it can change and/or not
be
> unique"... I was thinking of a two part key, one part Char: the letter the
> name starts with (used only for quicker searches as names can change) and
a
> permanent ID (iterative, last used stored in preferences)... Hopefully the
> first method workz (no insurance premiums...missed deadlines)
>
> Ben
> p.s. from what I've read in the documentation (briefly skimmed),
UniqueID's
> should stay constant during synchronization using more current versions of
> HotSynch... I'm a beginner looking for answers though, do NOT take my word
> on it AND/OR/PLEASE correct me...
>
>
>
>
>
>
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/