From: Matthias Apitz <guru@unixarea.de>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: Problem close curser after rollback
Date: Thu, 1 Oct 2020 08:36:55 +0200
Message-ID: <20201001063655.GB1813@r314251-amd64> (raw)
In-Reply-To: <891496.1601491043@sss.pgh.pa.us>
References: <DS7PR06MB6885FE41D39C4A2779CF13A7FF330@DS7PR06MB6885.namprd06.prod.outlook.com>
<DM6PR06MB6169D90391183C6AA56376C4EA330@DM6PR06MB6169.namprd06.prod.outlook.com>
<DS7PR06MB68850E9EB5C735140A5CC5D3FF330@DS7PR06MB6885.namprd06.prod.outlook.com>
<f2af04c4fc6af1791c52b8bd2937522832b4df8c.camel@cybertec.at>
<20200930171312.GA14156@r314251-amd64>
<891496.1601491043@sss.pgh.pa.us>
El día miércoles, septiembre 30, 2020 a las 02:37:23p. m. -0400, Tom Lane escribió:
> Matthias Apitz <guru@unixarea.de> writes:
> > El día miércoles, septiembre 30, 2020 a las 05:26:39p. m. +0200, Laurenz Albe escribió:
> >> On Wed, 2020-09-30 at 13:32 +0000, Wiltsch,Sigrid wrote:
> >>> What can I do so that the cursor is retained despite rollback?
>
> >> You cannot start a transaction while you are reading a cursor; you probably
> >> get a warning "there is already a transaction in progress".
>
> > I think we will prepare the ten-liner in ESQL/C for further discussion.
>
> I don't think you really need to: the point seems clear enough.
I did wrote the ten-liner to play around with. Interestingly, there exists an
undocumented ESQL/C statement 'EXEC SQL START TRANSACTION' which gives
in the esqlc log:
ECPGtrans on line 48: action "start transaction"; connection "sisis"
What as well does work is the following sequence:
EXEC SQL PREPARE stmt1 FROM "SELECT tstchar25, tstint FROM dbctest WHERE tstint > ?";
EXEC SQL DECLARE foo_bar CURSOR WITH HOLD FOR stmt1 ;
/* when end of result set reached, break out of while loop */
EXEC SQL WHENEVER NOT FOUND DO BREAK;
EXEC SQL OPEN foo_bar USING 1;
while (1)
{
EXEC SQL FETCH NEXT FROM foo_bar INTO :tstchar25, :tstint;
EXEC SQL COMMIT ;
EXEC SQL START TRANSACTION ;
printf("fetched: [%s] [%d] \n", tstchar25, tstint);
// ... do something with the fetched data and because
// it went wrong, we issue a ROLLBACK
EXEC SQL ROLLBACK ;
}
This fetches nicely through the table in the while-loop; without the
additional COMMIT, the START TRANSACTION gives
ECPGtrans on line 48: action "start transaction"; connection "sisis"
ECPGnoticeReceiver: there is already a transaction in progress
We will think now about what we have learned and how to repair our
application.
matthias
--
Matthias Apitz, ✉ guru@unixarea.de, http://www.unixarea.de/ +49-176-38902045
Public GnuPG key: http://www.unixarea.de/key.pub
Без книги нет знания, без знания нет коммунизма (Влaдимир Ильич Ленин)
Without books no knowledge - without knowledge no communism (Vladimir Ilyich Lenin)
Sin libros no hay saber - sin saber no hay comunismo. (Vladimir Ilich Lenin)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: guru@unixarea.de, tgl@sss.pgh.pa.us
Subject: Re: Problem close curser after rollback
In-Reply-To: <20201001063655.GB1813@r314251-amd64>
References: <DS7PR06MB6885FE41D39C4A2779CF13A7FF330@DS7PR06MB6885.namprd06.prod.outlook.com> <DM6PR06MB6169D90391183C6AA56376C4EA330@DM6PR06MB6169.namprd06.prod.outlook.com> <DS7PR06MB68850E9EB5C735140A5CC5D3FF330@DS7PR06MB6885.namprd06.prod.outlook.com> <f2af04c4fc6af1791c52b8bd2937522832b4df8c.camel@cybertec.at> <20200930171312.GA14156@r314251-amd64> <891496.1601491043@sss.pgh.pa.us> <20201001063655.GB1813@r314251-amd64>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox