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