php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #47113 Corrupt DBF When Using DATE
Submitted: 2009-01-15 10:43 UTC Modified: 2009-01-18 14:15 UTC
Votes:3
Avg. Score:5.0 ± 0.0
Reproduced:3 of 3 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: Shock dot art at gmail dot com Assigned:
Status: Not a bug Package: dBase related
PHP Version: 5.2.8 OS: FreeBSD 6.3-STABLE
Private report: No CVE-ID: None
 [2009-01-15 10:43 UTC] Shock dot art at gmail dot com
Description:
------------
Creating or opening a dBase file with a DATE-field type, will create a database with lenght = 0 for "date" field type.

Reproduce code:
---------------
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
 [2009-01-15 10:46 UTC] Shock dot art at gmail dot com
Creating a dBase file with a DATE-field type, will corrupt the database.
 [2009-01-17 22:37 UTC] felipe@php.net
Duplicated of Bug #46282, which was hopefully fixed today.
Thanks.
 [2009-01-18 10:29 UTC] Shock dot art at gmail dot com
Don't fixed!
 [2009-01-18 10:45 UTC] Shock dot art at gmail dot com
Be attentive!!!

To fix this bug maybe must do replace some lines in module dbf_head.c 
For function put_dbf_field()



In put_dbf_field 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);

maybe correct 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         case 'D':
202(delete) dbf->db_flen = 8;
202(add)    dbfield.dbf_flen[0] = 8;
   (add)    dbfield.dbf_flen[1] = ??? dbf->db_fdc;?

203         break;
204         case 'L':
205(delete) dbf->db_flen = 1;
205(add)    dbfield.dbf_flen[0] = 1;
   (add)    dbfield.dbf_flen[1] = ??? dbf->db_fdc;?
206         break;
207         default:
208             put_short(dbfield.dbf_flen, dbf->db_flen);



"dbfield.dbf_flen" and "dbf->db_flen" - is not the same!!! :)

compare with function "get_dbf_field": 

153	dbf->db_type = dbfield.dbf_type;
154	switch (dbf->db_type) {
155	    case 'N':
156	    case 'F':
157		dbf->db_flen = dbfield.dbf_flen[0];
158		dbf->db_fdc = dbfield.dbf_flen[1];
159		break;
160            case 'D':
161		dbf->db_flen = 8;
162		break;
163	    case 'L':
164		dbf->db_flen = 1;
165		break;
166	    default:
167	    	dbf->db_flen = get_short(dbfield.dbf_flen);
168		break;
169	}


I hopefully this is solve the problem and someone with an CVS account can use this info to 
get the change into the repository.
And i hope that "someone with an CVS" don't be a lazy for check my code. :)
 [2009-01-18 14:15 UTC] felipe@php.net
"dbfield.dbf_flen" and "dbf->db_flen" - is not the same!!! :)

Sure, that was the problem. And 'D' an 'L' can use perfectly the put_short(). They doesnt requires setting the value manually as 'N'.

What problem are you seeing? Thanks.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 22:01:30 2024 UTC