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 1mGOFY-0007Bz-V8 for pgsql-docs@arkaria.postgresql.org; Wed, 18 Aug 2021 16:17:08 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mGOFX-0007cx-Iy for pgsql-docs@arkaria.postgresql.org; Wed, 18 Aug 2021 16:17:07 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mGOFX-0007cp-Cw for pgsql-docs@lists.postgresql.org; Wed, 18 Aug 2021 16:17:07 +0000 Received: from momjian.us ([72.94.173.45]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mGOFU-00088H-Qd for pgsql-docs@lists.postgresql.org; Wed, 18 Aug 2021 16:17:07 +0000 Received: from bruce by momjian.us with local (Exim 4.92) (envelope-from ) id 1mGOFT-0008Jb-I0; Wed, 18 Aug 2021 12:17:03 -0400 Date: Wed, 18 Aug 2021 12:17:03 -0400 From: Bruce Momjian To: andrew@andrewculver.com, pgsql-docs@lists.postgresql.org Subject: Re: ECPG cursor examples should include EXEC SQL WHENEVER NOT FOUND CONTINUE; after the while loop Message-ID: <20210818161703.GC13002@momjian.us> References: <162531325118.701.13401788614496956581@wrigleys.postgresql.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <162531325118.701.13401788614496956581@wrigleys.postgresql.org> User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Sat, Jul 3, 2021 at 11:54:11AM +0000, PG Doc comments form wrote: > The following documentation comment has been logged on the website: > > Page: https://www.postgresql.org/docs/13/ecpg-variables.html > Description: > > Without this line: > EXEC SQL WHENEVER NOT FOUND CONTINUE; > after the while(1), I find that ECPG CURSOR examples fail. > > For example, this example under 36.4.4.3.2. Structures fails: Uh, can you give me full C example to test? I already see EXEC SQL WHENEVER NOT FOUND DO BREAK in the sample code, so I don't see how CONTINUE would actually work, since it would just loop over the result infinitely. --------------------------------------------------------------------------- > > EXEC SQL BEGIN DECLARE SECTION; > typedef struct > { > int oid; > char datname[65]; > long long int size; > } dbinfo_t; > > dbinfo_t dbval; > EXEC SQL END DECLARE SECTION; > > memset(&dbval, 0, sizeof(dbinfo_t)); > > EXEC SQL DECLARE cur1 CURSOR FOR SELECT oid, datname, > pg_database_size(oid) AS size FROM pg_database; > EXEC SQL OPEN cur1; > > /* when end of result set reached, break out of while loop */ > EXEC SQL WHENEVER NOT FOUND DO BREAK; > > while (1) > { > /* Fetch multiple columns into one structure. */ > EXEC SQL FETCH FROM cur1 INTO :dbval; > > /* Print members of the structure. */ > printf("oid=%d, datname=%s, size=%lld\n", dbval.oid, dbval.datname, > dbval.size); > } > > EXEC SQL CLOSE cur1; -- Bruce Momjian https://momjian.us EDB https://enterprisedb.com If only the physical world exists, free will is an illusion.