Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- IDENTIFICATION DIVISION.
- PROGRAM-ID. connection.
- ENVIRONMENT DIVISION.
- Input-output section.
- file-control.
- select parameterfile
- assign to "parbest.txt"
- organization is line sequential
- access mode is sequential.
- select logfile assign to "logfile.txt"
- organization is sequential
- access mode is sequential.
- DATA DIVISION.
- File section.
- FD logfile.
- * linage 60
- * with footing at 56
- * lines at bottom 3.
- * linage mag gebruikt worden in UC 2, maar is hier niet nodig.
- 01 logMessage pic x(100).
- FD parameterfile.
- 01 viewingRecord.
- 88 end-file value low-values.
- 02 readline pic x(1000).
- EXEC SQL BEGIN DECLARE SECTION END-EXEC
- 77 SQLCODE pic S9(3).
- 77 SQLSTATE pic x(5).
- EXEC SQL END DECLARE SECTION END-EXEC
- * SQLCODE is 0 for success, 100 for no data, -1 for failure
- 01 SQLCODE pic S9(3).
- * SQLSTATE is a 5 character communication code; 00xxx is success.
- 01 SQLSTATE pic x(5).
- Working-storage section.
- 01 inputString pic x(255).
- 01 email pic x(100).
- 01 name pic x(50).
- 01 firstName pic x(50).
- 01 pass pic x(100).
- 01 sqlCount pic 999 value 0.
- PROCEDURE DIVISION.
- Pgm.
- display "PMES Database Creator"
- display "====================="
- display ""
- open output logfile
- open input parameterfile
- * Initial read of parameterfile
- display "STATUS: Reading parameters"
- read parameterfile next at end
- move high-values to viewingRecord
- perform LOG-EMPTYFILE
- perform EXITPROGRAM
- end-read.
- move readline to inputString
- perform CONNECT
- if SQLCODE = 0
- display "STATUS: Successfully connected to the database"
- perform LOG-CONNECTION
- * Read email, name, firstName & pass
- display "STATUS: Reading e-mail, name, first name & password"
- perform READPARAMETERFILE
- unstring readline delimited by " " into
- email name firstName pass
- end-unstring
- * Read & execute SQL instructions
- display "STATUS: Reading & executing SQL statements"
- perform until end-file
- perform READPARAMETERFILE
- move readline to inputString
- EXEC SQL
- EXECUTE IMMEDIATE :inputString
- END-EXEC
- if SQLCODE = 0
- add 1 to sqlCount
- perform LOG-SQLSTATEMENT
- else
- string
- "ERROR : Problem while executing SQL statement " delimited
- by size
- sqlCount delimited by size
- into inputString
- end-string
- display inputString
- move -1 to sqlCount
- perform EXITPROGRAM
- end-if
- end-perform
- EXEC SQL
- COMMIT
- END-EXEC
- if SQLCODE = 0
- display "COMMIT OK"
- else
- perform LOG-COMMIT
- display "ERROR: Problem while commiting to database"
- move -1 to sqlCount
- perform EXITPROGRAM
- end-if
- EXEC SQL
- DISCONNECT
- END-EXEC
- else
- * TODO: Specifieke fouten loggen.
- move -1 to sqlCount
- perform LOG-CONNECTIONERROR
- end-if.
- perform EXITPROGRAM.
- * PROCEDURES
- READPARAMETERFILE.
- read parameterfile next at end
- move high-values to viewingRecord
- perform LOG-ENDOFFILE
- end-read.
- CONNECT.
- display "STATUS: Connecting to database"
- EXEC SQL
- CONNECT TO :inputString
- DRIVER "com.microsoft.sqlserver.jdbc.SQLServerDriver"
- END-EXEC.
- EXITPROGRAM.
- close logfile
- close parameterfile
- if sqlCount = -1
- display "The program has terminated due to errors, please ref"
- "er to the logfile for more infomation."
- else
- display "The program has successfully completed."
- end-if
- exit program.
- * LOG PROCEDURES
- LOG-EMPTYFILE.
- move "ERROR FILE : Read file is empty" to logMessage
- write logMessage.
- LOG-CONNECTION.
- move "STATUS DATABASE : Connection was made" to logMessage
- write logMessage
- move "STATUS FILE : Parameterfile is being read.."
- to logMessage
- write logMessage.
- LOG-CONNECTIONERROR.
- move "ERROR DATABASE : Connection could not be made."
- to logMessage
- write logMessage.
- LOG-ENDOFFILE.
- move "STATUS FILE : End of file." to logMessage
- write logMessage.
- LOG-SQLSTATEMENT.
- string
- "STATUS DATABASE : SQL statement " delimited by size
- sqlCount delimited by size
- " > " delimited by size
- inputString delimited by size
- into logMessage
- end-string
- write logMessage.
- LOG-COMMIT.
- move "ERROR DATABASE : Problem while commiting to database" to
- logMessage
- write logMessage.
Add Comment
Please, Sign In to add comment