i'm writing sql and c++ code that adds a technician into the database. there's 3 sql insert statements that has to be performed. i have that include in my code, but my code doesn't conform or do what is asked. here is what is asked.
the program should prompt the user for an ssn.
if that ssn/employee is already in the Employee table, the program should inform the user that the employee is already in the DB and ask the user if he wants to update the union-membership-number of that employee; if the user's answer is yes, the program should ask the user for the new union-member-number and update it in the DB.
if the ssn/employee is not already in the DB, the program should ask the user for the union-membership-number of that employee and then store that record in the Employee table. Assuming the employee is a technician the program should ask the user for the information to be stored about that technician (name, address and phone number) and store it in the Technician table; then the program should ask the user for the airplane model-number that the technician is an expert on and add the corresponding record into the Experts table.
here is my code:
void add_technician() {
EXEC SQL BEGIN DECLARE SECTION;
char sn[9];
int s=0;
char answer;
int umn;
char tname[30];
char tadd[30];
char tpho[10];
char tmod[15];
EXEC SQL END DECLARE SECTION;
cout << "Enter social security number:";
cin >> sn;
EXEC SQL SELECT SSN into :s from Employee where SSN= :sn;
if (s == sn)
{
cout << "Employee already exists in the database.";
cout <<"Would you like to update the union-membership-number?";
cin >> answer;
if (answer == 'y'|| 'Y')
{cout <<"Enter new union member number:";
cin >> umn;
EXEC SQL
INSERT INTO Employee (ssn, union_member_no)
VALUES (:sn, :umn);
}
}
else {
cout << "Enter in union membership number of the new employee: ";
cin >> umn;
EXEC SQL INSERT INTO Employees (ssn, union_member_no)
VALUES (:sn, :umn);
EXEC SQL COMMIT WORK;
cout << "Enter the address of the technician.";
cin >> tadd;
cout << "Enter the name technician name.";
cin >> tname;
EXEC SQL INSERT INTO Technicians (address, name, phone)
VALUES (:tadd, :tname, :tpho);
EXEC SQL COMMIT WORK;
cout << "Enter airplane model number that you are an expert on." ;
cin >> tmod;
EXEC SQL INSERT INTO Experts (model_no, ssn)
VALUES (:tmod);
EXEC SQL COMMIT WORK; }
}
when i run the program, it skips my first two IF statements. i can't seem to understand why.
No comments:
Post a Comment