Adrian Klaver wrote:
> On 07/18/2012 10:04 AM, Ethan Furman wrote:
>>
>> I think I'll go with option 1; if one really doesn't want to deal with
>> deleted records, then one can create an index based on the deleted flag
>> which doesn't include the deleted records (can't do that in Foxpro! that
>> I know of, anyway ;) :
>
> Than why have .use_deleted? If a programmer does not want to use deleted
> records then that should be respected by default.
>
Very good point, and very good question. If I keep .use_deleted I'll
have option 4 be the default, with option 1 a possibility:
def goto(self, recno, raise_if_deleted=True):
if is_deleted(self[recno)) and raise_if_deleted:
raise DbfError(
"Record %d is deleted and use_deleted is False" % recno)
self._index = recno
But about your very good question: why have .use_deleted? Well, it went
in long before I had usable indices, so at one point it was very
necessary. Now... not so much.
I am now contemplating removing .use_deleted, and having the index
method be the one used. This has the advantages of simpler code for me,
less questions like the above (a deleted record would not be physically
present in the index created by the below code), possible speed increase
(depending on how many records in the table are deleted), plus some
others I'm sure I'll think of after I hit <Send>. ;)
>> def ignore_deleted(record):
>> if dbf.deleted(record):
>> return dbf.DoNotIndex # record will not be present in the index
>> return dbf.recno(record)
Thoughts?
~Ethan~