1
votes

I'm trying to read rows of data from a csv and append them as records to an existing Visual FoxPro dbf. The existing Visual FoxPro dbf has many fields that are greater than 10 characters long, but this causes an error when using modules dbf or dbfpy.

Here is an example with a simplified version of the table structure:

import dbf
table=dbf.from_csv('seasdate.csv',field_names="zone_num   season_code",dbf_type='Vfp')
#table to write to
table2=('temptable','zone_num C(2); season_code C(1)',dbf_type='Vfp')
for datum in table:
    table2.append(datum)

This returns: 'dbf.ver_2.FieldSpecError: Maximum field name length is 10. 'season_code' is 11 characters long.'

I know it is possible to have a field name greater than 10 characters long in a Vfp table because, as I mentioned, the table I ultimately will append to already exists. Any help is greatly appreciated!

2
I don't remember implementing long field names; can you send me a small dbf with a couple long field names? I'll see what I can do. My email is in the package.Ethan Furman
Hi Ethan, I tried sending an email to the address listed in the package and it bounced back.herdnerd
It's my first name at stoneleaf dot us.Ethan Furman

2 Answers

1
votes

I don't use dbfpy but looking at that syntax, it looks like you are creating new "free" tables. Free tables' fieldNames are limited to 10 in length.

Probably you should look at www.leafe.com and Dabo Framework there. Ed Leafe is from VFP community and he is well aware of VFP database formats.

0
votes

As a work-around, the field names stored in the .dbf file are only 10 characters long -- the first 10, as it happens (I'm not sure if the first 10 characters must be unique, or how VFP handles that, though.) So if your field names are all unique in the first 10, just use the truncated names:

table2=('temptable','zone_num C(2); season_cod C(1)',dbf_type='Vfp')

Currently dbf does not support the long field names. If you want to get me a sample VFP .dbc with long field names I would be happy to look at adding that support.