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

From: Boszormenyi Zoltan <zb(at)cybertec(dot)at>
To: PG Hackers <pgsql-hackers(at)postgresql(dot)org>, Michael Meskes <meskes(at)postgresql(dot)org>
Subject: ECPG dynamic cursor fix for UPDATE/DELETE ... WHERE CURRENT OF :curname
Date: 2010-08-03 17:01:48
Message-ID: 4C584B7C.5060804@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Attachment Content-Type Size
ecpg-where-current-of-4.patch text/x-patch 18.5 KB
ecpg-fix-leaks.patch text/x-patch 34.8 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Kevin Grittner 2010-08-03 17:11:27 Re: ECPG dynamic cursor fix for UPDATE/DELETE ... WHERE CURRENT OF :curname
Previous Message Brendan Jurd 2010-08-03 16:58:35 Re: reducing NUMERIC size for 9.1, take two