|
From: Nacho U. <nac...@gm...> - 2008-03-12 19:51:17
|
Hello,
I have created a dbf file using dbfpy without any error message, but any
program was able to open it. Finally, I realize that dbfpy doesn't test if
the fieldnames has 10 or less characters.
Maybe it will be a nice improvement to do!
At the moment, I've made a little change at header.py to solve this problem.
Best regards,
Nacho Varela
### header.py
####################################
def _addField(self, *defs):
"""Internal variant of the `addField` method.
This method doesn't set `self.changed` field to True.
Return value is a length of the appended records.
Note: this method doesn't modify ``recordLength`` and
``headerLength`` fields. Use `addField` instead of this
method if you don't exactly know what you're doing.
"""
# insure we have dbf.DbfFieldDef instances first (instantiation
# from the tuple could raise an error, in such a case I don't
# wanna add any of the definitions -- all will be ignored)
_defs = []
_recordLength = 0
for _def in defs:
if isinstance(_def, fields.DbfFieldDef):
_obj = _def
else:
(_name, _type, _len, _dec) = (tuple(_def) + (None,) * 4)[:4]
_cls = fields.lookupFor(_type)
### [Nacho Uve] Just take the first 10 characters of the
fieldname
_obj = _cls(_name[0:10], _len, _dec,
ignoreErrors=self._ignore_errors)
_recordLength += _obj.length
_defs.append(_obj)
# and now extend field definitions and
# update record length
self.fields += _defs
return _recordLength
|