* An example program which adds new employee
* records to the personnel data base. Checking
* is done to insure the integrity of the data base.
* The employee numbers are automatically selected using
* the current maximum employee number as the start.
*
* The program queries the user for data as follows:
*
* Enter employee name:
* Enter employee job:
* Enter employee salary:
* Enter employee dept:
*
* The program terminates if return key (CR) is entered
* when the employee name is requested.
*
* If the record is successfully inserted, the following
* is printed:
*
* "ename" added to department "dname" as employee # "empno"
*
* The size of the HDA is defined by the HDA_SIZE constant,
* which is declared in ocidem.h to be 256 bytes for 32-
* bit architectures and 512 bytes for 64-bit architectures.
*/
text *username = (text *) "SCOTT";
text *password = (text *) "TIGER";
/* Define SQL statements to be used in program. */
text *insert = (text *) "INSERT INTO emp(empno, ename, job, sal, deptno)\
VALUES (:empno, :ename, :job, :sal, :deptno)";
text *seldept = (text *) "SELECT dname FROM dept WHERE deptno = :1";
text *maxemp = (text *) "SELECT NVL(MAX(empno), 0) FROM emp";
text *selemp = (text *) "SELECT ename, job FROM emp";
/* Define an LDA, a HDA, and two cursors. */
Lda_Def lda;
ub4 hda[HDA_SIZE/sizeof(ub4)];
Cda_Def cda1;
Cda_Def cda2;
/*
* Connect to ORACLE and open two cursors.
* Exit on any error.
*/
if (olog(&lda, (ub1 *)hda, username, -1, password, -1,
(text *) 0, -1, (ub4)OCI_LM_DEF))
{
err_report(&lda);
exit(EXIT_FAILURE);
}
printf("Connected to ORACLE as %s\n", username);