/* Copyright © Oracle Corporation 1995. All Rights Reserved. */ /***************************************************************************** * This routine transfers an employee from the EAST database to the WEST * database. It expects the distributed context structure as a parameter * The employee record is selected first, deleted from the EAST database * and inserted into the WEST database * *****************************************************************************/ #include #include #include #include #include EXEC SQL INCLUDE SQLCA; EXEC SQL DECLARE east ALIAS FOR FILENAME 2pceast; EXEC SQL DECLARE west ALIAS FOR FILENAME 2pcwest; struct context_struct { long version; long type; long length; long distributed_tid[4]; long end; }; struct employ_struct { char emp_id[6]; char emp_last_name[15]; char emp_first_name[11]; char emp_middle_initial[2]; char emp_address1[26]; char emp_city[21]; char emp_state[3]; char emp_zip[6]; char emp_sex[2]; char emp_birth[8]; }; extern char emp_id[6]; long sqlcode; void sql$dist_trans_error (struct context_struct *context); transfer_west(struct context_struct *context, struct employ_struct *employee) { struct context_struct local_context; struct employ_struct local_employee; local_context = *context; local_employee = *employee; EXEC SQL WHENEVER SQLERROR GOTO handle_error; printf("\nSelecting employee record from EAST \n"); EXEC SQL USING CONTEXT :local_context Select EMPLOYEE_ID,LAST_NAME,FIRST_NAME,MIDDLE_INITIAL, ADDRESS_DATA_1, CITY, STATE, POSTAL_CODE, SEX, BIRTHDAY INTO :local_employee.emp_id, :local_employee.emp_last_name, :local_employee.emp_first_name, :local_employee.emp_middle_initial, :local_employee.emp_address1, :local_employee.emp_city, :local_employee.emp_state, :local_employee.emp_zip, :local_employee.emp_sex, :local_employee.emp_birth FROM east.EMPLOYEES WHERE east.EMPLOYEES.EMPLOYEE_ID = :emp_id; printf("Deleting the record from the EAST database \n"); EXEC SQL USING CONTEXT :local_context DELETE FROM east.EMPLOYEES E WHERE E.EMPLOYEE_ID = :emp_id; printf("\nInserting the employee record into WEST \n"); EXEC SQL USING CONTEXT :local_context INSERT INTO west.EMPLOYEES (EMPLOYEE_ID,LAST_NAME,FIRST_NAME,MIDDLE_INITIAL, ADDRESS_DATA_1,CITY,STATE, POSTAL_CODE, SEX, BIRTHDAY) VALUES (:local_employee.emp_id, :local_employee.emp_last_name, :local_employee.emp_first_name, :local_employee.emp_middle_initial, :local_employee.emp_address1, :local_employee.emp_city, :local_employee.emp_state, :local_employee.emp_zip, :local_employee.emp_sex, :local_employee.emp_birth); return; handle_error: printf("\nError at Transfer_WEST \n"); sql$dist_trans_error(&local_context); return; }