ECPG regression with DECLARE STATEMENT support

From: Rushabh Lathia <rushabh(dot)lathia(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: ECPG regression with DECLARE STATEMENT support
Date: 2019-03-06 07:13:17
Message-ID: CAGPqQf1rVc=RoNJFF5K1M7yBJV7aai3G5zr39U_SjDQ=5Kv0Ww@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

Commit bd7c95f0c1a38becffceb3ea7234d57167f6d4bf add DECLARE
STATEMENT support to ECPG. This introduced the new rule
for EXEC SQL CLOSE cur and with that it gets transformed into
ECPGclose().

Now prior to the above commit, someone can declare the
cursor in the SQL statement and "CLOSE cur_name" can be
also, execute as a normal statement.

Example:

EXEC SQL PREPARE cur_query FROM "DECLARE cur1 CURSOR WITH HOLD FOR SELECT
count(*) FROM pg_class";
EXEC SQL PREPARE fetch_stmt FROM "FETCH next FROM cur1";
EXEC SQL EXECUTE cur_query;
EXEC SQL EXECUTE fetch_stmt INTO :c;
EXEC SQL CLOSE cur1;

With commit bd7c95f0c1, "EXEC SQL CLOSE cur1" will fail
and throw an error "sqlcode -245 The cursor is invalid".

I think the problem here is ECPGclose(), tries to find the
cursor into "connection->cursor_stmts" and if it doesn't
find it there, just throws an error. Maybe require fix
into ECPGclose() - rather than throwing an error continue
executing statement "CLOSE cur_name" with ecpg_do().

Attaching the ECPG program for reference.

Thanks,

--
Rushabh Lathia
www.EnterpriseDB.com

Attachment Content-Type Size
test.pgc application/octet-stream 561 bytes

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2019-03-06 07:19:00 Re: pg_dump is broken for partition tablespaces
Previous Message Andres Freund 2019-03-06 07:07:21 Re: Pluggable Storage - Andres's take