/* Copyright © 1995, 1997, Oracle Corporation. All Rights Reserved. */ /* ABSTRACT: * * This program demonstrates the use of the SQL precompiler for the C * language to load an Oracle Rdb database from a stream (flat) file. * * This program attaches to an existing Oracle Rdb database, opens a data * file containing job records, and reads the records, formatting and * inserting them into the database until the end of the date file * is reached. Then the program commits the transaction. */ #include #include #include #include #ifdef VMS #include "sql$sample:sql_load_rtl.sc" #endif #if defined(__osf__) || defined (_WIN32) #include #endif main( ) { /* Fields to receive strings read from the SQL_JOBS.DAT file record */ char j_code[5]; char w_class[2]; char j_title[21]; char min_sal[7]; char max_sal[7]; /* File definitions for reading the SQL_JOBS.DAT file */ FILE *jobs_file; /* Declarations for error handling */ int return_status; /* Define the SQLCA. */ EXEC SQL INCLUDE SQLCA; /* Declare the database. */ EXEC SQL DECLARE ALIAS FILENAME 'personnel'; /* Set up error handling for failures on execution of SQL statements. */ EXEC SQL WHENEVER SQLERROR GOTO HANDLE_ERROR; /* Operator message to the terminal */ printf("\nProgram: Loading JOBS"); /* Open the sequential file containing the job history data records. */ #ifdef VMS jobs_file = fopen("sql$sample:sql_jobs.dat","r"); #endif #if defined(__osf__) || defined (_WIN32) jobs_file = fopen("sql_jobs.dat","r"); #endif /* This procedure uses the executable form for starting a transaction. */ EXEC SQL SET TRANSACTION READ WRITE RESERVING JOBS FOR EXCLUSIVE WRITE; /* Main loop until data file is empty */ while (get_line(jobs_file) != NULL) { get_field(jobs_file,j_code ,4); get_field(jobs_file,NULL ,3); get_field(jobs_file,w_class ,1); get_field(jobs_file,NULL ,3); get_field(jobs_file,j_title ,20); get_field(jobs_file,NULL ,3); get_field(jobs_file,min_sal ,6); get_field(jobs_file,NULL ,3); get_field(jobs_file,max_sal ,6); /* INSERT a row in the JOBS table. * The list of names in the VALUES clause corresponds to the * host variables containing the values. The list of names that * follows the INSERT clause names the columns in the table * that are to be inserted. */ EXEC SQL INSERT INTO JOBS (JOB_CODE, WAGE_CLASS, JOB_TITLE, MINIMUM_SALARY, MAXIMUM_SALARY) VALUES (:j_code, :w_class, :j_title, :min_sal, :max_sal); } /* Commit the transaction. */ EXEC SQL COMMIT; /* Close the sql_jobs.dat data file. */ fclose(jobs_file); /* Operator prompt message */ printf("\nProgram: JOBS Loaded. Normal End-of-Job"); exit(1); /* Error handler for SQL errors */ HANDLE_ERROR: sql_signal(); exit(1); }