偶
偶尔幽默
Unregistered / Unconfirmed
GUEST, unregistred user!
数据库中两张表,表1(文章)和表2(文章内容),表2是以二进制流分段存储的,以32K为分界点,现用流读取分段存储的数据合并成文件,合并后的文件大小是对的,但打开文件是乱码或无法打开。文件的类型有多种,DOC,PPT,PDF等。
大家看下代码有没有问题:
function Tf_main.transEfile(contentId,fileName,pid:string): string;
var
efileTitle,efilePath:string;
a: TFileStream;
b:TMemoryStream;
begin
with self.qry_content do
begin
Close;
SQL.Clear;
SQL.Add(format('select CONTENT,SPLITNO,text from EB_ARTICLE_CONTENT_BB '
+'where ARTICLE_CONTENT_ID =''%s'''
+' order by SPLITNO',[trim(contentid)]));
Open;
efileTitle:= fileName;
efilePath:= ExtractFilePath(ParamStr(0))+'/temp/';
a := TFileStream.Create(efilePath+efileTitle, fmCreate);
First;
while not qry_content.Eof do
begin
try
b:= TMemoryStream.Create;
TBlobField(FieldbyName('content')).SaveToStream(b);
try
b.Position :=0;
a.Seek(0,soFromEnd); //
a.CopyFrom(b,0);
finally
FreeAndNil(b);
end;
except
Break;
end;
qry_content.Next;
end;
end;
end;
大家看下代码有没有问题:
function Tf_main.transEfile(contentId,fileName,pid:string): string;
var
efileTitle,efilePath:string;
a: TFileStream;
b:TMemoryStream;
begin
with self.qry_content do
begin
Close;
SQL.Clear;
SQL.Add(format('select CONTENT,SPLITNO,text from EB_ARTICLE_CONTENT_BB '
+'where ARTICLE_CONTENT_ID =''%s'''
+' order by SPLITNO',[trim(contentid)]));
Open;
efileTitle:= fileName;
efilePath:= ExtractFilePath(ParamStr(0))+'/temp/';
a := TFileStream.Create(efilePath+efileTitle, fmCreate);
First;
while not qry_content.Eof do
begin
try
b:= TMemoryStream.Create;
TBlobField(FieldbyName('content')).SaveToStream(b);
try
b.Position :=0;
a.Seek(0,soFromEnd); //
a.CopyFrom(b,0);
finally
FreeAndNil(b);
end;
except
Break;
end;
qry_content.Next;
end;
end;
end;