You've got to do a couple things for this to work. First, whenever you
archive or delete a record, you need to move it to the end of the database
using DmMoveRecord(StationDB, recordNum, DmNumRecords(StationDB)). But
remember you only need to archive/delete records if you intend to have a
desktop conduit that syncs the data to the desktop -- otherwise just use
DmRemoveRecord() and don't worry about deleted records.

next, use the DmQueryNextInCategory() function to fetch all records - it
stops when it hits a deleted record.

The correct method to access all records and avoid deleted records is to
use:

        UInt recordNum;
        VoidHand recHandle;

        recordNum = 0;
        recHandle = DmQueryNextInCategory (StationDB, &recordNum,
dmAllCategories);

        while (recHandle) {
             // handle record
                ++recordNum; // get next record
                recHandle = DmQueryNextInCategory (StationDB, &recordNum,
dmAllCategories);
        }

==-
John Schettino author of
Palm OS Programming For Dummies, http://schettino.tripod.com

-----Original Message-----
Subject: how to iterate through all records
From: Michael McFarland

After reading through the archives, I'm really not clear on this.  If I 
want to write a function that checks every record in the database to see 
(for instance) what the maximum value is for one of the fields, what's the 
best method to cycle through all *non-deleted* records?  Is it safe to use:

   UInt recordCount = DmNumRecords(StationDB);
   for (i=0; i<recordCount; i++)  {
      recHand = DmQuery(StationDB, i);
      // handle record
   }

Or will this give me records that shouldn't be accessed (ie, have been 
deleted but not hot-synced)?

Reply via email to