Perhaps it is not finding the correct record because of the way you are
searching. Are the records in the database guaranteed to be sorted by
the prodno field? If not, the search will not return the correct number,
and I think you would be better off writing your own search function.
Just open every record in turn and test to see if it is the correct one
until you find it.

Jonathan King

> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:bounce-417579-
> [EMAIL PROTECTED] On Behalf Of iajfoj jgoiejoisjo
> Sent: Sunday, March 20, 2005 6:04 PM
> To: Palm Developer Forum
> Subject: Very Urgent (Please respond by the end of today, my job
depends
> on it :<)
> 
> I am right at the last stage of the development cycle of a form I am
> writing for my new job and I have hit a major snag.
> 
> Database access :<
> 
> What I want to do is simple, I want to access a .pdb database, do a
binary
> search to find a record with the corresponding prodno unique id. I
have
> never accessed a database on a palm before, this all a first for me
and I
> seem to be so close.
> 
> What I get at this stage is a seemingly valid dbID of like 8552589 or
> something, a dbP that has the same value as my eventP and formP (I'm
not
> sure if that means I am not connecting right) a recordNumber (or
Index) of
> 1(not desired), and a bunch of completely insane values in my pointer
> record and basic record.
> 
> So dbID and dbP seem to be working, while DmFindSortPosition and
possibly
> my method of reading from the record handle are faulty. I really can't
> pinpoint it!
> 
> Here is some relevent code:  (Not copy and pasted, so ignore simple
typos)
> 
> //My Record Structure
> typedef struct
> {
> char prodno[21];
> char upc[21];
> char retail[11];
> etc. (all char values of correct size)
> }UPCD;
> 
> 
> //My Database Access (I am positive I have the correct db name)
> LocalID dbID = DmFindDatabase(0, "Detail-PMOO");
> DmOpenRef dbP = DmOpenDatabase(0, dbID, dmModeReadOnly);
> 
> //The Comparison Function for the DmFindSortPosition(I am very
unconfident
> in this function and based it exactly off of an example function I
found
> in two locations on the internet)
> 
> static int CompareRecordFunc(UPCD *rec1, UPCD *rec2, int unusedInt,
> SortRecordInfoPtr unused1, SortRecordInfoPtr unused2, int appInfoH)
> {
> int result;
> result = StrCompare(rec1->prodno, rec2->prodno);
> return result
> }
> 
> //The Binary Search
> UPCD FindRecord;
> UPCD *Record;
> StrCopy(FindRecord.prodno ,"00000000011");
> UInt32 recordNumber = DmFindSortPosition(dbP, &FindRecord, 0,
(DmComparF
> *) CompareRecordFunc, 0);
> if (recordNumber > 0) {
> MemHandle recH;
> recH = DmQueryRecord(dbP, recordNumber - 1);
> Record = (UPCD *) MemHandleLock(recH);
> Boolean foundIt = StrCompare(FindRecord.prodno, Record->prodno);
> MemHandleUnlock(recH); }
> 
> if (foundIt) {
> SetFieldText( MainDescriptionField, Record->prodno, 30, true);
> }
> 
> //Then close database and that's it.
> I think the possible problem areas are in the comparison function,
making
> Record = the memhandle, opening the database(somehow, it doesn't error
and
> dbID seems valid.
> 
> Another issue is packing, I don't understand what packing and
unpacking
> databases means. Do you have to unpack a database to read records from
it?
> 
> That's all I can think of, thank you for any help you give me, this is
SO
> very appreciated.
> 
> , Jamie
> --
> For information on using the Palm Developer Forums, or to unsubscribe,
> please see http://www.palmos.com/dev/support/forums/



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

Reply via email to