Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.1.1

Bug #17561 dba_exists() & dba_fetch() do not return correct data
Submitted: 2010-07-05 19:30 UTC
From: davidgibson2 Assigned:
Status: Open Package: DBA (version 1.1.1)
PHP Version: 5.3.2 OS: Windows XP, Apache 2.2.15
Roadmaps: (Not assigned)    
Subscription  


 [2010-07-05 19:30 UTC] davidgibson2 (David Gibson)
Description: ------------ In compatibility.php ... 1) function dba_exists($key, &$dba) returns true even when key does not exist 2) function dba_fetch($key, &$dba) returns true instead of fetching key Workarounds in compatibility.php ... function dba_exists($key, &$dba) { // return !PEAR::isError($dba->exists($key)); // (DG:) The above line appears to be incorrect. It is returning "true" // even when exists($key) is false. Here is a workaround... return $dba->exists($key); } function dba_fetch($key, &$dba) { // return !PEAR::isError($dba->fetch($key)); // (DG:) The above line appears to be incorrect, because we need to return the // actual data, not a flag. Here is a workaround... $fetched = $dba->fetch($key); if ($fetched == "DBA Error: key not found") { return false; } else return $fetched; } Test script: --------------- <?php require_once 'DBA/Compatibility.php'; $id = dba_open ("file_test", "n", "dbX"); // driver type is ignored echo dba_insert ('key0001', 'This is an example!', $id); echo dba_insert ('key9999', 'Another line of data', $id); echo dba_delete ('key9999', $id); // delete key echo dba_exists ('key9999', $id); // key is reported as still existing echo dba_fetch ('key0001', $id); // Returns true instead of data Expected result: ---------------- 111This is an example! Actual result: -------------- 11111

Comments