Hi all,

I am new to PalmOS programming, though not new to C/C++.  I'm trying to
debug a program written by someone else.  It has the following snippet,
which is supposed to iterate over a database and delete some of its
entries:

UInt16 record_id;

for(record_id=0;record_id<DmNumRecords(ref);record_id++) {
        rec_h = DmQueryRecord(ref, record_id);
        ...
        if(...) {
                DmRemoveRecord(ref, record_id);
        }
}

This looks highly suspicious to me.  I can't believe that the record id's
are guaranteed to be sequential.  For instance, if records were deleted,
I'd think there would be gaps in the record id's (since as far as I can
tell, deleting one record shouldn't alter the id's of the others).  In
fact, DmQueryRecord sometimes fails, as if one of the records doesn't
exist.  Is this actually the right way to iterate over a database, and if
not, what is?  Bear in mind that I want to be able to delete from the
database as I iterate.

(I should note as a caveat that I can't be sure this is the cause of the
failure.  DmQueryRecord is actually called through another function which
does the error checking.  But other records are queried as well while this
is going on, and the failures could be from there, so it's only by
deduction that I suspect the above code.)

Thanks very much for any suggestions!

-- 
Nate Eldredge
[EMAIL PROTECTED]

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

Reply via email to