php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #59968 Problem with date fields in a dbase table
Submitted: 2011-09-24 15:59 UTC Modified: 2016-08-14 04:22 UTC
From: larry at diabloresults dot com Assigned: cmb (profile)
Status: No Feedback Package: dbase (PECL)
PHP Version: 5.3.1 OS: Windows 7
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: larry at diabloresults dot com
New email:
PHP Version: OS:

 

 [2011-09-24 15:59 UTC] larry at diabloresults dot com
Description:
------------
I have created a dbase table with the following schema:

    $schema = array (
        array('ACCOUNTNO','c',20),
        array('COMPANY','c',40),
        array('CONTACT','c',40),
        array('LASTNAME','c',15),
        array('TITLE','c',30),
        array('PHONE1','c',25),
        array('PHONE2','c',25),
        array('PHONE3','c',25),
        array('FAX','c',25),
        array('EXT1','c',6),
        array('EXT2','c',6),
        array('EXT3','c',6),
        array('EXT4','c',6),
        array('ADDRESS1','c',40),
        array('ADDRESS2','c',40),
        array('CITY','c',26),
        array('STATE','c',3),
        array('ZIP','c',10),
        array('KEY5','c',20),
        array('UCRDEAEXP1','D'),
        array('UCREDSSN','c',11),
        array('UCREDFEDID','c',11),
        array('URECACLSEX','D'),
        array('URECATLSEX','D'),
        array('UCRTLEXP1','D'),
        array('UCRTST1','c',2),
        array('URECPALSEX','D')
    );
 I am trying to add the following record:

Array
(
    [0] => 1234FooBar
    [1] => 
    [2] => Paul W. Geiger
    [3] => Geiger
    [4] => Dr.
    [5] => (618)271-7061 Home
    [6] => 
    [7] => (618)795-0629 cell
    [8] =>  
    [9] => Home
    [10] => Cell
    [11] => Work
    [12] => 
    [13] => 2517 N. 38th Street;
    [14] => 
    [15] => Fairmont City
    [16] => IL
    [17] => 62201
    [18] => 
    [19] => 20110930
    [20] => ssn
    [21] => 
    [22] => 20110831
    [23] => 20090630
    [24] => 
    [25] => IL
    [26] => 00000000
)

Using my friendly dbf viewer, I get the following:

1234FooBar, ,Paul W. Geiger  ,Geiger ,Dr.  ,(618)271-7061 Home ,  ,(618)795-0629 cell ,  ,Home ,Cell ,Work , ,2517 N. 38th Street;  ,   ,Fairmont City ,IL ,62201 ,  ,09/30/2011,20110930ssn, , / / , / / , / / , , /20/ 

Note the first date field goes in correctly but the following fields are corrupted.  If I change all the date fields except the last one, the data in inserted 'correctly'.  This is not a viable solution as this dbf table is used to transfer data to a legacy system.

I have looked at hex dumps of the header and the Field Displacement in the record and the Field length are not specified/

Reproduce code:
---------------
<?php
    $schema = array (
        array('ACCOUNTNO','c',20),
        array('UCRDEAEXP1','D'),
        array('UCRTST1','c',2),
        array('URECPALSEX','D')
    );
    $dbf = dbase_create('TEST.DBF', $schema);
    $data = array('Text Data', '20110911', 'ST', '20111111');
    dbase_add_record($dbf, $data);
    dbase_close($dbf);
?>


Expected result:
----------------
From the dbf viewer:

Text Data,09/11/2011,ST,11/11/2011



Actual result:
--------------
From the dbf viewer:

Text Data,09/11/2011,20,11/ST/1109



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-10-03 03:58 UTC] alan at akbkhome dot com
This may be a windows issue. - it appears to work fine on unix, and I 
do not have any windows machines to test on.


<?php
dl('dbase.so');
if (file_exists('/tmp/TEST.DBF')) {
	unlink('/tmp/TEST.DBF');
}

    $schema = array (
        array('ACCOUNTNO','c',20),
        array('UCRDEAEXP1','D'),
        array('UCRTST1','c',2),
        array('URECPALSEX','D')
    );

    $dbf = dbase_create('/tmp/TEST.DBF', $schema);
    $data = array('Text Data', '20110911', 'ST', '20111111');
    dbase_add_record($dbf, $data);
    dbase_close($dbf);

// let's look at it..
passthru('/usr/bin/dbview /tmp/TEST.DBF');

------

Outputs:
Accountno  : Text Data
Ucrdeaexp1 : 20110911
Ucrtst1    : ST
Urecpalsex : 20111111
 [2016-08-06 16:09 UTC] cmb@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2016-08-06 16:09 UTC] cmb@php.net
> I have looked at hex dumps of the header and the Field
> Displacement in the record and the Field length are not
> specified/

I've tested your supplied script with current master of the PECL
dbase package, and the field lengths are correctly specified. The
field data address is indeed zeroed, but that appears to be not
uncommon, and according to the Xbase File Format Description[1]
this is only required for the dBASE and FoxPro applications, and
has different meaning for each.

> This may be a windows issue.

I have also verified that identical DBFs are produced under Linux
and Windows.

> Using my friendly dbf viewer, […]

Which one do you use?

[1] <http://www.clicketyclick.dk/databases/xbase/format/dbf.html#DBF_NOTE_6_TARGET>
 [2016-08-14 04:22 UTC] pecl-dev at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 03:01:28 2024 UTC