standard_conforming_strings and pg_escape_string()

Поиск
Список
Период
Сортировка
От Conrad Lender
Тема standard_conforming_strings and pg_escape_string()
Дата
Msg-id 49F0C277.6020805@gmail.com
обсуждение исходный текст
Ответы Re: standard_conforming_strings and pg_escape_string()  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: standard_conforming_strings and pg_escape_string()  ("Joshua D. Drake" <jd@commandprompt.com>)
Re: standard_conforming_strings and pg_escape_string()  ("Daniel Verite" <daniel@manitou-mail.org>)
Список pgsql-general
Hi.

I'm using PostgreSQL 8.3 with PHP's "pgsql" module (libpq 8.3.7). When
the server's standard_conforming_strings setting is off (this is
currently still the default, I believe), I use something like this to
escape strings:

  if ($escWildcards) {
    $str = strtr($str, array("%" => '\%', "_" => '\_'));
  }
  return "E'" . pg_escape_string($str) . "'";

I would like our database abstraction to be able to handle both settings
for standard_conforming_strings transparently, i.e. perform the escaping
according to the current DB server settings. Since pg_escape_string() is
aware of the current database connection, I had expected its behavior to
change accordingly:

no std strings:
   x\y --> x\\y
with std strings:
   x\y --> x\y

Unfortunately, this doesn't happen. Isn't pg_escape_string() the
preferred way to escape strings for PostgreSQL in PHP?

And finally, would it be safe to always use the E'\\' syntax, regardless
of how standard_conforming_strings is set on the server?


  - Conrad


В списке pgsql-general по дате отправления:

Предыдущее
От: Merlin Moncure
Дата:
Сообщение: Re: Dynamic SQL in Function
Следующее
От: Ben Welsh
Дата:
Сообщение: OperationalError: FATAL: could not open file : Too many open files in system