phargogh / dbfpy3

Port of DBFPY to Python 3

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Does not update record_count

kpoman opened this issue · comments

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