OCI 批量处理BLOB locator问题。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。

fengkewei 2008-06-20 06:32:38
bool update_blob(BLOBPIC **blobsub, OCILobLocator **blob)
{
text *update = (text *)"SELECT pic FROM blobpic WHERE pid = :1 FOR UPDATE";
OCIBind *bndhp1 = NULL;
OCIDefine *defhp1 = NULL;
sb4 status = 0;
bool ersign = 1;
BLOBPIC *tempid = NULL; //用来临时保存PID

//tempid = blobsub->pid;
//prepare to update

ersign = ersign & CheckErr(errhp, OCIStmtPrepare(stmthp, errhp, (oratext *)update, (sb4)strlen((char *)update), OCI_NTV_SYNTAX, OCI_DEFAULT));

ersign = ersign & CheckErr(errhp, OCIBindByPos(stmthp, &bndhp1, errhp, 1, blobsub[0]->pid,(sb4)sizeof(blobsub[0]->pid), SQLT_INT,&blobsub[0]->indic, &blobsub[0]->alen, &blobsub[0]->rcodep, MAXPICNUM, &blobsub[0]->curelp, OCI_DEFAULT));
OCIBindArrayOfStruct(bndhp1, errhp, sizeof(blobsub[0]->pid), sizeof(sb2), sizeof(ub2), sizeof(ub2), sizeof(ub2)); //批量处理

ersign = ersign & CheckErr(errhp, OCIDefineByPos(stmthp, &defhp1, errhp, 1, (void *)blob[0], (sb4)sizeof(blob[0]), SQLT_BLOB, 0, 0, 0, OCI_DEFAULT));
OCIDefineArrayOfStruct(defhp1, errhp, sizeof(blob),sizeof(sb2), sizeof(ub2), sizeof(ub2));

//update
status = OCIStmtExecute(svchp, stmthp, errhp, MAXPICNUM, 0, NULL, NULL, OCI_DEFAULT);

if(status && status != OCI_SUCCESS_WITH_INFO) //出错则返回
{
CheckErr(errhp, status);
OCIHandleFree((dvoid *)envhp, OCI_HTYPE_ENV);
return FALSE;
}

return ersign;
}


运行时出现"编译绑定长度不同于执行绑定长度"的错误代码
MAXPICNUM 为3
是不是哪儿的参数错了?

OCIBindByPos()的最后那几个指针是否必须为指针?数组可以么?alenp 与indp rcodep maxarr_len curelep 他们都必须要设置么?

谢谢!!
...全文
205 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
sailing0123 2008-07-11
  • 打赏
  • 举报
回复
楼主搞清楚了吗?

sword OCIBindByPos ( OCIStmt *stmtp,
OCIBind **bindpp,
OCIError *errhp,
ub4 position,// 绑定的位置
dvoid *valuep,
sb4 value_sz,
ub2 dty,
dvoid *indp,
ub2 *alenp,
ub2 *rcodep,
ub4 maxarr_len,
ub4 *curelep,
ub4 mode );

后面的几个参数中有一个参数需要赋值,设置好了就插入空值也可以,
不知是indp还是alenp,
目前也在尝试中。。。。。
fengkewei 2008-06-21
  • 打赏
  • 举报
回复
Is any body who know this???
fengkewei 2008-06-20
  • 打赏
  • 举报
回复
//在表项中插入空值(其他表项也一并插入),blobsub指向表中的一行数据,成功返回1,失败返回0
bool insert_null_blob(BLOBPIC **blobsub, OCILobLocator **blob)
{
bool ersign = 1; //用于错误检测
OCIBind *bndhp1 = NULL,
*bndhp2 = NULL,
*bndhp3 = NULL;
ub4 status = 0;
BLOBPIC *tempstrc = NULL; //保存临时结构
sb4 temid; //保存临时ID
sb4 tempid; //保存临时PID
text *insert = (text *)"INSERT INTO blobpic VALUES(:1, empty_blob(), :2)";

assert(blobsub);
assert(blob);

/*
tempstrc = blobsub;
temid = tempstrc->patientid;
tempid = tempstrc->pid;*/



//insert a null BLOB

ersign = ersign|CheckErr(errhp, OCIStmtPrepare(stmthp, errhp, (oratext *)insert, (sb4)strlen((char *)insert), OCI_NTV_SYNTAX, OCI_DEFAULT));

//Attrset to NULL
//OCIAttrSet(*blob, OCI_DTYPE_LOB, (dvoid*)0, (ub4)0, OCI_ATTR_LOBEMPTY, errhp); //将locator指向的blob置空
ersign = ersign|CheckErr(errhp, OCIBindByPos(stmthp, &bndhp1, errhp, 1, blobsub[0]->patientid, (sb4)sizeof(blobsub[0]->patientid), SQLT_INT, 0, 0, 0, 0, 0, OCI_DEFAULT));
CheckErr(errhp, OCIBindArrayOfStruct(bndhp1, errhp, sizeof(blobsub[0]->patientid), 0, 0, 0));

/*
ersign = ersign|CheckErr(errhp, OCIBindByPos(stmthp, &bndhp2, errhp, 2, *blob, (sb4)sizeof(blob), SQLT_BLOB, 0, 0, 0, 0, 0, OCI_DEFAULT));
OCIBindArrayOfStruct(bndhp1, errhp, sizeof(blob), 0, 0, 0);*/


ersign = ersign|CheckErr(errhp, OCIBindByPos(stmthp, &bndhp3, errhp, 2, blobsub[0]->pid, (sb4)sizeof(blobsub[0]->pid), SQLT_INT, 0, 0, 0, 0, 0, OCI_DEFAULT));
CheckErr(errhp, OCIBindArrayOfStruct(bndhp1, errhp, sizeof(blobsub[0]->pid), 0, 0, 0));

//insert an empty BLOB
status = OCIStmtExecute(svchp, stmthp, errhp, MAXPICNUM, 0, NULL, NULL, OCI_DEFAULT);
if(status && status != OCI_SUCCESS_WITH_INFO)
{
CheckErr(errhp, status);
OCIHandleFree((dvoid *)envhp, OCI_HTYPE_ENV);
return FALSE;
}
printf("The empty record has been inserted into the database!\n");
printf("Beginning to update the BOLB...\n");

//commit
//OCITransCommit(svchp, errhp, 0);
return ersign;


}


这个是批量插入空值的 老在执行的那步出写入错误
fengkewei 2008-06-20
  • 打赏
  • 举报
回复
我还想问下 批量绑定空值的时候 我怎么老出写入错误? 后面的参数都设置的0

谢谢!!!

17,086

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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