ID:               47113
 Updated by:       fel...@php.net
 Reported By:      Shock dot art at gmail dot com
 Status:           Bogus
 Bug Type:         dBase related
 Operating System: FreeBSD 6.3-STABLE
 PHP Version:      5.2.8
 New Comment:

"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.


Previous Comments:
------------------------------------------------------------------------

[2009-01-18 10:45:09] 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 10:29:06] Shock dot art at gmail dot com

Don't fixed!

------------------------------------------------------------------------

[2009-01-17 22:37:26] fel...@php.net

Duplicated of Bug #46282, which was hopefully fixed today.
Thanks.

------------------------------------------------------------------------

[2009-01-15 10:46:39] Shock dot art at gmail dot com

Creating a dBase file with a DATE-field type, will corrupt the
database.

------------------------------------------------------------------------

[2009-01-15 10:43:36] 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.


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=47113&edit=1

Reply via email to