Re: Blank value problem with db+dataobject+formbuilder

From: Date: Thu, 02 Mar 2006 05:22:23 +0000
Subject: Re: Blank value problem with db+dataobject+formbuilder
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-23188@lists.php.net to get a copy of this message
On 3/1/06, Benjamin Wragg <bwragg@tpg.com.au> wrote: > Hi all, > > I'm having a problem when using formbuilder, Dataobject & DB using > postgresql when processing a form. If I have a form with some empty fields, > when I process it, I get two single quotes e.g '' put in the string fields > and 0 put in integer fields in the database rather than null values. > > Regarding the string problem, I've used a line by line debugger and followed > it through to line 1227 of DataObject.php where it passes the value of > string (which is an empty string) to $this->_quote. This then passes the > string to the quoteSmart function on line 495 of pgsql.php. Now here I think > is where things go wacky, as the empty string fails all checks and gets > returned using the last else: > > return "'" . $this->escapeSimple($in) . "'"; > > Is this how it should work? IMHO if a field is empty it should be saved as a > null not as ''. A '' in a database field is something! If I go to query a > field where it is null, all the '' won't be returned. > > Regarding the integer problem. I've again used a line by line debugger and > followed it through to line 1242 of DataObject.php where it runs intval over > the value returned from the form. Again this value is an empty string with a > length of 0. So intval returns 0 as the value. Again IMHO if a field is > empty it should be stored as null not 0. 0 is definitely something. > > > So is there a setting somewhere I am missing? Should I be doing something > else that I've missed? > DO and FB generally don't support NULL directly. As you say, an empty string is an empty string and not NULL. It is assumed that when you submit an empty value you are submitting something and hence NULL would be changing what you have submitted. Now, if your value in the DB is *actually* two single quotes and not an empty string then that's a definite bug. Try to figure out what's going on and submit a patch. Make sure that it doesn't break anything else though. As for making entries NULL you should be able to do this with the preProcessForm callback. Try setting the value of that field to DB_DataObject_Cast::sql('NULL'); -- Justin Patrin

« previous php.pear.general (#23188) next »