home *** CD-ROM | disk | FTP | other *** search
- PROGRAM cursor
- INCLUDE 'SQLENV.FOR'
- EXEC SQL INCLUDE SQLCA
- EXEC SQL BEGIN DECLARE SECTION
- CHARACTER*10 pname
- INTEGER*2 dept
- EXEC SQL END DECLARE SECTION
- INTEGER*2 RC
-
- WRITE(*,*) 'Sample FORTRAN program: CURSOR'
-
- EXEC SQL CONNECT TO sample IN SHARE MODE
-
- IF ( SQLCODE .NE. 0 ) THEN
- WRITE(*,*) 'Start DB Error: SQLCODE = ', SQLCODE
- STOP
- ENDIF
-
- EXEC SQL WHENEVER SQLERROR GO TO 300
- EXEC SQL WHENEVER NOT FOUND GO TO 200
-
- EXEC SQL DECLARE c1 CURSOR FOR
- C SELECT name, dept FROM staff
- C WHERE job='Mgr' FOR UPDATE OF job
-
- EXEC SQL OPEN c1
-
- 100 CONTINUE
- EXEC SQL FETCH c1 INTO :pname, :dept
-
- WRITE(*,*) pname , ' in dept. ',
- C dept, ' will be demoted to Clerk.'
-
- EXEC SQL UPDATE staff SET job = 'Clerk' WHERE CURRENT OF c1
- GOTO 100
-
- 200 EXEC SQL CLOSE c1
-
- 300 IF ( SQLCODE .NE. 0 ) THEN
- WRITE (*,*) 'Error: SQLCODE = ', SQLCODE
- ENDIF
-
- EXEC SQL WHENEVER SQLERROR CONTINUE
- EXEC SQL ROLLBACK
- WRITE (*,*) 'On second thought...changes rolled back.'
- EXEC SQL CONNECT RESET
- STOP
- END