Re: problem with serial

From: Raymond O'Donnell <rod(at)iol(dot)ie>
To: Chris Angelico <rosuav(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: problem with serial
Date: 2012-04-19 19:07:40
Message-ID: 4F90627C.5010908@iol.ie
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 19/04/2012 17:12, Chris Angelico wrote:
> On Fri, Apr 20, 2012 at 2:03 AM, Yvon Thoraval <yvon(dot)thoraval(at)gmail(dot)com> wrote:
>> function quoteAsAre($string){
>> return preg_replace('/\\\"/', '"', preg_replace("/\\\'/", "'",
>> $string));
>> }
>> function sql2str($string){
>> return preg_replace('/\'\'/', "'", $string);
>> }
>> function str2sql($string){
>> return preg_replace('/\'/', "''", $string);
>> }
>>
>> OK, i'll carrefully inspect all of those.
>
> No; ditch them. I mean no offense to you personally, but these
> functions are not worth keeping. Every SQL API includes a function for
> quoting something as a literal string. With PDO, it's this one:
>
> http://www.php.net/manual/en/pdo.quote.php
>
> I don't know where you would be using sql2str, but it's just as
> dangerous as the others (not to mention inefficient, there's no need
> to use regular expressions for simple string replacement). Replace all
> your calls to any of these functions with standard quoting functions
> and see if your problem disappears. If not, well, it's still not been

Or better still - and easier - use parametrised queries.

Ray.

--
Raymond O'Donnell :: Galway :: Ireland
rod(at)iol(dot)ie

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Yvon Thoraval 2012-04-19 19:30:46 Re: problem with serial
Previous Message Yvon Thoraval 2012-04-19 18:21:08 Re: problem with serial