Re: [HACKERS] Modifing returning value of PQgetvalue.

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: [HACKERS] Modifing returning value of PQgetvalue.
Дата
Msg-id 9122.1498546482@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: [HACKERS] Modifing returning value of PQgetvalue.  (Peter Eisentraut <peter.eisentraut@2ndquadrant.com>)
Список pgsql-hackers
Peter Eisentraut <peter.eisentraut@2ndquadrant.com> writes:
> On 6/24/17 06:31, Dmitry Igrishin wrote:
>> PQgetvalue returns a value of type char* (without const). But the
>> documentation says:
>> "The pointer returned by PQgetvalue points to storage that is part of
>> the PGresult structure. /One should not modify the data it points to/"
>> (my italics). Could someone tell me please, what wrong with modifing
>> arbitrary character of the data pointed by PQgetvalue's returning value?
>> Or why this restriction is documented? Thanks.

> This is just how the API is defined.  It could be defined differently,
> but it is not.

To enlarge on that: it might well work today.  But if we change the
code in future so that it does not work, we will make no apologies.

There's at least one case where you could have a problem today.
All null entries in a PGresult share the same pointer to an empty
string, so that if you were to modify that string, it would affect
what's seen for other "null" values.  If the API allowed modification
of data values, that would be a bug.  But it doesn't, and so it isn't,
and we wouldn't look kindly on complaints about it.

Ideally, PQgetvalue should be redefined to return "const char *".
I don't really see us doing that anytime soon though.  It would
result in a lot of compile warnings for perfectly-safe client code.
I'm sure this API would look different if it weren't older than
universal availability of "const" :-(
        regards, tom lane



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

Предыдущее
От: sanyam jain
Дата:
Сообщение: Re: [HACKERS] pgjdbc logical replication client throwing exception
Следующее
От: Pavel Stehule
Дата:
Сообщение: Re: [HACKERS] psql - add special variable to reflect the last query status