Skip to content

LOB操作示例

int ret; 
char sql_insert[]="insert into T_BLOB_A1 values(lob_t1_seq.nextval,?,?)";
int i=0;  
char desc_val[40]={0};
int clen1,clen2,rp1,rp2;
FILE* fp;
int  BUFFLEN=20*1024*1024;
char* buff_val=(char*)malloc(BUFFLEN+1);

LobLocator p_lob= XuguCILobCreate();
for(i=1;i<135;i++)  
{
    ret= XuguCIFreeStmt(connp->hdstmt,Xugu_RESET);
    //bind param
    memset(buff_val,0x0,BUFFLEN+1);
    memset(  desc_val, 0x0,40);
    sprintf(desc_val,"%s%d",prefix , i);
    clen1=strlen(desc_val);
    fp=fopen(desc_val,"rb");
    clen2 = fread(buff_val,1 ,BUFFLEN,fp);
    fclose(fp);
    //bind 
    ret= XuguCILobPutData(p_lob, clen2,buff_val);
    ret=XuguCIBindParamByPos(connp->hdstmt,1,PARAM_IN,desc_val,30,Xugu_C_CHAR,&rp1,&clen1,SQL_CHAR);
    ret=XuguCIBindParamByPos(connp->hdstmt,2,PARAM_IN,p_lob,8,Xugu_C_LOB,&rp2,&clen2,SQL_BLOB);
    ret=XuguCIExecDirect(connp->hdstmt,sql_insert,XuguCI_NTS);
    if(ret<0)
    {
        print_error(connp,ret,sql_insert);
        return ret; 
    }
    XuguCILobReset(p_lob);
}