dbf
dbf copied to clipboard
dbf.Table() Overwrites existing files if 'field_specs' are specified
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.