OCI批量 新增 数据时数据长度的问题

CHID 2010-12-14 03:24:42
字段q_id的类型为varchar(45),更新数据时,如果q_id字符串的长度刚好为45时,没有问题,可实际上q_id字符串的长度可能小于45,例如当q_id="ID1000"时,实际存入数据库中的值为"ID1000"+乱码,怎么解决?
表结构:
create table testtable
(
q_id varchar(45),
qq_flag varchar(2),
qvalue decimal(20,2)
)
批量新增数据的函数:


int OCI_TOOLS::ORA_BindArrayWithupdatead(char *buff, float qvalue[], char q_id[][45],char qq_flag[][2],int maxiter)
{
text *sqltext;
int i;
sword ret1,ret2,ret3,ret4;
text msgbuf[512];

/* bind handles will be implicitly allocated in the bind calls */
/* need to initialize them to null prior to first usage in bind calls */

OCIBind *bnd1p = (OCIBind *) 0; /* the first bind handle */
OCIBind *bnd2p = (OCIBind *) 0; /* the second bind handle */
OCIBind *bnd3p = (OCIBind *) 0; /* the third bind handle */

text *sqlstmt = (text *)buff;

if (OCIStmtPrepare(stmthp, errhp, sqlstmt, (ub4)strlen((char *)sqlstmt),
(ub4) OCI_NTV_SYNTAX, (ub4) OCI_DEFAULT))
{
(void) printf("FAILED: OCIStmtPrepare() update\n");
//report_error(errhp);
return OCI_ERROR;
}
ret1=OCIBindByPos(stmthp, &bnd1p,errhp, (ub4) 1,
(dvoid *) qvalue, (sb4) 4, SQLT_FLT,
(dvoid *) 0, (ub2 *)0, (ub2 *)0,
(ub4) 0, (ub4 *) 0, (ub4) OCI_DEFAULT);

ret3=OCIBindByPos(stmthp, &bnd3p,errhp, (ub4) 3,
(dvoid *) q_id, (sb4) 45, SQLT_CHR,
(dvoid *) 0, (ub2 *)0, (ub2 *)0,
(ub4) 0, (ub4 *) 0, (ub4) OCI_DEFAULT);

ret2=OCIBindByPos(stmthp, &bnd2p,errhp, (ub4) 2,
(dvoid *) qq_flag, (sb4) 2, SQLT_CHR,
(dvoid *) 0, (ub2 *)0, (ub2 *)0,
(ub4) 0, (ub4 *) 0, (ub4) OCI_DEFAULT);


if (ret1||ret2||ret3)
{
(void) printf("FAILED: OCIBindArrayOfStruct()\n");
//report_error(errhp);
return OCI_ERROR;
}

ret1=OCIBindArrayOfStruct(bnd1p,errhp, 4, 0, 0, 0);
ret3=OCIBindArrayOfStruct(bnd3p,errhp, 45, 0, 0, 0);
ret2=OCIBindArrayOfStruct(bnd2p,errhp, 2, 0, 0, 0);

if (ret1||ret2||ret3)
{
(void) printf("FAILED: OCIBindArrayOfStruct()\n");
//report_error(errhp);
return OCI_ERROR;
}



if (OCIStmtExecute(svchp, stmthp,errhp, (ub4) maxiter, (ub4) 0,
(CONST OCISnapshot*) 0, (OCISnapshot*) 0,
(ub4) OCI_COMMIT_ON_SUCCESS))
{
(void) printf("FAILED: OCIStmtExecute() update ccbase\n");
//report_error(errhp);
sb4 errcode = 0;
(void) OCIErrorGet((dvoid *) errhp, (ub4) 1, (text *) NULL, &errcode,
msgbuf, (ub4) sizeof(msgbuf), (ub4) OCI_HTYPE_ERROR);
(void) printf("ERROR CODE = %d\n", errcode);
(void) printf("%.*s\n", 512, msgbuf);
return OCI_ERROR;
}
status=OCITransCommit(svchp,errhp,0);
if(status!=OCI_SUCCESS)
{
error_proc(errhp,status);
return OCI_FAIL;
}

return OCI_SUCCESS;
}
...全文
97 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
lgs666 2010-12-15
  • 打赏
  • 举报
回复
冷清。

4,018

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 数据库
社区管理员
  • 数据库
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧