php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #46282 Corrupt DBF When Using DATE
Submitted: 2008-10-12 14:03 UTC Modified: 2009-01-17 17:22 UTC
Votes:17
Avg. Score:4.6 ± 0.8
Reproduced:15 of 15 (100.0%)
Same Version:1 (6.7%)
Same OS:0 (0.0%)
From: mattias dot geniar at gmail dot com Assigned:
Status: Closed Package: dBase related
PHP Version: 5.2.6 OS: CentOS 5.2
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
36 - 29 = ?
Subscribe to this entry?

 
 [2008-10-12 14:03 UTC] mattias dot geniar at gmail dot com
Description:
------------
Creating a dBase file with a DATE-field type, will corrupt the database. Work-around as for now is to use a CHAR-type and convert it later manually.

This bug is similar to #42261, which dates back to August 2007.

Reproduce code:
---------------
<?php
	// database "definition"
	$def = array(
	  array("date",     "D"),
	  array("name",     "C",  50),
	  array("email",    "C", 128),
	  array("ismember", "L")
	);

	// creation
	if (!dbase_create('test.dbf', $def)) {
	  echo "Error, can't create the database\n";
	}

	// open in read-write mode
	$db = dbase_open('test.dbf', 2);

	if ($db) {
		for ($i = 0; $i < 5; $i++) {
			dbase_add_record($db, array(
		              date('Ymd'),
		              'Name #'. $i,
		              'Email #'. $i,
		              'T'));
		}
	  dbase_close($db);
	}
?>


Expected result:
----------------
A simple database with 5 lines, where DATE, Name & Email are entered correctly.

Actual result:
--------------
The code above will create file called "test.dbf", which is corrupted when opening it with any normal DBF-viewer (CDBF, DBF Manager, ...). If the DATE-field is replaced with a CHAR-field, all works fine. Date-format is taken from the PHP.NET website and confirmed by the dBase-format.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-11-10 11:32 UTC] jani@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/


 [2008-11-18 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2009-01-15 10:48 UTC] no at spam dot net
I have the same problem on FreeBSD 6.3-STABLE, PHP5.2.8
 [2009-01-17 13:44 UTC] arne at bukkie dot nl
The problem is that a record of type D (date) as well as type L (logical) get's into the database with the length of 0 and not 8 (or 1 in the case of L). 

I traced down this bug to the put_dbf_field() function in dbf_head.c In there the record is written to disk, but in neither of the D and L types the length of the field is put in the correct struct. The fix is to remove both the cases for D and L so the length is set using the default case.

Was: 

196     switch (dbf->db_type) {
197         case 'N':
198         dbfield.dbf_flen[0] = dbf->db_flen;
199         dbfield.dbf_flen[1] = dbf->db_fdc;
200         break;
201         case 'D':
202         dbf->db_flen = 8;
203         break;
204         case 'L':
205         dbf->db_flen = 1;
206         break;
207         default:
208             put_short(dbfield.dbf_flen, dbf->db_flen);


Is:

196     switch (dbf->db_type) {
197         case 'N':
198         dbfield.dbf_flen[0] = dbf->db_flen;
199         dbfield.dbf_flen[1] = dbf->db_fdc;
200         break;
201         default:
202             put_short(dbfield.dbf_flen, dbf->db_flen);
203     }       


I am aware this is not the way to submit fixes but I'm limited by time and still wanted to share the knowledge I did proceed using comments to specify this. Hopefully someone with an CVS account can use this info to get the change into the repository.
 [2009-01-17 17:22 UTC] felipe@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.

Fixed, thanks for the patch!
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 14:01:31 2024 UTC