Received: from postgresql.org.org (webmail.postgresql.org [216.126.85.28]) by postgresql.org (8.11.3/8.11.1) with SMTP id f5KGdoa90820 for ; Wed, 20 Jun 2001 12:39:50 -0400 (EDT) (envelope-from pgsql-sql-owner@postgresql.org) Received: from news.tht.net (news.hub.org [216.126.91.242]) by postgresql.org (8.11.3/8.11.1) with ESMTP id f5JDVea78274; Tue, 19 Jun 2001 09:31:40 -0400 (EDT) (envelope-from news@news.tht.net) Received: (from news@localhost) by news.tht.net (8.11.4/8.11.4) id f5JD4DE82218; Tue, 19 Jun 2001 09:04:13 -0400 (EDT) (envelope-from news) From: "Sergey E. Volkov" X-Newsgroups: comp.databases.postgresql.general,comp.databases.postgresql.sql Subject: Re: Passing cursor between functions in embedded SQL Date: Tue, 19 Jun 2001 17:01:40 +0400 Organization: Hub.Org Networking Services (http://www.hub.org) Lines: 77 Message-ID: <9gnik9$2g97$1@news.tht.net> References: <9275d56e.0106181034.51a22104@posting.google.com> X-Complaints-To: scrappy@hub.org X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4522.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200 To: pgsql-general@postgresql.org.pgsql-sql@postgresql.org X-Archive-Number: 200106/312 X-Sequence-Number: 3585 Hi Alla, Short answer - you can't. Cursor ( cursors' name ) in esql ALWAYS has a FILE scope ( correct me - global scope in ecpg ) so you can to use it anywhere ( in the file where it was defined ) without passing ones as parameter. However if you want to pass cursor as parameter I recommend you to use postgresql's c++ library or c library. It's best way to make a flexible application. ( For example in Informix's esqlc I can to define cursor as follows: *** exec sql begin declare section char *c1 = "my_first_cursor", *c2 = "my_second_corsor"; exec sql end declare section exec sql declare :c1 cursor for ...; exec sql declare :c2 cursor for ...; status = process_result_set(c1); status = process_result_set(c2); *** ecpg however doesn't support this syntax ... ) "Alla" ???????/???????? ? ???????? ?????????: news:9275d56e.0106181034.51a22104@posting.google.com... > Did anybody try to do something like this? > > int > open_cursor(...) > { > EXEC SQL DECLARE cur CURSOR FOR ... > > EXEC SQL OPEN cur; > > return cur1; /* how can I do that???? */ > } > > int > fetch_cursor(... cur) > { > EXEC SQL FETCH cur; > > return some data; > } > > That's how it's going to look in the calling program: > > cur := open_cursor; > > while (not found) > { > fetch_cursor(cur); > do some processing with the data > } > > > My point is I don't want to declare huge arrays or linked lists and > keep all the fetched data in the memory. I want to fetch a row, > process it and move on to the next one. > > May be there is another approach to do this? Please help > > Thanks > > Alla Gribov