Re: PQexec(), what should I do for the "NULL in command" problem?

Поиск
Список
Период
Сортировка
От Martijn van Oosterhout
Тема Re: PQexec(), what should I do for the "NULL in command" problem?
Дата
Msg-id 20071113072154.GA6945@svana.org
обсуждение исходный текст
Ответ на Re: PQexec(), what should I do for the "NULL in command" problem?  ("yang zhenyu" <zhyuyang@gmail.com>)
Ответы Re: PQexec(), what should I do for the "NULL in command" problem?
Список pgsql-general
On Tue, Nov 13, 2007 at 10:52:09AM +0800, yang zhenyu wrote:
> > > But there exist "\0" in some data filed, and I found PQexec() failed
> > > on such situation.
>
> Thanks for reply :-)
> But would you please give me more details or some references?
>
> > Two ways:
> > - out of line parameters
> How to? Is there any function for this? I mean the C interface.

PQexecParams.

> > - escape the nulls, like \0
> Do you mean this function?
> #unsigned char *PQescapeBytea(const unsigned char *from,
> #                 size_t from_length,
> #                 size_t *to_length);
>
> But after the "escape", the data is changed, and it cannot
> automatically change back when insert them into database.
> I have to "unescape" it when query. Is this necessary?

True. You should realise that the text data type does not handle
embedded nulls, that's why the bytea datatype exists. If you don't want
the full conversion, you'll need to handle your own escaping.
PostgreSQL is not going return you strings with embedded NULLs...

Have a nice day,
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> Those who make peaceful revolution impossible will make violent revolution inevitable.
>  -- John F Kennedy

Вложения

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

Предыдущее
От: Ow Mun Heng
Дата:
Сообщение: Re: Calculation for Max_FSM_pages : Any rules of thumb?
Следующее
От: "yang zhenyu"
Дата:
Сообщение: Re: PQexec(), what should I do for the "NULL in command" problem?