RE: [PEAR-DEV] RFC: slight modification to the get*Value() methods
| From: | Lukas Smith | Date: | Mon, 30 Dec 2002 11:56:36 +0000 |
| Subject: | RE: [PEAR-DEV] RFC: slight modification to the get*Value() methods | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-11952@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Lorenzo Alberton [mailto:l.alberton@quipo.it]
> Sent: Monday, December 30, 2002 12:42 AM
> To: pear-dev
> Subject: RE: [PEAR-DEV] RFC: slight modification to the get*Value()
> methods
>
> > Currently working with NULL values is a bit clumsy imho.
> > If you want a NULL value from getTimestampValue() for example you
will
> > have to set the value passed to the method to 'Null'. Its even worse
> > for getTextValue where this is currently not even handled
internally.
> > You will have to determine if to use getTextValue() or not yourself.
> > This is done because the string 'Null' passed to getTextValue()
could
> > very well mean that you want the string 'Null' inserted into your
DB.
> >
> >
> > Therefore I am proposing the following change:
> > If you pass the PHP constant NULL to any of the get*Value() methods
> > you will get the string 'NULL' returned.
> >
> >
> > Then we don't need the old method used in all but getTextValue() of
> > passing the string 'Null', so I would like to drop it.
>
>
> Could you expand the part regarding getTextValue?
> In particular, what are the differences between the
> following statements:
> ----
> $var = NULL;
> $db->getTextValue($var);
> ----
> $var = 'NULL';
> $db->getTextValue($var);
> ----
>
> To me it's quite obvious that the first one should return a NULL
> constant, while the second one should return the 'NULL' string.
> What the current behaviour is and what the proposed one is?
The current behavior of getTextValue ist hat it cant handle SQL NULL at
all. You have to do that outside of MDB.
> If I use get*Value(null) I'd like to have a NULL constant back, don't
> care what the field datatype is. But if I use getTextValue('null') I'd
> like to have the 'null' string back...
>
> I don't think that having the string 'NULL' back on NULL fields would
> be welcome... I mean, yes, maybe the MDB method is a bit faster, but
> then it's up to the user to check if a 'NULL' string is returned, so
> this only means more work for the user and zero gained time.
> But I really think I didn't understand what you meant :-)
Here goes the list:
1)
// input
$text = NULL;
var_dump($mdb->getTextValue($text));
// old output
string(2) "''"
// new output
string(4) "NULL"
2)
// input
$text = 'NULL';
var_dump($mdb->getTextValue($text));
// old and new output
string(6) "'NULL'"
about 1)
This will result in the field being set to NULL (as in the SQL NULL) in
the DB
About 2)
This will result in the field being set to the string NULL in the DB
(not SQL NULL)
Regards,
Lukas