| From: | Tom Good <tomg(at)nrnet(dot)org> | 
|---|---|
| To: | PostgreSQL Interfaces List <pgsql-interfaces(at)postgreSQL(dot)org> | 
| Subject: | Re: [INTERFACES] Do cursors work? | 
| Date: | 1998-08-04 12:27:42 | 
| Message-ID: | Pine.LNX.3.95.980804082701.23123A-100000@mailhost.nrnet.org | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | 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(at)q8(dot)nrnet(dot)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 
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Mariano Herrero | 1998-08-04 14:00:56 | About connecting to a database | 
| Previous Message | Tom Good | 1998-08-04 12:22:30 | Re: [INTERFACES] Do cursors work? |