1

I am trying to add a record to an existing and empty DBF table (Fox Pro) that has an index file and a memo file. It already exists in my folder:

Table.dbf
Table.fpt
Table.cdx

Table.dbf has three fields:

Field1 (Integer)
Field2 (Character)
Field3 (Memo)

I use the method as described in

http://stackoverflow.com/questions/37891686/how-to-add-a-field-to-a-dbf-file

It is as follows:

import dbf

db = dbf.Table('table.dbf')
db.open() 
rec = dbf.create_template(db) 
rec.field1 = 9 
rec.field2 = ('some text')
db.append(rec)

So far so good. The problem is when a field is of type memo

Db = dbf.Table ('table.dbf')
Db.open ()
Rec = dbf.create_template (db)
Rec.field1 = 9
Rec.field2 = ('some text')
Rec.field3 = ('This is a long text')
Db.append (rec)

Then I have an error message:

Traceback (most recent call last):
   File "dbf12.py", line 8, in <module>
     Rec.field3= ('This is a long text')
   File "...libsite-packages\dbf\ver_33.py", line 2959, in __setattr__
     Self._dirty = True
   File "...libsite-packages\dbf\ver_33.py", line 2956, in __setattr__
     Raise FieldMissingError (name)
Dbf.ver_33.FieldMissingError: '_dirty: no such field in table'

I have looked at a similar question in

Http://stackoverflow.com/questions/16682470/using-python-to-write-dbf-table-with-fpt-memos?rq=1

I tried to change:

Db = dbf.Table ('table.dbf', dbf_type = 'Vfp')

But the result is the same.

Does anyone know the correct way to enter the memo field?

Thanks.

Luis GP
  • 13
  • 3

1 Answers1

0

I'm not seeing this behavior in the latest version, but if you are unable to upgrade you have a couple other choices:

  • pass the data in as a tuple (fields must be in order)

  • pass the data in as a dict

For example:

db.append( (9, 'some text', 'a lot of text') )

or

db.append( {'field1': 9, 'field3': 'a lot of text', 'field2': 'some text'} )
Ethan Furman
  • 63,992
  • 20
  • 159
  • 237
  • Great!. Works with the second option, But following the example should be db.append(..., not dbf.append(.... I have seen that you are the author of the python DBF package. Congratulations, I find it very useful. Thanks for your help. K.R. – Luis GP Apr 09 '17 at 23:15
  • @LuisGP: Thanks, fixed the second example. You're welcome! – Ethan Furman Apr 09 '17 at 23:16