Bug #13865 Updated: Bad booleans with dbase_get_record_with_names
| From: | sniper@php.net | Date: | Tue, 30 Oct 2001 23:52:00 +0000 |
| Subject: | Bug #13865 Updated: Bad booleans with dbase_get_record_with_names | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-69371@lists.php.net to get a copy of this message | ||
ID: 13865
Updated by: sniper
Reported By: cjames@callone.net
Status: Closed
Bug Type: dBase related
Operating System: Win32
PHP Version: 4.0.6
New Comment:
www.php4win.com has the win32 snapshots.
Previous Comments:
------------------------------------------------------------------------
[2001-10-30 18:51:05] sniper@php.net
This is fixed in CVS. Try a snapshot from http://snaps.php.net/
------------------------------------------------------------------------
[2001-10-30 16:19:37] cjames@callone.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-29 15:40:06] cjames@callone.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
------------------------------------------------------------------------
Edit this bug report at http://bugs.php.net/?id=13865&edit=1