! Copyright © 1995, 2003, Oracle Corporation. All Rights Reserved. OPTION TYPE = EXPLICIT ON ERROR GOTO ERR_ROUTINE ! Declare a variable to hold the value of SQLCODE. DECLARE LONG SQL_RETURN_STATUS ! Declare variables to hold the integer values of the ! input salary amounts. ! DECLARE INTEGER MAX_SAL, MIN_SAL ! Use the RECORD statement to specify a record structure. ! RECORD JOBS STRING JOB_CODE = 4 STRING FILL1 = 3 STRING WAGE_CLASS = 1 STRING FILL2 = 3 STRING JOB_TITLE = 20 STRING FILL3 = 3 STRING MINIMUM_SALARY = 6 STRING FILL4 = 3 STRING MAXIMUM_SALARY = 6 STRING FILL5 = 1 END RECORD JOBS ! Use MAP to associate the record structure with the input ! file. ! MAP (LINEIN) JOBS JOB_REC ! SQL module language procedure declarations EXTERNAL SUB SET_TRANSACTION (LONG) EXTERNAL SUB INSERT_JOBS (LONG,STRING,STRING,STRING,INTEGER,INTEGER) EXTERNAL SUB COMMIT_TRANS (LONG) EXTERNAL SUB ROLLBACK_TRANS (LONG) ! Open the file, using MAP to associate the input file with ! the record structure. ! OPEN "SQL$SAMPLE:SQL_JOBS.DAT" & FOR INPUT AS FILE #1, & ORGANIZATION SEQUENTIAL VARIABLE, & ACCESS READ, & RECORDTYPE ANY, & MAP LINEIN ! Call the SQL module to start the transaction. CALL SET_TRANSACTION(sql_return_status) get_loop: WHILE -1% GET #1 ! Use the INTEGER function to convert the TEXT ! data type to LONGWORD. ! MIN_SAL = INTEGER(JOB_REC::MINIMUM_SALARY) MAX_SAL = INTEGER(JOB_REC::MAXIMUM_SALARY) ! Call the SQL module to insert a row in the jobs table. ! Notice that the program stores MIN_SAL and MAX_SAL, the ! converted integer values, instead of the TEXT ! fields, from the input file. CALL INSERT_JOBS (sql_return_status,JOB_REC::JOB_CODE,& JOB_REC::WAGE_CLASS, JOB_REC::JOB_TITLE, & MIN_SAL,MAX_SAL) NEXT EXIT PROGRAM err_routine: SELECT ERR CASE 11 PRINT "Encountered end-of-file" ! Commit the transaction. CALL COMMIT_TRANS(sql_return_status) RESUME JOB1 CASE ELSE PRINT "Unexpected error number "; ERR PRINT "Error is "; ERT$(ERR) ! Rollback the transaction. CALL ROLLBACK_TRANS(sql_return_status) RESUME JOB1 END SELECT JOB1: END PROGRAM