ECPG dynamic cursor fix for UPDATE/DELETE ... WHERE CURRENT OF :curname

Поиск
Список
Период
Сортировка
От Boszormenyi Zoltan
Тема ECPG dynamic cursor fix for UPDATE/DELETE ... WHERE CURRENT OF :curname
Дата
Msg-id 4C584B7C.5060804@cybertec.at
обсуждение исходный текст
Ответы Re: ECPG dynamic cursor fix for UPDATE/DELETE ... WHERE CURRENT OF :curname  ("Kevin Grittner" <Kevin.Grittner@wicourts.gov>)
Re: ECPG dynamic cursor fix for UPDATE/DELETE ... WHERE CURRENT OF :curname  (Michael Meskes <meskes@postgresql.org>)
Список pgsql-hackers
Hi,

attached is a patch that adds the missing feature to use
"WHERE CURRENT OF :curname" in UPDATE and
DELETE statements via ECPG. I used the current CVS MAIN
but also applies almost cleanly to 9.0beta4. I certainly feel that
this should be applied to 9.0 as a bugfix.

The execute.c changes were required because

1. The statement

    UPDATE table SET fld1 = :input1
    WHERE CURRENT OF :curname
    RETURNING id + :input2;

    is transformed into

    UPDATE table SET fld1 = $1
    WHERE CURRENT OF $0
    RETURNING id + $2;

    and the $0 is past $1. The current code cannot deal with such
    a messed up order, and scanning the original query twice is
    needed, once for $0 substitution, once for mapping $1, etc. to
    the other input variables.

2. With such a statement and auto-prepare turned on, I always got

    SQL error: there is no parameter $0 on line X

    It turned out that the statement was prepared by the auto-prepare
machinery
    before the $0 substitution. PostgreSQL allows
        PREPARE mystmt AS UPDATE ... WHERE CURRENT OF mycur
    even if "mycur" is currently unknown to the system. It's resolved upon
    executing the prepared query, so we should allow it in ECPG even with
    dynamic cursorname.

The code survives "make check" and I also went through all the regression
tests manually to check them with valgrind to see that there's no leak.
As a result, another patch is attached that fixes two memory leaks in
PGTYPESnumeric_from_asc() and PGTYPESnumeric_to_long() and
quite some leaks in the regression tests themselves.

Best regards,
Zoltán Böszörményi


Вложения

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

Предыдущее
От: Brendan Jurd
Дата:
Сообщение: Re: reducing NUMERIC size for 9.1, take two
Следующее
От: "Kevin Grittner"
Дата:
Сообщение: Re: ECPG dynamic cursor fix for UPDATE/DELETE ... WHERE CURRENT OF :curname