PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » Database » DB_DataObject » Bug #4919

->update sets numeric null cols to zero

Details

Submitted2005-07-26 11:42 UTC
Fromkuppiel at libero dot it
Assignedalan_k
StatusClosed
PackageDB_DataObject
PHP Version4.3.11
OSLinux 2.6.11-gentoo-r11
Roadmaps(Not assigned)

Comments

[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 )

[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 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-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!