Re: PQunescapeBytea
От | Joe Conway |
---|---|
Тема | Re: PQunescapeBytea |
Дата | |
Msg-id | 402980D9.8070505@joeconway.com обсуждение исходный текст |
Ответ на | PQunescapeBytea (Iker Arizmendi <iker@research.att.com>) |
Список | pgsql-general |
Iker Arizmendi wrote: > Am I using the escape/unescape functions incorrectly? I was > expecting the unescape function to produce an exact > duplicate of a[]. The two functions are not, and should not be, precise reciprocals. PQescapeBytea() prepares a string to be used in an SQL statement, meaning it must produce something in the form "\\ooo" (without the quotes) -- notice *two* backslashes before the octal number. This is needed because the SQL string literal parser eats one backslash, and the byteain() function needs the other to recognize that it is receiving an octal sequence. PQunescapeBytea(), on the other hand, takes a string in the form "\ooo" which is the output format produced by byteaout() function. Notice that only *one* backslash is expected before the octal. In your example, "aaaa\0" is fed into PQescapeBytea(), producing "aaaa\\000". When that is fed into PQunescapeBytea(), the two backslashes are seen as a single backslash that has been escaped. Therefore the two backslashes are transformed into a single unescaped backslash, and the octal number is taken as a literal part of the string, producing "aaaa\000". HTH, Joe
В списке pgsql-general по дате отправления: