var
m_blob: TStream;
m_jpeg: TJpegImage;
begin
if length(st)=0 then
exit;
if length(st1)=0 then
exit;xhquery.Close;
xhquery.SQL.Clear;
xhquery.SQL.Add(' select tx from moble.SJXH where sjbh='+QuotedStr(st[ComboBox1.itemindex])+' and xhbh='+QuotedStr(st1[ComboBox2.itemindex]));
xhquery.Open;
xhquery.First;
m_blob := xhquery.CreateBlobStream(xhquery.FieldByName('tx'),bmRead);
m_jpeg:=TJpegImage.Create;
try
if m_blob.Size<>0 then begin
try
m_jpeg.LoadFromStream(m_blob);
Image3.Picture.Assign(m_jpeg);
// Image3.Refresh;
except
end;
end
else
Image3.Picture.Assign(nil);
finally
m_jpeg.Free;
m_blob.Free;
end;
end;以前做的一个试验程序!将数据库的blob数据存到程序上.数据是一张图片
m_blob: TStream;
m_jpeg: TJpegImage;
begin
if length(st)=0 then
exit;
if length(st1)=0 then
exit;xhquery.Close;
xhquery.SQL.Clear;
xhquery.SQL.Add(' select tx from moble.SJXH where sjbh='+QuotedStr(st[ComboBox1.itemindex])+' and xhbh='+QuotedStr(st1[ComboBox2.itemindex]));
xhquery.Open;
xhquery.First;
m_blob := xhquery.CreateBlobStream(xhquery.FieldByName('tx'),bmRead);
m_jpeg:=TJpegImage.Create;
try
if m_blob.Size<>0 then begin
try
m_jpeg.LoadFromStream(m_blob);
Image3.Picture.Assign(m_jpeg);
// Image3.Refresh;
except
end;
end
else
Image3.Picture.Assign(nil);
finally
m_jpeg.Free;
m_blob.Free;
end;
end;以前做的一个试验程序!将数据库的blob数据存到程序上.数据是一张图片
因为和delphi的还是有一些区别的,我的程序也写了,不过总是有问题,以前没用过blob类型,也不知道那个地方用的不恰当,我用OCILocatorIsInit()函数测了一下,好像是我的blob的定位符在被使用之前没有初始化,可是我不知道怎么初始化它,我用select语句和OCIDefineByPos()函数绑定了也不行。
急死了,是不是现在没人用c语言调用oracle数据库了,怎么没人帮我呢。哭泣中……
{
int i = 0, idcol = 1;
ub4 offset = 1;
ub4 amt = 0;
char buf[128];
text *sqlstmtcre = (text *)
"CREATE TABLE testblob(colid INTEGER, colblob BLOB)";
text *sqlstmtins = (text *) "INSERT INTO testblob VALUES (:1, EMPTY_BLOB())";
text *sqlstmtsel = (text *)"select colblob from testblob where colid = :1 for update";
OCILobLocator *pt_blob;
OCIDefine *dfnhp = (OCIDefine *) 0;
OCIBind *bndhp = (OCIBind *) 0; memset(buf, 0, 128);
strcpy(buf, "Shit");
/* Prepare the statement */
if (OCIStmtPrepare(stmthp, errhp, sqlstmtcre, (ub4)strlen((char *)sqlstmtcre),
(ub4) OCI_NTV_SYNTAX, (ub4) OCI_DEFAULT))
{
(void) printf("FAILED: OCIStmtPrepare() create\n");
report_error(errhp);
return OCI_ERROR;
} /* Execute the Create statement */
if (OCIStmtExecute(svchp, stmthp, errhp, (ub4) MAXITER, (ub4) 0,
(CONST OCISnapshot*) 0, (OCISnapshot*) 0,
(ub4) OCI_DEFAULT))
{
(void) printf("FAILED: OCIStmtExecute() create\n");
report_error(errhp);
return OCI_ERROR;
} if(OCIDescriptorAlloc((dvoid *) envhp, (dvoid **) &pt_blob,
(ub4) OCI_DTYPE_LOB, (size_t) 0, (dvoid **) 0))
{
(void) printf("FAILED: OCIDescriptorAlloc()\n");
return OCI_ERROR;
} /* Prepare the statement */
if(OCIStmtPrepare(stmthp, errhp, sqlstmtins, (ub4)strlen((char *)sqlstmtins),
(ub4) OCI_NTV_SYNTAX, (ub4) OCI_DEFAULT))
{
(void) printf("FAILED: OCIStmtPrepare() insert\n");
report_error(errhp);
return OCI_ERROR;
}
if(OCIBindByPos(stmthp, &bndhp, errhp, (ub4)1, (dvoid *)&idcol,
(sb4)sizeof(idcol), SQLT_INT, (dvoid *)0,
(ub2 *)0, (ub2 *)0, (ub4)0, (ub4 *)0, (ub4)OCI_DEFAULT))
{
(void) printf("FAILED: OCIBindByPos() \n");
report_error(errhp);
return OCI_ERROR;
} if (OCIStmtExecute(svchp, stmthp, errhp, (ub4)1, (ub4) 0,
(CONST OCISnapshot*) 0, (OCISnapshot*) 0,
(ub4) OCI_DEFAULT))
{
(void) printf("FAILED: OCIStmtExecute() insert\n");
report_error(errhp);
return OCI_ERROR;
} /* Prepare the statement */
if (OCIStmtPrepare(stmthp, errhp, sqlstmtsel, (ub4)strlen((char *)sqlstmtsel),
(ub4) OCI_NTV_SYNTAX, (ub4) OCI_DEFAULT))
{
(void) printf("FAILED: OCIStmtPrepare() read\n");
report_error(errhp);
return OCI_ERROR;
} idcol = 1;
if(OCIBindByPos(stmthp, &bndhp, errhp, (ub4)1, (dvoid *)&idcol,
(sb4)sizeof(idcol), SQLT_INT, (dvoid *)0,
(ub2 *)0, (ub2 *)0, (ub4)0, (ub4 *)0, (ub4)OCI_DEFAULT))
{
(void) printf("FAILED: OCIBindByPos() insert\n");
report_error(errhp);
return OCI_ERROR;
}
if(OCIDefineByPos(stmthp, &dfnhp, errhp, (ub4)1, (dvoid *)&pt_blob,
(sb4) -1, (ub2)SQLT_BLOB, (dvoid *) 0, (ub2 *)0,
(ub2 *)0, (ub4) OCI_DEFAULT))
{
(void) printf("FAILED: OCIDefineByPos() insert\n");
report_error(errhp);
return OCI_ERROR;
}
if (OCIStmtExecute(svchp, stmthp, errhp, (ub4)0, (ub4) 0,
(CONST OCISnapshot*) 0, (OCISnapshot*) 0,
(ub4) OCI_DEFAULT))
{
(void) printf("FAILED: OCIStmtExecute() read\n");
report_error(errhp);
return OCI_ERROR;
}
printf("Here. \n"); amt = strlen(buf);
if(OCILobWrite(svchp, errhp, pt_blob, &amt, offset, (dvoid *) buf,
(ub4)strlen(buf), OCI_ONE_PIECE, (dvoid *)0,
(sb4 (*)(dvoid *, dvoid *, ub4 *, ub1 *)) 0,
(ub2) 0, (ub1) SQLCS_IMPLICIT))
{
report_error(errhp);
(void) printf("FAILED: OCILobWrite()\n");
return OCI_ERROR;
} return OCI_SUCCESS;
}