pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Do cursors work?
3+ messages / 2 participants
[nested] [flat]

* Do cursors work?
@ 1998-08-04 12:07 George Kousi <g.kousi@albourne.com>
  1998-08-04 12:22 ` Re: [INTERFACES] Do cursors work? Tom Good <tomg@nrnet.org>
  0 siblings, 1 reply; 3+ messages in thread

From: George Kousi @ 1998-08-04 12:07 UTC (permalink / raw)
  To: pgsql-interfaces

    Hi,

I'm a new user and new in the mailing list.  Has anyone been using the
cursors with ecpg successfuly?  Whenever I try to open a cursor, my
system hangs completely.  Is there a version later than ecpg 1.1.0?

Thank you,

George




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

* Re: [INTERFACES] Do cursors work?
  1998-08-04 12:07 Do cursors work? George Kousi <g.kousi@albourne.com>
@ 1998-08-04 12:22 ` Tom Good <tomg@nrnet.org>
  1998-08-04 12:27   ` Re: [INTERFACES] Do cursors work? Tom Good <tomg@nrnet.org>
  0 siblings, 1 reply; 3+ messages in thread

From: Tom Good @ 1998-08-04 12:22 UTC (permalink / raw)
  To: George Kousi <g.kousi@albourne.com>; +Cc: pgsql-interfaces

On Tue, 4 Aug 1998, George Kousi wrote:

> I'm a new user and new in the mailing list.  Has anyone been using the
> cursors with ecpg successfuly?  Whenever I try to open a cursor, my
> system hangs completely.  Is there a version later than ecpg 1.1.0?

Hi George,

Yes there is...look on the web site.  But you may want to check
your syntax.  I use ecpg 1.1 on some boxes - with good effect.

Here is some code:


#include <stdio.h>
#include <string.h>

EXEC SQL BEGIN DECLARE SECTION;
  int c_id;
  char c_fname[100]; 
  char c_lname[100]; 
  int ClientID;         /* client_id */  
  char FirstName[16];   /* client_fname */
  char LastName[16];    /* client_lname */
EXEC SQL END DECLARE SECTION;

EXEC SQL INCLUDE sqlca;

main() {
EXEC SQL CONNECT 'registry';
  if(sqlca.sqlcode) {
    printf("Error connecting to database server.\n");
    exit(0);
  }
system("tput clear");
printf("\n"); 

EXEC SQL DECLARE cur_sor CURSOR FOR
  SELECT client_lname, client_fname, client_id
  FROM central 
  ORDER BY client_lname;
EXEC SQL OPEN cur_sor;

EXEC SQL FETCH cur_sor INTO :c_lname, :c_fname, :c_id;
    printf("\t\t   Lastname       Firstname           ID\n");
    printf("\t\t   -------------------------------------\n");
  while(!sqlca.sqlcode) {
    printf("\t\t   %s %s %d \n", c_lname, c_fname, c_id);
EXEC SQL FETCH cur_sor INTO :c_lname, :c_fname, :c_id;

EXEC SQL CLOSE cur_sor;
EXEC SQL COMMIT RELEASE;

  exit(0);
}

 Cheers,
 Tom

    ----------- Sisters of Charity Medical Center ----------
                    Department of Psychiatry
                              ----     
 Thomas Good, System Administrator            <tomg@q8.nrnet.org>
 North Richmond CMHC/Residential Services     Phone: 718-354-5528
 75 Vanderbilt Ave, Quarters 8                Fax:   718-354-5056
 Staten Island, NY   10304                    www.panix.com/~ugd
                              ----     
 Powered by PostgreSQL 6.3.2 / Perl 5.004 / DBI-0.91::DBD-PG-0.69 




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

* Re: [INTERFACES] Do cursors work?
  1998-08-04 12:07 Do cursors work? George Kousi <g.kousi@albourne.com>
  1998-08-04 12:22 ` Re: [INTERFACES] Do cursors work? Tom Good <tomg@nrnet.org>
@ 1998-08-04 12:27   ` Tom Good <tomg@nrnet.org>
  0 siblings, 0 replies; 3+ messages in thread

From: Tom Good @ 1998-08-04 12:27 UTC (permalink / raw)
  To: pgsql-interfaces

George - here is a better example!  That last bit was ripped out
of a longer file and didn't compile - this does!

#include <stdio.h>

EXEC SQL BEGIN DECLARE SECTION;
  int c_id;
  char c_fname[100]; 
  char c_lname[100]; 
EXEC SQL END DECLARE SECTION;

EXEC SQL INCLUDE sqlca;

main() {
EXEC SQL CONNECT 'registry';
  if(sqlca.sqlcode) {
    printf("Error connecting to database server.\n");
    exit(0);
  }
  printf("Connected to database server.\n");

EXEC SQL DECLARE cur_sor CURSOR FOR
  SELECT client_lname, client_fname, client_id
  FROM central 
  ORDER BY client_lname;
EXEC SQL OPEN cur_sor;

EXEC SQL FETCH cur_sor INTO :c_lname, :c_fname, :c_id;
  while(!sqlca.sqlcode) {

    printf("%20s %20s %5d \n", c_fname, c_lname, c_id);

EXEC SQL FETCH cur_sor INTO :c_lname, :c_fname, :c_id;
  }

EXEC SQL CLOSE cur_sor;
EXEC SQL COMMIT RELEASE;
  exit(0);
}


 Sorry about that!
 Tom

    ----------- Sisters of Charity Medical Center ----------
                    Department of Psychiatry
                              ----     
 Thomas Good, System Administrator            <tomg@q8.nrnet.org>
 North Richmond CMHC/Residential Services     Phone: 718-354-5528
 75 Vanderbilt Ave, Quarters 8                Fax:   718-354-5056
 Staten Island, NY   10304                    www.panix.com/~ugd
                              ----     
 Powered by PostgreSQL 6.3.2 / Perl 5.004 / DBI-0.91::DBD-PG-0.69 




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


end of thread, other threads:[~1998-08-04 12:27 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1998-08-04 12:07 Do cursors work? George Kousi <g.kousi@albourne.com>
1998-08-04 12:22 ` Tom Good <tomg@nrnet.org>
1998-08-04 12:27   ` Tom Good <tomg@nrnet.org>

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