Oracle8.1.6图象文件保存问题,哪位大侠救救我!(300分)

  • 主题发起人 主题发起人 xiecc
  • 开始时间 开始时间
X

xiecc

Unregistered / Unconfirmed
GUEST, unregistred user!
Oracle8.1.6 Blob字段保存图象总是出错,我已经把能用的方法全用了

方法一:
with query1 do
begin
Edit;
ImagePic.Picture.SaveToFile(sPicFileName);
TBlobField(FieldByName('Picture')).LoadFromFile(sPicFileName);
Post;
end;

方法二:
Query.Close;
Query.SQL.Clear;
Query.SQL.Add('INSERT myimages VALUE(:filename,EMPTY_BLOB())');
Query.ParamByName('filename').AsString := DBEdit1.Text;
Query.ExecSQL;
Query.SQL->Clear;
Query.SQL->Add('UPDATE myimages SET images=:pic WHERE filename=:filename');
Query.ParamByName("filename").AsString := DBEdit1.Text;
Query.ParamByName('pic').LoadFromStream(MyStream,ftOraBlob);;
Query.ExecSQL;

方法三:
procedure saveimage;
Var
BlobStream:TBlobStream;
JpegImage:TJpegImage;
begin
try
with Frm_DossierView.query1 do
try
JpegImage:=TJpegImage.Create;
BlobStream:=TBlobStream.Create(TBlobField(FieldByName('WSNR')),bmWrite);
BlobStream.Position:=0;
// BlobStream.Truncate;
JpegImage:=TJpegImage(Frm_DossierView.image1.Picture.Graphic);
JpegImage.SaveToStream(BlobStream);
finally
if Not Assigned(BlobStream) then BlobStream.Free;
if Not Assigned(JpegImage) then JpegImage.Free;
end;
except
end;
end;


读取

procedure loadimage;
Var
BlobStream:TBlobStream;
JpegImage:TJpegImage;
begin
try
BlobStream:=TBlobStream.Create(TblobField(Frm_DossierView.Query1.FieldByName('WSNR')),bmRead);
if BlobStream.Size>0 then
begin
JpegImage:=TJpegImage.Create;
JpegImage.LoadFromStream(BlobStream);
Frm_DossierView.Image1.Picture.Assign(JpegImage);
end
else
Frm_DossierView.Image1.Picture:=nil;
Finally
if Not Assigned(BlobStream) then BlobStream.Free;
if Not Assigned(JpegImage) then JpegImage.Free;
End;
end;

可最后返回的错误都是一样的:
“General SQL error.ORA-22275:指定LOB定位器无效”
以前用MS SQL Server从来不曾出过这种事,哪位大侠快救救我吧!

 
300分还没人答?
 
我也遇到过同样的问题, 但我把表重新建一下就好了. 至今不知道是什么原因,
估计是BDE的问题.
 
把保存图象的字段的类型改成'long raw',试一试,应该可以。(用不着流)
 
你用ADO连接,选Oracle ODBC Driver,直接用DBImage,不会遇到任何问题,也不用写什么其它
的代码.若你的图片不是BMP,则还需要自己转一下.你可以先试试BMP,成功后再试基它类型.
最好不要用Long Raw类型,这种类型一个表中只能有一个,不像BLOB可以有多个.
 
bde的话要打补丁的,建议用blob ,long已经被oracle淘汰了
 
这么久早应该搞定了吧!
 
TO:goingknife
把保存图象的字段的类型为'long raw',不用流?
如何实现,可否细说,愿闻其祥。

EMAIL:117924@163.com

 
procedure TForm1.Button1Click(Sender: TObject);
var
FileStream:TFileStream;// 将入的AVI文件
BlobStream:TBlobStream;//保存的BLOB流
begin
Application.ProcessMessages;
Button1.Enabled:=false;
Button2.Enabled:=false;
if not OpenDialog1.Execute then
exit;
FileStream:=TFileStream.Create(OpenDialog1.FileName,fmOpenRead);
Table1.insert;
//为Table1AVI字段创建一个BLOBSTREAM
BlobStream:=TBlobStream.Create(Table1AVI,bmReadWrite);
//移动到STREAM的首位
BlobStream.Seek(0,soFromBeginning);
//清空数据流
BlobStream.Truncate;
//将FILESTREAM的内容拷贝到BLOBSTREAM
BlobStream.CopyFrom(FileStream,FileStream.size);
//释放流
FileStream.Free;
BlobStream.Free;
//添加记录
Table1.Post;
//使buttons可用
Button1.Enabled:=true;
Button2.Enabled:=true;
end;

procedure TForm1.Button2Click(Sender: TObject);
var
FileStream:TFileStream;
BlobStream:TBlobStream;
begin
//为AVI字段创建BLOB数据流
BlobStream:=TBlobStream.Create(Table1AVI,bmRead);
if BlobStream.Size=0 then
begin
BlobStream.Free;
Exit;
end;

// 关闭media player
MediaPlayer1.Close;
//重值文件名
MediaPlayer1.FileName:='';
//刷新显示窗口
MediaPlayer1.Display:=Panel1;
Panel1.Refresh;
//创建前删除同名的临时文件
if FileName<>'' then
DeleteFile(FileName);
//设置临时文件名
FileName:=GetTemporaryFileName;
//为临时文件创建文件流
filename:=changefileext(filename,'.avi');
FileStream:=TFileStream.Create(FileName,fmCreate or fmOpenWrite);
//拷贝BLOB到临时文件
FileStream.CopyFrom(BlobStream,BlobStream.Size);
//释放流
FileStream.Free;
BlobStream.Free;
//设置Media Player播放AVI文件
MediaPlayer1.DisplayRect:=panel1.ClientRect;
MediaPlayer1.FileName:=filename;
MediaPlayer1.Open;
MediaPlayer1.Play;
end;
 
BDE 设置 BLOB SIZE 512
不会再有问题
-------但大图只能存一部分。

 
后退
顶部