Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

record_count not updated when adding records #3

Open
kpoman opened this issue Mar 31, 2023 · 0 comments
Open

record_count not updated when adding records #3

kpoman opened this issue Mar 31, 2023 · 0 comments

Comments

@kpoman
Copy link

kpoman commented Mar 31, 2023

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 is 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant