Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DbfReader GetString(fieldname) or GetBytes(fieldname) Return Incorrect Value #25

Open
gstockr opened this issue Aug 9, 2016 · 1 comment

Comments

@gstockr
Copy link

gstockr commented Aug 9, 2016

I am using Visual FoxPro table (type: VisualFoxPro1) and want to read it in Java. I always get blank or weird value (wrong place or wrong column or not full value) when I use GetString(fieldname) or GetBytes(fieldname). Example: I have a column called COMPNAME which has value "World Bank N.V.".

To get the value based on the field name, I write the code, rec.getString("COMPNAME") and it returns blank.

However, if I tried to get full row value such as rec.getBytes(), I could see "World Bank N.V."

Please advice what I did do wrong. I have set charset to cp1252 correctly.

@wescleveland56
Copy link

wescleveland56 commented May 1, 2017

I am having the same problem. I have a program that reads any .dbf file and dynamically copies data based on the meta data for that file. It knows nothing about the data within the file. It can read MANY (20+) Visual FoxPro1 files just fine. But there are 2 files that are defined identically that when it reads the first record, the first 232 bytes of the record contain 0x00 followed by the data that I expected to see at the beginning of the record. when it reads the second record, the first 232 bytes are the tail end of the first record. It appears that the offset for the data being read is not correct.

It turns out that there are 232 bytes between the header record terminator byte (0x0D) and the beginning of the first record.

After opening the file, all of the meta data seems correct to me.

The file contains:
00000000 : 30 11 04 16 66 00 00 00 E8 20 21 06 00 00 00 00
00000010 : 00 00 00 00 00 00 00 00 00 00 00 00 01 03 00 00
00000020 : 49 4E 44 43 4F 44 45 00 00 00 00 43 01 00 00 00
:
00001FC0 : 49 4E 44 43 4F 44 45 00 00 00 00 43 01 00 00 00
00001FD0 : 20 00 05 00 00 00 00 00 00 00 00 00 00 00 00 00
00001FE0 : 0D 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00001FF0 : 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
: same to
000020E0 : 00 00 00 00 00 00 00 00 20 30 31 30 33 20 32 31

After opening the file DbfMetadata contains:

  • type VisualFoxPro1
  • recordsQty 102
  • fullHeaderLength 8424
  • oneRecordLength 1569

All of the above are exactly as I expect. But, when I read the first record, the first 232 bytes contain 0x00 followed by the data that is at offset 0x20E8 into the file (0x20 0x30 0x31 0x30 0x33 0x20 0x32 0x31).

For those experiencing this same problem, here is my temporary workaround:

// Setup the file as usual
File dbfFile = new File( dbfPath + table + ".dbf" );
InputStream tblDbf = new FileInputStream( dbfFile );
DbfReader tblReader = new DbfReader( tblDbf );
// Bad record workaround
tblReader.read();
tblReader.findFirstRecord();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants