Re: Improvements in psql hooks for variables

Поиск
Список
Период
Сортировка
От Daniel Verite
Тема Re: Improvements in psql hooks for variables
Дата
Msg-id 14360f32-7d7e-4452-8fd5-e726477272b1@mm
обсуждение исходный текст
Ответ на Re: Improvements in psql hooks for variables  (Stephen Frost <sfrost@snowman.net>)
Ответы Re: Improvements in psql hooks for variables
Список pgsql-hackers
    Stephen Frost wrote:

> Just fyi, there seems to be some issues with this patch because setting
> my PROMPT1 and PROMPT2 variables result in rather odd behavior.

Good catch! The issue is that the patch broke the assumption
of prompt hooks that their argument points to a long-lived buffer.
The attached v4 fixes the bug by passing to hooks a pointer to the final
strdup'ed value in VariableSpace rather than temp space, as commented
in SetVariable().

Also I've changed something else in ParseVariableBool(). The code assumes
"false" when value==NULL, but when value is an empty string, the result
was true and considered valid, due to the following test being
positive when len==0 (both with HEAD or the v3 patch from this thread):

    if (pg_strncasecmp(value, "true", len) == 0)
        return true;
It happens that "" as a value yields the same result than "true" for this
test so it passes, but it seems rather unintentional.

The resulting problem from the POV of the user is that we can do that,
for instance:

   test=> \set AUTOCOMMIT

without error message or feedback, and that leaves us without much
clue about autocommit being enabled:

   test=> \echo :AUTOCOMMIT

   test=>

So I've changed ParseVariableBool() in v4 to reject empty string as an
invalid boolean (but not NULL since the startup logic requires NULL
meaning false in the early initialization of these variables).

"make check" seems OK with that, I hope it doesn't cause any regression
elsewhere.


Best regards,
--
Daniel Vérité
PostgreSQL-powered mailer: http://www.manitou-mail.org
Twitter: @DanielVerite

Вложения

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

Предыдущее
От: Stephen Frost
Дата:
Сообщение: Re: Improvements in psql hooks for variables
Следующее
От: "Daniel Verite"
Дата:
Сообщение: Re: Improvements in psql hooks for variables