Menu

#17 Add support for the extended fields

-
open
nobody
None
5
2015-08-09
2015-04-11
No

Look at the complete fields description:
http://www.clicketyclick.dk/databases/xbase/format/data_types.html

I have met the file with the fields marked with codes 'V' and '0'.

Discussion

  • George

    George - 2015-07-08

    Am I right in thinking this is the cause of the error...

    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "c:\python27\lib\site-packages\dbfpy\dbf.py", line 138, in init
    self.header = self.HeaderClass.fromStream(self.stream)
    File "c:\python27\lib\site-packages\dbfpy\header.py", line 128, in fromStream
    _fld = fields.lookupFor(_data[11]).fromString(_data, _pos)
    File "c:\python27\lib\site-packages\dbfpy\fields.py", line 473, in lookupFor
    return _fieldsRegistry[typeCode]
    KeyError: '0'

     
  • Alexey Kolyanov

    Alexey Kolyanov - 2015-07-08

    As I remember it helped me to work with this by adding 2 classes as workaround. File 'fields.py':

    class DbfVarCharacterFieldDef(DbfFieldDef):
        """Definition of the character field."""
    
        typeCode = "V"
        defaultValue = ""
    
        def decodeValue(self, value):
            """Return string object.
    
            Return value is a ``value`` argument with stripped right spaces.
    
            """
            return value  # .rstrip(" ")
    
        def encodeValue(self, value):
            """Return raw data string encoded from a ``value``."""
            return str(value)[:self.length].ljust(self.length)
    
    class DbfCharacterNameFieldDef(DbfFieldDef):
        """Definition of the character field."""
    
        typeCode = "0"
        defaultValue = ""
    
        def decodeValue(self, value):
            """Return string object.
    
            Return value is a ``value`` argument with stripped right spaces.
    
            """
            return value.rstrip(" ")
    
        def encodeValue(self, value):
            """Return raw data string encoded from a ``value``."""
            return str(value)[:self.length].ljust(self.length)
    
     
  • Aleksandr Smyshliaev

    Please, can you provide an example data file?

     
  • Alexey Kolyanov

    Alexey Kolyanov - 2015-08-09

    I cannot, sorry. It was the file of my client.

     

Log in to post a comment.