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

Bug #4919 ->update sets numeric null cols to zero
Submitted: 2005-07-26 11:42 UTC
From: kuppiel at libero dot it Assigned: alan_k
Status: Closed Package: DB_DataObject
PHP Version: 4.3.11 OS: Linux 2.6.11-gentoo-r11
Roadmaps: (Not assigned)    
Subscription  
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes. If this is not your bug, you can add a comment by following this link. If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
2005-12-29 03:08 UTC
Package:
Bug Type:
Summary:
From: kuppiel at libero dot it
New email:
PHP Version: Package Version: OS:

 

 [2005-07-26 11:42 UTC] kuppiel at libero dot it
Description: ------------ As the summary: the update method sets numeric null columns to zero in Postgresql. Zero and null are two very different things... Test script: --------------- $prod = new PoProduct; $prod->get($values['id']); $prod->setFrom($values); $id = $prod->update(); Expected result: ---------------- SQL from DB_DataObject::debugLevel(5) should be INSERT INTO products (supplier , supp_prod_id , prod_name , family , compound_prod , max_discount , valid ) VALUES ( 36 , '' , 'Prova' , null , null , null , 1 ) Actual result: -------------- SQL from DB_DataObject::debugLevel(5) is INSERT INTO products (supplier , supp_prod_id , prod_name , family , compound_prod , max_discount , valid ) VALUES ( 36 , '' , 'Prova' , 0 , 0 , 0 , 1 )

Comments

 [2005-07-26 11:48 UTC] kuppiel at libero dot it
Sorry: DB_DataObject version is 1.7.15.
 [2005-07-26 12:24 UTC] kuppiel at libero dot it
Update: columns' default is not set (and so is null).
 [2005-07-26 14:22 UTC] kuppiel at libero dot it
Solved replacing $this->$col = $value; with $this->$col = is_numeric($value) ? (float) $value : 'null'; at line 3548 in DataObject.php. I know it's quick and dirty but it works for me now. Maybe someone can do it better.
 [2005-07-26 14:29 UTC] alan_k
can you try and give a small reproducable example, the one you give - uses values not shown - call update, yet outputs insert? Thanks Alan
 [2005-07-26 16:41 UTC] kuppiel at libero dot it
Sorry, the test example should be: $prod = new PoProduct; $prod->setFrom($values); // Could be $_POST $id = $prod->insert(); However the problem is present with updates too. Thank you Alan.
 [2005-07-26 16:53 UTC] kuppiel at libero dot it
var_dump($values) gives array(8) { ["supplier"]=> string(2) "36" ["supp_prod_id"]=> string(0) "" ["prod_name"]=> string(5) "Prova" ["family"]=> string(0) "" ["compound_prod"]=> string(0) "" ["max_discount"]=> string(0) "" ["valid"]=> string(1) "1" ["save"]=> string(5) "Salva" } Thanks again
 [2005-07-26 23:34 UTC] alan_k
can you confirm a value of $value that has the problem: $value = array(); - has the problem. $value = array('compound_amount' => ''); - has the problem.
 [2005-07-26 23:38 UTC] alan_k
Try using the checkEmpty() method in setFrom function setFrom(&$from, $format = '%s', $checkEmpty=false) eg. $prod->setFrom($values,'%s',true);
 [2005-07-31 17:41 UTC] kuppiel at libero dot it
"$value = array();" has no sense in my situation, and "$value = array('compound_amount' => '');" has surely problems. Tried with checkEmpty but with no luck. Kamal
 [2005-12-14 13:00 UTC] bjartekv at gmail dot com
Has this issue been solved anywhere? I'm getting similar problems with DB_DataObject 1.7.15 I have a mysql table with the following column definition: grp_id INTEGER(10) UNSIGNED DEFAULT NULL When i insert a new row without setting grp_id it works fine, grp_id is set to NULL. However when i set grp_id to '' (like the empty value from a formbuilder select box) it gets set to 0. Which is fairly annoying considering i want to display an empty field not a 0. I also tried $do->setFrom($values,'%s',true); with no success. my hack around this is: $do->setFrom($form->exportValues()); $do->grp_id = is_numeric($do->grp_id) ? (float) $do->grp_id : 'null'; But its kinda ugly, so any chance this could be implemented? Thanks Bjarte
 [2005-12-20 19:16 UTC] bjartekv at gmail dot com
On second thought, this is perhaps the expected behaviour when inserting an empty string into an integer column. Sorry!
 [2005-12-22 03:19 UTC] alan_k
This bug has been fixed in CVS. 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. try CVS - skipEmpty is now actually used....
 [2005-12-29 03:08 UTC] alan_k
this should be fixed in 1.8.0