jdbf icon indicating copy to clipboard operation
jdbf copied to clipboard

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

Open gstockr opened this issue 9 years ago • 1 comments

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.

gstockr avatar Aug 09 '16 17:08 gstockr

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();

wescleveland56 avatar May 01 '17 13:05 wescleveland56