Re: Quote String

From: Date: Thu, 05 Jul 2001 21:16:08 +0000
Subject: Re: Quote String
References: 1 2 3  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-558@lists.php.net to get a copy of this message
At 8:02 PM +0200 7/3/01, Tomas V.V.Cox wrote:
Paul DuBois wrote:
At 11:19 AM +0200 7/3/01, Tomas V.V.Cox wrote:
Sorry for not to follow the thread but I recently have suscribed to the list. Please test this patch to the pear/DB/mysql.php, so if works I'll commit the change to the quote string behavoir. The same for the sybase extension. For the question about null values I don't see any way for inserting them, but the needed change in executeEmulateQuery() for supporting it is trivial. What do you think to add the unquoted NULL string when the null (constant) value is given?
Personally, I think that's the corrrect behavior. But on the other hand, it wouldn't be so difficult to make quoteString() do that to, such that: quoteString("a") => "'a'" quoteString (null) => "NULL"
Yeah, great idea, but it will require a little more work. Hope to have some time in the next days to start with it, if noone have anything more to say.
I guess the question isn't as simple as I thought. Initially, I thought this might do it:
    // {{{ quoteString()
    function quoteString($string)
    {
        return ($string == null ? "NULL" : mysql_escape_string($string)) ;
    }
However, the problem is that quoteString() doesn't add quotes around non-NULL values. So it doesn't really act like DBI's quote() at all. Having quoteString() act like I initially suggested would involve a change to PEAR that's probably too incompatible with existing behavior, so I guess it shouldn't try to handle NULL at all. (All other quoteString() versions would have to change, and executeEmulateQuery() in common.php would need to change the way it uses quoteString().) The MySQL quoteString() should still use mysql_escape_string(), though.
That's how the quote() method in DBI works. (Am I allowed to say that here? :-)
Sure Pear DB has taken many ideas from DBI. But remember what people say about perl: "Perl is the only language that looks the same before and after a RC5 encryption" ;) Tomas V.V.Cox
-- Paul DuBois, paul@snake.net

« previous php.pear.dev (#558) next »