Closed casperhart closed 12 months ago
This implicit but not so implicit deletion flag has caused me some troubles in the past.
For example the reader's computation does not include the deletion flag size, but that's ok because it reads it and skip the rest of the record if its marked deleted.
https://github.com/tmontaigu/dbase-rs/pull/75 Should be the correct fix for the dbase::File
While trying to finis #77, I found that even the newly introduced stations.dbf does not have its header's size_of_record include the size of deletion flag.
So propably recomputing the record_size is safer than trusting the header.
Are you sure? The new one has the size of record bytes = F903 = 1017 which looks correct (4 fields @ 254 bytes each + deletion flag). The old one was 1016.
Ah yes you are right, I got confused, its the stations_with_deleted.dbf
that is not correct
Switching from
Reader
toFile
gives different behaviour when calculating record offsets, so a file that's read correctly withReader
is read incorrectly usingFile
. For example the following usesReader
:But then switching to
File
I get:This is because
Reader
calculates record size as the following (excluding deletion flag) which is correct in all cases:Whereas
File
gets the record size from the header, and then adds the deletion flag size when calculating the record offset. But the record size in the header already includes the deletion flag size, so I get an off-by-one issue with my FoxPro 2.x file with memo.This doc suggests the record size in the header includes the deletion flag size, so I believe my file is in spec: https://www.dbf2002.com/dbf-file-format.html. But I don't know if this is the case for all dbase files, or just some types like foxpro? Is there a different spec that suggests otherwise?
The fix for this is very easy, just remove
+ DELETION_FLAG_SIZE
from here: https://github.com/tmontaigu/dbase-rs/blob/ddb11cbae4086f99cf10fbf55b2885fc2adfcc84/src/header.rs#L416, but I don't want to break other's code.