dbfpy3
dbfpy3 copied to clipboard
Does not update record_count
Hello, I am adding records to an existing dbf, the recs are correctly inserted, but the header field record_count is not incremented with the added records which leads to corrupt db file.
apparently problem here:
def flush(self, stream):
if not self.changed:
return
self.last_update = datetime.date.today()
self.write(stream)
you are indeed incrementing the record_count but you are not telling the header that a record was added. Adding this update into db.write() method fixes the issue:
if record.index is None:
# we must increase record count before set index,
# because set index will raise error if out of range
self.header.record_count += 1
record.index = self.header.record_count - 1
self.header._changed = True # <= added line to force header recalc