php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52112 dbase_get_record() returns integer instead of decimal values
Submitted: 2010-06-17 19:16 UTC Modified: 2016-08-11 14:08 UTC
Votes:4
Avg. Score:4.8 ± 0.4
Reproduced:4 of 4 (100.0%)
Same Version:1 (25.0%)
Same OS:2 (50.0%)
From: velociraptor at bluewin dot ch Assigned: cmb (profile)
Status: Closed Package: dbase (PECL)
PHP Version: 5.2.13 OS: Linux (OpenSuse 11.1 64), WinXP
Private report: No CVE-ID: None
 [2010-06-17 19:16 UTC] velociraptor at bluewin dot ch
Description:
------------
dbase_get_record_with_names() doesn't work as expected for me:

I run PHP-GTK on four machines:

- Slackware Linux 13.1 32bit   (PHP 5.2.8)
- OpenSuse Linux 11.1 64bit    (PHP 5.2.8)
- Windows Vista 32bit          (PHP 5.2.6)  *OK*
- Windows XP 32bit             (PHP 5.2.6)

Both Windows machines use the exactly same PHP-GTK compilation with PHP 5.2.6, whereas on Linux I run 2 independently compiled PHP/PHP-GTK installations.

On both Linux machines and on Windows XP dbase_get_record_with_names() fails to output decimal values (dBase number fields with a precision higher than 0) correctly, whereas on Vista the output is formatted as expected (eventhough the compilation used on Vista is exactly the same as the one I use on XP. I even replaced the installation on XP with the one I have on Vista, without any effects).

Now, what happens with the output is as follows:

One expects to receive a decimal string when requesting the content of a number field with the precision of 1 position or higher (ex: 'p2,N,4,2'). Now, what happens is that every position after the comma/dot is stripped away (on the systems where this error occurs).

I have no idea why it works on Windows Vista, but not on my other machines. However, I thought it could eventually have to do with internationalization? In central europe we use to separate the full number with comma instead of the dot. Is it possible that my Windows Vista somehow handles that differently than XP, Suse and Slack?


Test script:
---------------
#!/usr/bin/php-gtk
<?php
      echo "\ndBase_get_record_with_names() - - TEST" .
           "\nPHP 5.2.8" .
           "\n======================================\n\n";
      
      // dBase-file
      // ==========
      
      $db_path = "test.dbf";
      
      // open dBase-file
      // ===============
      
      $db = dbase_open($db_path, 0) or die("Failed to open '$db_path'.");
      
      if($db){
         
         // show dBase-header
         // =================
         
         echo "# header info\n\n";
         $info = dbase_get_header_info($db);
         print_r($info);
         
         // show contents
         // =============
         
         echo "\n\n# contents\n\n";
         $rows = dbase_numrecords($db);
         for($i = 1; $i <= $rows; $i++){
            $dBase_row = dbase_get_record_with_names($db, $i);
            print_r($dBase_row);
         }
      }
      
      echo "\n";
?>

Expected result:
----------------
dBase_get_record_with_names() - - TEST
PHP 5.2.8                             
======================================

# header info

Array
(    
    [0] => Array
        (       
            [name] => int
            [type] => number
            [length] => 2   
            [precision] => 0
            [format] => %2s 
            [offset] => 1   
        )                   

    [1] => Array
        (       
            [name] => p2
            [type] => number
            [length] => 4   
            [precision] => 2
            [format] => %4s 
            [offset] => 3   
        )                   

    [2] => Array
        (       
            [name] => p3
            [type] => number
            [length] => 5   
            [precision] => 3
            [format] => %5s 
            [offset] => 7   
        )                   

)


# contents

Array
(
    [int] => 44
    [p2] => 3.56
    [p3] => 6.341
    [deleted] => 0
)
Array
(
    [int] => 55
    [p2] => 1.05
    [p3] => 3.820
    [deleted] => 0
)


Actual result:
--------------
dBase_get_record_with_names() - - TEST
PHP 5.2.8                             
======================================

# header info

Array
(    
    [0] => Array
        (       
            [name] => int
            [type] => number
            [length] => 2   
            [precision] => 0
            [format] => %2s 
            [offset] => 1   
        )                   

    [1] => Array
        (       
            [name] => p2
            [type] => number
            [length] => 4   
            [precision] => 2
            [format] => %4s 
            [offset] => 3   
        )                   

    [2] => Array
        (       
            [name] => p3
            [type] => number
            [length] => 5   
            [precision] => 3
            [format] => %5s 
            [offset] => 7   
        )                   

)


# contents

Array
(
    [int] => 44
    [p2] => 3
    [p3] => 6
    [deleted] => 0
)
Array
(
    [int] => 55
    [p2] => 1
    [p3] => 3
    [deleted] => 0
)


Patches

bug52112 (last revision 2016-08-06 12:20 UTC by cmb@php.net)

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-07-10 14:07 UTC] cmb@php.net
-Package: dBase related +Package: dbase
 [2016-08-05 19:12 UTC] cmb@php.net
-Status: Open +Status: Analyzed -Assigned To: +Assigned To: cmb
 [2016-08-05 19:12 UTC] cmb@php.net
> However, I thought it could eventually have to do with
> internationalization?

Indeed, that is the case. The dbase extension uses atof() in
php_dbase_get_record[1] to convert the string value read from the
DBF into a double, but atof() is locale dependend. Using
zend_strtod() instead should solve the issue.

[1] <http://svn.php.net/viewvc/pecl/dbase/trunk/dbase.c?revision=338472&view=markup>
 [2016-08-06 12:18 UTC] cmb@php.net
-Summary: dbase_get_record_with_names() returns integer instead of decimal values +Summary: dbase_get_record() returns integer instead of decimal values
 [2016-08-06 12:20 UTC] cmb@php.net
The following patch has been added/updated:

Patch Name: bug52112
Revision:   1470486001
URL:        https://bugs.php.net/patch-display.php?bug=52112&patch=bug52112&revision=1470486001
 [2016-08-11 13:59 UTC] cmb@php.net
Automatic comment from SVN on behalf of cmb
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=339851
Log: Fix #52112: dbase_get_record() returns integer instead of decimal values

We're going to use zend_strtod() instead of atof() when reading decimal
values from a DBF to avoid any locale specific behavior.
 [2016-08-11 14:01 UTC] cmb@php.net
Automatic comment from SVN on behalf of cmb
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=339852
Log: Merged revision(s) 339849-339851 from pecl/dbase/branches/dbase-5.1:

Fix #52112: dbase_get_record() returns integer instead of decimal values

We're going to use zend_strtod() instead of atof() when reading decimal
values from a DBF to avoid any locale specific behavior.
 [2016-08-11 14:02 UTC] cmb@php.net
-Status: Analyzed +Status: Closed
 [2016-08-11 14:08 UTC] cmb@php.net
The fix for this bug has been committed.

Thank you for the report, and for helping us make PHP better.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Sat Jan 18 15:01:23 2020 UTC