You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I was trying to read a dbf file, I found that when the dbf file has a wrong field type definition, it cannot read the data correctly.
e.g.
the blfm2 is actually filled with float, but it was mistakenly defined as 'C' type. If correctly parsed with the follwing method (dbf.py line 122) self._read_field_headers(infile)
def _read_field_headers(self, infile):
while True:
sep = infile.read(1)
if sep in (b'\r', b'\n', b''):
# End of field headers
break
field = DBFField.unpack(sep + infile.read(DBFField.size - 1))
field.type = chr(ord(field.type))
# For character fields > 255 bytes the high byte
# is stored in decimal_count.
if field.type in 'C':
field.length |= field.decimal_count << 8
field.decimal_count = 0
# Field name is b'\0' terminated.
field.name = self._decode_text(field.name.split(b'\0')[0])
if self.lowernames:
field.name = field.name.lower()
self.field_names.append(field.name)
self.fields.append(field)
it should produce DBFField like: DBFField(name='blfm2', type='C', address=196, length=17, decimal_count=12,
# For character fields > 255 bytes the high byte
# is stored in decimal_count.
if field.type in 'C':
field.length |= field.decimal_count << 8
field.decimal_count = 0
After I removed these lines, I finally got the correct result.
The text was updated successfully, but these errors were encountered:
hi,
When I was trying to read a dbf file, I found that when the dbf file has a wrong field type definition, it cannot read the data correctly.
e.g.
the blfm2 is actually filled with float, but it was mistakenly defined as 'C' type. If correctly parsed with the follwing method (dbf.py line 122)
self._read_field_headers(infile)
it should produce DBFField like:
DBFField(name='blfm2', type='C', address=196, length=17, decimal_count=12,
But the it turns out to be
DBFField(name='blfm2', type='C', address=196, length=3072, decimal_count=0
I think the problem is here:
After I removed these lines, I finally got the correct result.
The text was updated successfully, but these errors were encountered: