php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #13865 Bad booleans with dbase_get_record_with_names
Submitted: 2001-10-29 15:40 UTC Modified: 2001-10-30 18:52 UTC
From: cjames at callone dot net Assigned:
Status: Closed Package: dBase related
PHP Version: 4.0.6 OS: Win32
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: cjames at callone dot net
New email:
PHP Version: OS:

 

 [2001-10-29 15:40 UTC] cjames at callone dot net
dbase_get_record_with_names is not returning the correct values when I am checking a boolean field.  Here is the test I used.

function CreateDummy()
{
  $fields = array(
        array("NAME", "C", 32),
        array("MALE",  "L"));
  $db = dbase_create("dummy.dbf", $fields);
  dbase_add_record($db, array("Clinton", "T"));
  dbase_add_record($db, array("Debbie", "F"));
  dbase_add_record($db, array("Benjamin", "T"));
  dbase_add_record($db, array("Anna", "F"));
  dbase_close($db);
}

function WorkDummy()
{
  CreateDummy();  
  $db = dbase_open("dummy.dbf", 0);
  if ($db == FALSE)
  {
    echo "<h2>Unable to open the dbase.</h2>";
    exit;
  }
  for ($i = 0; $i < 4; $i++)
  {
    $dummy = dbase_get_record_with_names($db, $i+1);
    echo "$i NAME is ". $dummy['NAME'] ." and MALE is ". gettype($dummy['MALE']) . " of value ".$dummy['MALE']. "<br>\n";
  }
}

I get the following output.
0 NAME is Clinton and MALE is integer of value 0
1 NAME is Debbie and MALE is integer of value 0
2 NAME is Benjamin and MALE is integer of value 0
3 NAME is Anna and MALE is integer of value 0




Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-10-30 16:19 UTC] cjames at callone dot net
I looked over the code in dbase.c and saw that boolean values are not handled very well. I made some code changes and got the following output.

0 NAME is Clinton and MALE is boolean of value 1
1 NAME is Debbie and MALE is boolean of value 
2 NAME is Benjamin and MALE is boolean of value 1
3 NAME is Anna and MALE is boolean of value 

Here is a suggestion for a code change to dbase.c in the functions:
PHP_FUNCTION(dbase_get_record) {
PHP_FUNCTION(dbase_get_record_with_names) {

CHANGE -----------------------------------------------
  case 'N':  /* FALLS THROUGH */
  case 'L':  /* FALLS THROUGH */

TO     -----------------------------------------------
  case 'L':	/* 30 Oct 2001 clintonjames@email.com */
  { 
    int nValue = toupper(*get_field_val(data, cur_f, fnp));
    if (nValue == 'T' || nValue == 'F' || nValue == 'Y' || nValue == 'N') {
      /* make sure this is a boolean and not a NULL */
      add_assoc_bool(return_value,cur_f->db_fname, (nValue == 'T' || nValue =='Y'));
    } else {
      add_assoc_null(return_value,cur_f->db_fname);
    }
    break;
  }
  case 'N':	/* FALLS THROUGH */

 [2001-10-30 18:51 UTC] sniper@php.net
This is fixed in CVS. Try a snapshot from http://snaps.php.net/ 
 [2001-10-30 18:52 UTC] sniper@php.net
www.php4win.com has the win32 snapshots.

 [2024-04-08 20:20 UTC] git@php.net
Automatic comment on behalf of kocsismate (author) and web-flow (committer)
Revision: https://github.com/php/php-src/commit/2079da0158bc91fff4edd85ac66c89b40c4faf3a
Log: Fix #13865 Improve parameter and return value related deprecation messages (#13913)
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Mar 13 00:01:31 2025 UTC