Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kNsDD-000870-DL for pgsql-general@arkaria.postgresql.org; Thu, 01 Oct 2020 06:37:07 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kNsDC-0005s4-C4 for pgsql-general@arkaria.postgresql.org; Thu, 01 Oct 2020 06:37:06 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kNsDC-0005rx-4o for pgsql-general@lists.postgresql.org; Thu, 01 Oct 2020 06:37:06 +0000 Received: from ms-10.1blu.de ([178.254.4.101]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kNsD9-0002SJ-6O for pgsql-general@lists.postgresql.org; Thu, 01 Oct 2020 06:37:04 +0000 Received: from [178.254.11.41] (helo=r314251-amd64) by ms-10.1blu.de with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kNsD3-0001Ii-GN; Thu, 01 Oct 2020 08:36:57 +0200 Date: Thu, 1 Oct 2020 08:36:55 +0200 From: Matthias Apitz To: Tom Lane Cc: pgsql-general@lists.postgresql.org Subject: Re: Problem close curser after rollback Message-ID: <20201001063655.GB1813@r314251-amd64> Reply-To: Matthias Apitz References: <20200930171312.GA14156@r314251-amd64> <891496.1601491043@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <891496.1601491043@sss.pgh.pa.us> X-Operating-System: FreeBSD 8.0-CURRENT (i386) User-Agent: Mutt/1.8.0 (2017-02-23) X-Con-Id: 51246 X-Con-U: 0-guru X-Originating-IP: 178.254.11.41 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk El día miércoles, septiembre 30, 2020 a las 02:37:23p. m. -0400, Tom Lane escribió: > Matthias Apitz 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)