一个表中有两个字段image1和image2都是blob类型,用来存取图像,保存可以,但是在显示时,只能读出第一个字段image1,为什么呢??????????
var
mStream1,mStream2: TMemoryStream;
Graphic1,Graphic2 : TOleGraphic;
begin
try
if (ADOQuery.Active) then ADOQuery.Active := false;
ADOQuery.SQL.Clear;
ADOQuery.SQL.Add('select image1,title1,image2,title2 from image_test'); ADOQuery.Open;
label1.Caption := ADOQuery.fieldByName('title1').AsString;
label2.Caption := ADOQuery.fieldByName('title2').AsString;
mStream1 := TMemoryStream.Create;
mStream2 := TMemoryStream.Create;
Graphic1 := TOleGraphic.Create;
Graphic2 := TOleGraphic.Create;
TBlobField(ADOQuery.FieldByName('image1')).SaveToStream(mStream1);
TBlobField(ADOQuery.FieldByName('image2')).SaveToStream(mStream2);
mStream1.Position :=0;
mStream2.Position :=0;
Graphic1.LoadFromStream(MStream1);
Graphic2.LoadFromStream(MStream2);
Image1.Picture.Graphic := Graphic1;
Image2.Picture.Graphic := Graphic2;
Graphic1.Free;
mStream1.Free;
Graphic2.Free;
mStream2.Free;
except
end;
end;
var
mStream1,mStream2: TMemoryStream;
Graphic1,Graphic2 : TOleGraphic;
begin
try
if (ADOQuery.Active) then ADOQuery.Active := false;
ADOQuery.SQL.Clear;
ADOQuery.SQL.Add('select image1,title1,image2,title2 from image_test'); ADOQuery.Open;
label1.Caption := ADOQuery.fieldByName('title1').AsString;
label2.Caption := ADOQuery.fieldByName('title2').AsString;
mStream1 := TMemoryStream.Create;
mStream2 := TMemoryStream.Create;
Graphic1 := TOleGraphic.Create;
Graphic2 := TOleGraphic.Create;
TBlobField(ADOQuery.FieldByName('image1')).SaveToStream(mStream1);
TBlobField(ADOQuery.FieldByName('image2')).SaveToStream(mStream2);
mStream1.Position :=0;
mStream2.Position :=0;
Graphic1.LoadFromStream(MStream1);
Graphic2.LoadFromStream(MStream2);
Image1.Picture.Graphic := Graphic1;
Image2.Picture.Graphic := Graphic2;
Graphic1.Free;
mStream1.Free;
Graphic2.Free;
mStream2.Free;
except
end;
end;
可能的情况是,image2的内容不是一个合法的 TOleGraphic,把错误信息贴出来看一下
Project PSaveImg.exe raised exception class EOleSysError with Message'灾难性故障'. Process stopped Use Step or Run to continue.
var
testStream1,testStream2:TMemoryStream;
begin
try
testStream1 := TMemoryStream.Create;
testStream2 := TMemoryStream.Create;
if Image1.Picture.Graphic <> nil then
Image1.Picture.Graphic.SaveToStream(testStream1);
if Image2.Picture.Graphic <> nil then
Image2.Picture.Graphic.SaveToStream(testStream2);
adoquery.Close;
adoquery.SQL.Clear;
adoQuery.SQL.Add('Insert into image_test (id,image1,title1,image2,title2)'+
' values (1,:photo1,''图片1'',:photo2,''图片2'')');
//adoquery1.Parameters.ParamByName('id').Value := '004';
adoQuery.Parameters.ParamByName('photo1').LoadFromStream(testStream1,ftBlob);
adoQuery.Parameters.ParamByName('photo2').LoadFromStream(testStream2,ftBlob);
adoquery.ExecSQL;
finally
testStream1.Free;
testStream2.Free;
end;
end;
var
mStream1,mStream2: TADOblobStream;
Graphic1,Graphic2 : TOleGraphic;
begin
try
if (ADOQuery.Active) then ADOQuery.Active := false;
ADOQuery.SQL.Clear;
ADOQuery.SQL.Add('select image1,title1,image2,title2 from image_test'); ADOQuery.Open;
label1.Caption := ADOQuery.fieldByName('title1').AsString;
label2.Caption := ADOQuery.fieldByName('title2').AsString;
mStream1 := TADOBlobStream.Create(TBlobField(ADOQuery.Fields.FieldByName('image1')), bmRead);
mStream2 := TADOBlobStream.Create(TBlobField(ADOQuery.Fields.FieldByName('image2')), bmRead);
//TBlobField(ADOQuery.FieldByName('image1')).SaveToStream(mStream1);
//TBlobField(ADOQuery.FieldByName('image2')).SaveToStream(mStream2);
mStream1.Position :=0;
mStream2.Position :=0;
Graphic1 := TOleGraphic.Create;
Graphic2 := TOleGraphic.Create;
Graphic1.LoadFromStream(MStream1);
Graphic2.LoadFromStream(MStream2);
Image1.Picture.Graphic := Graphic1;
Image2.Picture.Graphic := Graphic2;
Graphic1.Free;
mStream1.Free;
Graphic2.Free;
mStream2.Free;
except
end;
end;
如果真的是两个图像字段完全一样,读出无问题
update image_test set image2=image1;
改用ODAC,报ORA-01026 multiple buffers of size > 4000 in the bind list错,google一下,说是因客户端版本低引起的(我用的是ora816连ora805),有的说与数据引擎有关
看来,oracle中有两个图像字段的确有问题
/
1.建表
CREATE TABLE TEST
(
A1 BLOB,
A2 BLOB
)
2.建存储过程序
CREATE OR REPLACE procedure
testp(pa1 out blob,pa2 out blob)
is
begin
insert into test values(empty_blob(),empty_blob())
returning a1,a2 into pa1,pa2;
end;
/
3.用ODAC插入图片
rocedure TForm1.Button2Click(Sender: TObject);
begin
with OraStoredProc1 do
begin
StoredProcName:='TESTP';
params.Add;
params.Add;
params.Items[0].Name:='aa1';
params.Items[1].Name:='aa2';
params.Items[0].DataType:=ftorablob;
params.Items[1].DataType:=ftorablob;
params.Items[0].ParamType :=ptinput;
params.Items[1].ParamType :=ptinput;
params.Items[0].AsOraBlob.LoadFromFile('e:\temp\t.bmp');
params.Items[1].AsOraBlob.LoadFromFile('e:\temp\t.bmp');
execproc;
end;
end;
不过用ADO没成功(ADO的存储过程控件对oracle有些问题)
with Query1 do
begin
sql.Text:='insert into test values(:pa1,:pa2)';
ParamByName('pa1').LoadFromFile('e:\temp\t.bmp',ftblob);
ParamByName('pa2').LoadFromFile('e:\temp\t.bmp',ftblob);
execsql;
end;
在我机上成功
procedure TForm1.Button1Click(Sender: TObject);
var
t:dword;
begin
t:=gettickcount;
Database1.StartTransaction;
with Query1 do
begin
sql.Text:='insert into test values(empty_blob(),empty_blob()) returning a1,a2 into :a1,:a2';
Params[0].LoadFromFile('e:\temp\t.bmp',ftorablob);
Params[1].LoadFromFile('e:\temp\t.bmp',ftorablob);
execsql;
end;
Database1.Commit;
edit1.Text:=inttostr(gettickcount-t);
end;procedure TForm1.Button2Click(Sender: TObject);
var
t:dword;
begin
t:=gettickcount;
OraSession1.StartTransaction;
with OraQuery1 do
begin
Params.Clear;
sql.Text:='insert into test values(empty_blob(),empty_blob()) returning a1,a2 into :a1,:a2'; Params[0].ParamType:=ptinput;
Params[1].ParamType:=ptinput;
Params[0].LoadFromFile('e:\temp\t.bmp',ftorablob);
Params[1].LoadFromFile('e:\temp\t.bmp',ftorablob);
execsql;
end;
OraSession1.Commit;
edit2.Text:=inttostr(gettickcount-t);
end;procedure TForm1.Button3Click(Sender: TObject);
var
t:dword;
begin
t:=gettickcount;with Query2 do
begin
sql.Text:='insert into test values(:a1,:a2)'; Params[0].LoadFromFile('e:\temp\t.bmp',ftblob);
Params[1].LoadFromFile('e:\temp\t.bmp',ftblob);
execsql;
end;
edit3.Text:=inttostr(gettickcount-t);
end;procedure TForm1.Button4Click(Sender: TObject);
var
t:dword;
TD: TTransactionDesc;begin
t:=gettickcount;
TD.TransactionID := 1;
TD.IsolationLevel := xilREADCOMMITTED;
SQLConnection1.StartTransaction(TD);
with SQLQuery1 do
begin
sql.Text:='insert into test values(empty_blob(),empty_blob()) returning a1,a2 into :a1,:a2';
Params[0].LoadFromFile('e:\temp\t.bmp',ftorablob);
Params[1].LoadFromFile('e:\temp\t.bmp',ftorablob);
execsql;
end;edit4.Text:=inttostr(gettickcount-t);
SQLConnection1.Commit(TD);
end;procedure TForm1.Button5Click(Sender: TObject);
var
t:dword;
begin
t:=gettickcount;with ADOQuery1 do
begin
sql.Text:='insert into test values(:a1,:a2)'; parameters[0].LoadFromFile('e:\temp\t.bmp',ftblob);
parameters[1].LoadFromFile('e:\temp\t.bmp',ftblob);
execsql;
end;
edit5.Text:=inttostr(gettickcount-t);end;其中odbc最快,ADO+ODBC最慢,如果你一定要用ado,就可以用ado+odbc方式
(建一个odbc,ADO用MSDASQL.1来连该odbc)
1.BDE
2.ODAC
3.ODBC
4.DBX
5.ADO+ODBC
热心,有责任感。好淫。。问题都说了,路过。
我建了个表,CREATE TABLE "PALM"."IMAGE_TEST" ("ID" NUMBER, "IMAGE1" BLOB, "TITLE1" VARCHAR2(12 byte), "IMAGE2" BLOB, "TITLE2" VARCHAR2(12
byte))
如果用odbc来存取,也不行,如果建的表为create table (image1 blob, image1 blob),则用odbc,bde,ado都可以如果建的表为create table (id number, image blob),则用odbc,bde,ado也可以,
procedure TForm1.Button1Click(Sender: TObject);
begin
with Query1 do
begin
sql.Text:='insert into IMAGE_TEST values(1,:a1,''test1'',:a2,''test2'')';
Params[0].LoadFromFile('e:\temp\t.bmp',ftblob);
Params[1].LoadFromFile('e:\temp\t.bmp',ftblob);
execsql;
end;
1.升级你的MDAC
2.一定要用oracle odbc driver,用m$的肯定不行