pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Passing cursor between functions in embedded SQL
2+ messages / 2 participants
[nested] [flat]

* Passing cursor between functions in embedded SQL
@ 2001-06-18 18:34 Alla <alla@sergey.com>
  2001-06-19 13:01 ` Re: Passing cursor between functions in embedded SQL Sergey E. Volkov <sve@raiden.bancorp.ru>
  0 siblings, 1 reply; 2+ messages in thread

From: alla@sergey.com @ 2001-06-18 18:34 UTC (permalink / raw)
  To: pgsql-general@postgresql.org.pgsql-sql

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



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Passing cursor between functions in embedded SQL
  2001-06-18 18:34 Passing cursor between functions in embedded SQL Alla <alla@sergey.com>
@ 2001-06-19 13:01 ` Sergey E. Volkov <sve@raiden.bancorp.ru>
  0 siblings, 0 replies; 2+ messages in thread

From: Sergey E. Volkov @ 2001-06-19 13:01 UTC (permalink / raw)
  To: pgsql-general@postgresql.org.pgsql-sql

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" <alla@sergey.com> ???????/???????? ? ???????? ?????????:
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





^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2001-06-19 13:01 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-06-18 18:34 Passing cursor between functions in embedded SQL Alla <alla@sergey.com>
2001-06-19 13:01 ` Sergey E. Volkov <sve@raiden.bancorp.ru>

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