Re: PHP pg_escape_string

Поиск
Список
Период
Сортировка
От Andy Shellam
Тема Re: PHP pg_escape_string
Дата
Msg-id 4A367281.2020900@networkmail.eu
обсуждение исходный текст
Ответ на PHP pg_escape_string  (Zdravko Balorda <zdravko.balorda@siix.com>)
Список pgsql-sql
Hi,

Zdravko Balorda wrote:
> there are both pg_(un)escape_bytea() functions
> but only one pg_escape_string()... I wonder if I may be
> missing something here?

Yeah, I think you are.  pg_escape_string (funnily enough) escapes string 
data which is then stored in the database.  You would use this for 
escaping things like apostrophes in a text field so PostgreSQL wouldn't 
think the apostrophe in the field is the "end of data" marker.  However 
this string is *not* stored in the database in an escaped form, as it's 
only escaped for the SQL command, therefore it makes no sense to 
unescape it.

bytea columns on the other hand, are a way of sending and receiving 
binary data as a textual representation to/from the database server.  
The data you send and receive is both encoded, therefore you need to 
unescape it to read it back out.  For example a null byte (byte value 0) 
cannot be sent or received in a SQL command, because a null byte 
represents an end-of-string in C.  Other byte values similarly cannot be 
sent in a string because they cannot be converted to a character (e.g. 
ASCII newline/linefeed.)

Regards,
Andy


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

Предыдущее
От: Zdravko Balorda
Дата:
Сообщение: PHP pg_escape_string
Следующее
От: Carol Cheung
Дата:
Сообщение: left outer join on more than 2 tables?