RE: [PEAR-DEV] RFC: slight modification to the get*Value() methods
| From: | Lukas Smith | Date: | Mon, 30 Dec 2002 13:08:11 +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-11957@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 1:44 PM
> To: pear-dev
> Subject: RE: [PEAR-DEV] RFC: slight modification to the get*Value()
> methods
>
> > The current behavior of getTextValue ist hat it cant handle SQL NULL
> > at all. You have to do that outside of MDB.
>
> I see.
>
> > 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)
>
>
> Well, I think I like more #1, for it stores a SQL NULL value in the
DB,
> but I think that having a NULL const back (not a string) would be
> the best option. Don't know if this is difficult to implement, though
> (I didn't checked the source about this). As a matter of fact, if a
NULL
> const is not feasible, I'd prefer an empty string instead of the
'NULL'
> string if in the db there's a SQL NULL value...
> Just my 0.02$
But getting back a constant will not get you anywhere.
The point of getTextValue() is to get get the correct format to put into
a text field. If getTextValue() returns the NULL constant you will
surely get an error. As the SQL database will then get nothing at all:
$null = NULL;
$query = 'SELECT * from foo WHERE bar = '.$mdb->getTextValue($null);
1) if it were to return the php constant NULL $query would be this:
"SELECT * from foo WHERE bar = "
which will pretty much always give you an error
2) if it where to return the string 'NULL' $query would be this:
"SELECT * from foo WHERE bar = NULL"
If I pass a string then the bavior will not change at all:
$null = 'NULL';
$query = 'SELECT * from foo WHERE bar = '.$mdb->getTextValue($null);
3) will result in $query being this:
"SELECT * from foo WHERE bar = 'NULL'"
the point of get*Value() method is not to ensure that you pass the
correct data to it, but to convert the given data into something that
the chosen SQL DB will handle correctly.
regards,
Lukas