The following is an example that connects to the database defined as the default. All rows are then fetched from the table INFORMATION_SCHEMA.TABLES.
The example is stored in a file called simple.efo (see links below).
PROGRAM SQLEX
EXEC SQL BEGIN DECLARE SECTION
CHARACTER*5 SQLSTATE
CHARACTER*128 SCHEMA
CHARACTER*128 TABLE
CHARACTER*20 TYPE
EXEC SQL END DECLARE SECTION
EXEC SQL DECLARE MYCURSOR CURSOR FOR
+ SELECT TABLE_SCHEMA, TABLE_NAME, TABLE_TYPE
+ FROM INFORMATION_SCHEMA.TABLES
C Connect to default database
EXEC SQL CONNECT TO '' USER 'SYSADM' USING 'SYSADM'
EXEC SQL OPEN MYCURSOR
EXEC SQL FETCH MYCURSOR INTO :SCHEMA, :TABLE, :TYPE
DO WHILE (SQLSTATE .NE. ‘02000’)
WRITE(6,100) SCHEMA, TABLE, TYPE
100 FORMAT(X,A,X,A,X,A)
EXEC SQL FETCH MYCURSOR INTO :SCHEMA, :TABLE, :TYPE
END DO
EXEC SQL CLOSE MYCURSOR
EXEC SQL COMMIT
EXEC SQL DISCONNECT DEFAULT
END
The program is preprocessed as follows:
esql –for simple.efo
The resulting file, ‘simple.for’, is compiled using a FORTRAN-compiler and then linked. When executing the resulting ‘simple’ program, a list of the items selected will be displayed.
You can find a more complete example in example.efo.