|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 11:00:01 2025 UTC |
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. :)