HELPLIB.HLB  —  SQL72  System Tables, Example
    The following BASIC program uses an SQL Module to query system
    tables

    PROGRAM SYSTEM_RELATION
    !  This BASIC program interactively prompts a user to enter a name
    !  of a system table (table).  Next, the program calls an SQL
    !  Module which uses a cursor to read the system table that the
    !  user entered.  Upon reading the fields (domains) of the system
    !  table, the program displays a message to the user as to whether
    !  the fields in a system table can be updated.
    OPTION TYPE = EXPLICIT, SIZE = INTEGER LONG
    ON ERROR GOTO ERR_ROUTINE
    !
    ! Declare variables and constants
    !
    DECLARE STRING Column_name, Table_name
    DECLARE INTEGER Update_yes, sqlcode
    DECLARE INTEGER CONSTANT TRIM_BLANKS = 128, UPPER_CASE = 32
    EXTERNAL SUB SET_TRANSACTION (LONG)
    EXTERNAL SUB OPEN_CURSOR(LONG,STRING)
    EXTERNAL SUB FETCH_COLUMN(LONG,STRING,INTEGER)
    EXTERNAL SUB CLOSE_CURSOR(LONG)
    EXTERNAL SUB COMMIT_TRANS (LONG)
    !
    ! Prompt for table name
    !
    INPUT 'Name of Table'; Table_name
    Table_name = EDIT$(Table_name, UPPER_CASE)
    PRINT 'Starting query'
    PRINT 'In '; Table_name; ' Table, columns:'
    !
    ! Call the SQL module to start the transaction.
    !
    CALL SET_TRANSACTION(Sqlcode)
    !
    ! Open the cursor.
    !
    CALL OPEN_CURSOR(Sqlcode, Table_name)
    GET_LOOP:
    WHILE (Sqlcode = 0)
    !
    ! Fetch each column
    !
    CALL FETCH_COLUMN(Sqlcode, Column_name, Update_yes)
         IF (Sqlcode = 0)
           THEN
             !
             ! Display returned column
             !
             PRINT '  '; EDIT$(Column_name, TRIM_BLANKS);
             IF (update_yes = 1)
               THEN
                 PRINT ' can be updated'
               ELSE
                 PRINT ' cannot be updated'
             END IF
         END IF
    NEXT

    ERR_ROUTINE:
      IF Sqlcode = 100
        THEN
          PRINT "No more rows."
          RESUME PROG_END
        ELSE
          PRINT "Unexpected error: ", Sqlcode, Err
          RESUME PROG_END
      END IF
    PROG_END:
    !
    ! Close the cursor, commit work and exit
    !
     CALL CLOSE_CURSOR(Sqlcode)
     CALL COMMIT_TRANS(Sqlcode)
    END PROGRAM

    The following module provides the SQL procedures that are called
    by the preceding BASIC program.

    -- This SQL module provides the SQL procedures that are called by the
    -- preceding BASIC program, System Table

    -----------------------------------------------------------------
    -- Header Information Section
    -----------------------------------------------------------------
    MODULE          SQL_SYSTEM_REL_BAS  -- Module name
    LANGUAGE        BASIC               -- Language of calling program
    AUTHORIZATION   SQL_SAMPLE          -- Authorization ID

    --------------------------------------------------------------------
    -- DECLARE Statements Section
    --------------------------------------------------------------------
    DECLARE ALIAS FILENAME 'MF_PERSONNEL'  -- Declaration of the database.

    DECLARE SELECT_UPDATE CURSOR FOR
        SELECT RDB$FIELD_NAME, RDB$UPDATE_FLAG
        FROM RDB$RELATION_FIELDS
        WHERE RDB$RELATION_NAME = table_name
        ORDER BY RDB$FIELD_POSITION

    --------------------------------------------------------------------
    -- Procedure Section
    --------------------------------------------------------------------
    -- Start a transaction.
    PROCEDURE SET_TRANSACTION
        SQLCODE;

        SET TRANSACTION READ WRITE;

    -- Open the cursor.
    PROCEDURE OPEN_CURSOR
        SQLCODE
        table_name          RDB$RELATION_NAME;

        OPEN SELECT_UPDATE;

    -- Fetch a row.
    PROCEDURE FETCH_COLUMN
        SQLCODE
        field_name          RDB$FIELD_NAME
        update_flag         RDB$UPDATE_FLAG;

        FETCH SELECT_UPDATE INTO :field_name, :update_flag;

    -- Close the cursor.
    PROCEDURE CLOSE_CURSOR
        SQLCODE;

        CLOSE SELECT_UPDATE;

    -- Commit the transaction.
    PROCEDURE COMMIT_TRANS
        SQLCODE;

        COMMIT;
Close Help