OCI编程中BindByPos绑定时总出错,求解!!!
OCI编程时,我绑定的数据如果为数值型字符串时(char * sno[] = "123"),最后可以成功入库,但如果绑定不为数值字符串(char * sno[] = "abc")时,总不能入库,不知为何,求高手指点。部分代码如下:
if(g_IndbInterFace.ConnectToDB(chUserName, chPassword, chServerName))
{
printf("can not connect to DB!");
return -1;
}
printf("connect succeed!\n");
int status;
char no[] = "333";
char name[] = "aaa";
OCIBind *bndhp1, *bndhp2;
char chInsertArray[1024];
sprintf(chInsertArray,"insert into s(sno,sname) values(%s,%s)",no,name);
g_IndbInterFace.SqlBind(chInsertArray);
if(status=OCIBindByPos(stmthp,&bndhp1,errhp,(ub4)(1),
(dvoid *)(no),(sb4)(FIELD_LEN+1),
SQLT_STR,(dvoid *)0,(ub2 *)0,(ub2 *)0,
(ub4)0, (ub4 *)0,(ub4)OCI_DEFAULT))
{
WriteAlert("DataInBind(433) FAILED: OCIBindByPos()");
}
if(status=OCIBindByPos(stmthp,&bndhp2,errhp,(ub4)(2),
(dvoid *)(&b),(sb4)(FIELD_LEN+1),
SQLT_STR,(dvoid *)0,(ub2 *)0,(ub2 *)0,
(ub4)0, (ub4 *)0,(ub4)OCI_DEFAULT))
{
WriteAlert("DataInBind(433) FAILED: OCIBindByPos()");
}
g_IndbInterFace.DataInExec(1,0);
g_IndbInterFace.TransCommit();
g_IndbInterFace.DisConnectToDB();