高分请教:Oracle数据库的blob字段中的wav文件的存入和提取(附代码)?(200分)

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

xuxincheng

Unregistered / Unconfirmed
GUEST, unregistred user!
Query1WAVECONTENT为TblobField;

procedure TForm1.Button2Click(Sender: TObject);
var
MemSize: Integer;
Buffer: PChar;
FileStream: TFileStream;
BlobStream: TBlobStream;
str:string;
begin
filename:=getcurrentdir+'/abc2.wav';
with Query1 do
begin
open;
insert;
FieldbyName('WAVEID').Asinteger:=31;
FieldbyName('planid').asinteger:=55;
FieldbyName('RECORDDATE').asdatetime:=now;
FileStream:=Tfilestream.create(filename,fmopenread);
BlobStream:= TBlobStream.Create(Query1WAVECONTENT, bmWrite);
MemSize := FileStream.Size;
showmessage(inttostr(MemSize));
Buffer := AllocMem(MemSize);
try
BlobStream.Seek(0, soFromBeginning);
FileStream.Read(Buffer^,MemSize);
BlobStream.Write(Buffer^,MemSize);
finally
FileStream.Free;
BlobStream.Free;
end;
post;
applyupdates;
showmessage('导入成功!');
end;
end;
//导入时提示信息为'指定的lob定位器无效',但将Query换成Table就好了

procedure TForm1.Button3Click(Sender: TObject);
var
BlobStream:TBlobStream;
memorystream:tmemorystream;
begin

Query1.Close;
Query1.sql.text:='select * from ABC_TEMP where waveid=26';
Query1.Open;
if Query1.IsEmpty then
begin
showmessage('没有找到匹配的数据记录');
EXit;
end;
MemoryStream:=Tmemorystream.Create;
BlobStream:=TBlobStream.Create(Query1WAVECONTENT,bmRead);
try
memorystream.SetSize(BlobStream.Size);
memorystream.LoadFromStream(BlobStream);
// memorystream.Seek(0, soFromBeginning);
memorystream.SaveToFile(GetCurrentDir+'/dbn.wav');
finally
memorystream.Free;
end;

showmessage('输出成功!');

if FileExists(GetCurrentDir+'/dbn.wav') then
sndplaysound(pchar(GetCurrentDir+'/dbn.wav'),SND_ASYNC);

end;
//导出是没有报错,但dbn.wav文件只有32768个字节,
如何使声音文件正常输入输出呢?
 
2:32K可能是由于BDE设置造成的,你改改那个地方,可能会好。
1:你可以换种方法
 
To:天真
导出的问题在我将bde当前数据库的blob size改为5000后工作正常了,100分归你了.
你说的另外一种方法是如何实现的呢?
 
try
memorystream.SetSize(BlobStream.Size);
memorystream.LoadFromStream(BlobStream);
// memorystream.Seek(0, soFromBeginning);
memorystream.SaveToFile(GetCurrentDir+'/dbn.wav');
finally
memorystream.Free;
end;
上面所有的的改成一行试试:
memorystream.LoadFromStream(BlobStream);


另外看看下面的有没有必要修改:
Buffer := AllocMem(MemSize);
try
BlobStream.Seek(0, soFromBeginning);
FileStream.Read(Buffer^,MemSize);
BlobStream.Write(Buffer^,MemSize);
finally
改成:
fileStream.Writetostream(BlobStream);
 
To:jsxjd
TFileStream没有Writetostream这个方法.
 
对不起,没有就不改。
我主要的意思是尽量简洁。
另外,注意参数是否正确。
 
BlobStream.CopyFrom(
 
天真:
能说详细点吗?
 
多人接受答案了。
 
后退
顶部