oci 执行sql问题。
void insertRecord()
{
char insert[255] = "INSERT INTO emp(empno, ename, job, sal, deptno) VALUES (";
text *ename, *job,*empno, *sal, *deptno;
static sword sql_function;
ename = (text *) malloc((int)sizeof(sword) + 2);
job = (text *) malloc((int)sizeof(sword) + 2);
empno = (text *) malloc((int)sizeof(sword) + 2);
deptno = (text *) malloc((int)sizeof(sword) + 2);
//
printf("\nenter user name: ");
gets((char*)ename);
printf("\nenter job: ");
gets((char *) job);
printf("\nenter deptno: ");
gets((char*)deptno);
printf("\nenter empno: ");
gets((char*)empno);
printf("\nenter sal: ");
gets((char*)sal);
printf("\nenter complete please wait commit\n");
//执行sql语句
// :empno, :ename, :job, :sal, :deptno)
strcat((char*)insert,empno);
strcat((char*)insert,",'");
strcat((char*)insert,ename);
strcat((char*)insert,"'");
strcat((char*)insert,",'");
strcat((char*)insert,job);
strcat((char*)insert,"'");
strcat((char*)insert,",");
strcat((char*)insert,sal);
strcat((char*)insert,",");
strcat((char*)insert,deptno);
strcat((char*)insert,");");
printf("%s",insert);
if (oparse(&cda, (text *) insert, (sb4) -1,
(sword) 0, (ub4) 2))
{
oci_error(&cda);
}
if(oexec(&cda)&& cda.rc != 1)
{
printf("\nexecute the insert error.");
}
//提交
if(ocom(&lda))
{
printf("\ncommit error!");
}
}
检查sql 语句时出错。
打印出来的sql 在sql plus 里可以正确执行。