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

Bug #20291 Ignored in update $dao->field = 0
Submitted: 2014-06-05 14:42 UTC
From: yourchoicero Assigned: alan_k
Status: Closed Package: DB_DataObject (version 1.11.3)
PHP Version: 5.5.3 OS: windows8
Roadmaps: (Not assigned)    
Subscription  


 [2014-06-05 14:42 UTC] yourchoicero (Florin Yourchoice)
Description: ------------ If I try to update an field type integer with zero (0) value, it is ignored from update list ($dao->field = 0). Solution temporary found was to set zero as string: $dao->field = '0'; So I go back to the version 1.10.0 . Intermediar version till this last (1.11.3) don't like because ignore: &PEAR::getStaticProperty('DB_DataObject', 'lastError'). Expected result: ---------------- $dao_uti = DB_DataObject::factory($this->tableName); $dao_uti->uti_identifiant = $user; if($dao_uti->find(1)) { $dao_uti->uti_nb_failed_login = 0; $dao_uti->update(); } This (in the last vers. 1.11.3) ignore the field uti_nb_failed_login from sql update query. If I set a value >0 or i put 0 as string '0' working. With version 1.10.0 working.

Comments

 [2014-06-05 14:48 UTC] yourchoicero (Florin Yourchoice)
-Operating System: update +Operating System: windows8
 [2014-06-06 10:55 UTC] alan_k (Alan Knowles)
is 'field' defined as allow NULL (eg. does not have NOT NULL)
 [2014-06-06 17:16 UTC] yourchoicero (Florin Yourchoice)
`uti_nb_failed_login` int(4) DEFAULT NULL,
 [2014-06-06 17:21 UTC] yourchoicero (Florin Yourchoice)
But does not matter is null or not null. If I cannot set an integer, even 0, this it's a bug. Old version allow it.
 [2014-06-09 08:06 UTC] alan_k (Alan Knowles)
Can you test with the column as not null. Update the schema. It needs fixing but I need to be sure of the exact reason for it occurring
 [2015-03-06 05:34 UTC] mmn (Mikael Nordfeldth)
I just ran into this issue. The problem is that "disable_null_strings" will not only test against null _strings_ but anything that can be compared to false ('', 0, false...). Here is the code, starting around line 1345 in DB/DataObject.php (latest stable): if ((!isset($this->$k) || ($v == 1 && $this->$k == '')) && $ignore_null ) { continue; } If you change $this->$k == '' to $this->$k === '' a type-aware comparison will be made. Since "&& $ignore_null" is derived from the config value of "disable_null_strings" we only want to disable null _strings_, not anything that results in false. For example, this is true: 0 == '' which causes the problem of trying to set a value to 0 using default "disable null strings" unless the 0 value is given _as a string_ ('0'). To fix this properly everywhere, both the "update" and the "insert" functions need to be fixed identically. So a quick solution to this problem is to make the type-aware comparison with three equal signs: $this->$k === '' The code in the "insert" function looks like this around line 1097, you can see it is exactly the same: if ( (!isset($this->$k) || ($v == 1 && $this->$k == '')) && $ignore_null ) { continue; } After fixing it should be: if ( (!isset($this->$k) || ($v == 1 && $this->$k === '')) && $ignore_null ) { continue; }
 [2015-03-06 05:40 UTC] mmn (Mikael Nordfeldth)
 [2015-03-06 08:38 UTC] alan_k (Alan Knowles)
-Status: Open +Status: Closed -Assigned To: +Assigned To: alan_k
This bug has been fixed in SVN. If this was a documentation problem, the fix will appear on pear.php.net by the end of next Sunday (CET). If this was a problem with the pear.php.net website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better. this has been changed in svn.