Re: problem with serial

Поиск
Список
Период
Сортировка
Искать
От
Chris Angelico
Тема
Re: problem with serial
Дата
Msg-id
CAPTjJmox=YPuT5vCo_WNaXFo7PxKVQrQ2LMBG30US4iSOf_6fw@mail.gmail.com
Ответ на
Re: problem with serial (Yvon Thoraval)
Список
Дерево обсуждения
problem with serial Yvon Thoraval <yvon.thoraval@gmail.com>
Re: problem with serial Adrian Klaver <adrian.klaver@gmail.com>
Re: problem with serial Alban Hertroys <haramrae@gmail.com>
Re: problem with serial Chris Angelico <rosuav@gmail.com>
Re: problem with serial Yvon Thoraval <yvon.thoraval@gmail.com>
Re: problem with serial Chris Angelico <rosuav@gmail.com>
Re: problem with serial Yvon Thoraval <yvon.thoraval@gmail.com>
On Fri, Apr 20, 2012 at 2:03 AM, Yvon Thoraval  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
a fruitless exercise, because now you are relying for safety and
security on something that the database engine promises is correct :)

Chris Angelico
В списке pgsql-general по дате отправления
От: Yvon Thoraval
Дата:
Сообщение: Re: problem with serial
От: Jen
Дата:
FAQ