Databases Reference
In-Depth Information
printf ("\n");
}
EXEC SQL CONNECT RESET;
}
/******************************************************
** This function will add a product into the
** INVENTORY table. It demonstrates how to write a
** simple static SQL statement and work with the
** SQLCA to get back information on the processing of
** an SQL statement
*******************************************************/
void add_product(void)
{
printf("-------------------------------------------------\n");
printf(" Add A Product \n\n");
printf(" Enter Product ID : ");
scanf("%s", &PID);
printf(" Enter Quantity : ");
scanf("%d", &quantity);
printf(" Enter Location : ");
scanf("%s", &location);
EXEC SQL INSERT INTO inventory (PID, quantity, location) VALUES
(:PID, :quantity, :location);
if (sqlca.sqlcode!=0) {
if (sqlca.sqlcode == -803)
printf("\n Error: Product already exists in the database.\n");
else
printf("\n Error: Problem occurred when adding a new product.
Sqlcode: %d Sqlstate: %s\n",sqlca.sqlcode, sqlca.sqlstate);
return;
}
EXEC SQL COMMIT;
printf("\n Product successfully added.");
}
/******************************************************
** This function will update information on an existing
** product into the INVENTORY table. It demonstrates
** how to write dynamic SQL, and use the WHENEVER
** statement.
Search WWH ::




Custom Search