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

dbf.Table() Overwrites existing files if 'field_specs' are specified #18

Open
mimminou opened this issue Aug 20, 2021 · 0 comments
Open
Labels
enhancement New feature or request

Comments

@mimminou
Copy link

dbf module should warn the user if they are overwriting any existing files when calling dbf.Table()
What i tried to do was open my dBase III file on memory :

myDatabaseFile = path-to-my-file
testTable = dbf.Table(filename=myDatabaseFile, on_Disk=False).open(dbf.READ_ONLY)
print("Number of records on this file : " + str(testTable.__len__()))

This threw an error :

dbf.DbfError: field list must be specified for memory tables

What i did not know was that this module (probably) does support loading a file into memory, but only throught create_index(), so i foulishly added the field specs to the arguments and restarted the test. And lo and behold :

Number of records on this file : 0

Turns out i nuked an entire 56K records database in an instant, the database file itself was deleted from that folder. Fortunately i had several backups.
Still, i think that the READ_ONLY flag is very deceptive, since the code will delete or overwrite an existing file without warning (depending on how you set on_Disk) if the field_specs are specified. READ_ONLY should also throw an error when specifying field_specs, since the developer will have to populate the database it anyways.

@ethanfurman ethanfurman added the enhancement New feature or request label Dec 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants