You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've noticed that if a Visual FoxPro DBase file (TableType::VISUAL_FOXPRO) already exists, you can open and modify it just fine. This is because its Header Length is already defined.
However, if you're creating one from scratch, it has to generate the Header and this fails. This is because there is no Specification defined for Visual FoxPro so it falls back to the default. Edit: Actually, the issue is TableCreator::prepare_header() in this case. See my next comment.
This results in a non-integer value from VisualFoxproHeaderReader::getLogicalFieldCount() which throws an exception.
I've been trying to determine how to get the necessary values for a valid Specification without success. Is there any documentation out there regarding how to get this information? I've been unable to find anything myself.
The text was updated successfully, but these errors were encountered:
It seems that the Header Length itself just needs some adjustments in how it is calculated, likely using the extractArgs method for the VisualFoxproHeaderReader Class.
Edit:
The primary culprit is TableCreator::prepareHeader() where it writes the Header Length. This doesn't take into consideration the Backlist Length for Visual FoxPro files.
Given the global use of TableCreator for any DBase file, I don't think there's a good way to adjust that behavior without making Classes that extend it to adjust this behavior similar to how the Specification and HeaderReader Classes work.
In my case, I may just calculate the appropriate Header Length and write it to the file after it is created. This should solve my immediate problem.
Edit 2:
Here's the code I wrote to patch the Header Length after creating my table.
$file_stream = Stream::createFromFile( $path, 'rb+' );
// Position of first record is stored in bytes 8-9
$file_stream->seek( 8 );
$saved_header_length = $file_stream->readUShort();
// Calculate correct Header Length. Just have to add the length of the Backlist in there
$header_length = $saved_header_length + VisualFoxproHeaderReader::VFP_BACKLIST_LENGTH;
// Write the corrected Header Length to the proper offset
$file_stream->seek( 8 );
$file_stream->writeUShort( $header_length );
$file_stream->close();
// This helps to confirm that our adjusted Header Length worked by attempting to parse the Header
$table_reader = new TableReader( $path );
$table_reader->close();
d4mation
changed the title
Creating Visual FoxPro files
Creating Visual FoxPro files results in an incorrect Header Length
Sep 13, 2022
I've noticed that if a Visual FoxPro DBase file (
TableType::VISUAL_FOXPRO
) already exists, you can open and modify it just fine. This is because its Header Length is already defined.However, if you're creating one from scratch, it has to generate the Header and this fails.
This is because there is no Specification defined for Visual FoxPro so it falls back to the default.Edit: Actually, the issue isTableCreator::prepare_header()
in this case. See my next comment.php-xbase/src/Header/Specification/HeaderSpecificationFactory.php
Lines 11 to 19 in e818e35
This results in a non-integer value from
VisualFoxproHeaderReader::getLogicalFieldCount()
which throws an exception.I've been trying to determine how to get the necessary values for a valid Specification without success. Is there any documentation out there regarding how to get this information? I've been unable to find anything myself.
The text was updated successfully, but these errors were encountered: