//就是把整个WORD文件保存进去是吧?
//不只是WORD,其他所有的文件都适用的。。。
//保存
procedure SaveWordToSQL;
var
MyStream: TMemoryStream;
FileStream: TFileStream; // 将写入的文件
size: Cardinal;
iPosition: Cardinal;
blocksize:Cardinal;
begin
blocksize:=1024; //1M
FileStream:=TFileStream.Create(OpenDialog1.FileName,fmOpenRead);
MyStream:=TMemoryStream.Create();
MyStream.Position:=0;
size:=FileStream.Size;
iPosition := 0;
ADOQ_input.Close;
ADOQ_input.SQL.Clear;
ADOQ_input.SQL.Add('update file_ver set file_ver=:ID where uid=''1''');
while iPosition<size do
begin
application.ProcessMessages;
FileStream.Position:=iPosition;
if (iPosition+BlockSize)<=size then
MyStream.CopyFrom(FileStream,BlockSize)
else
MyStream.CopyFrom(FileStream,Size-iPosition);
iPosition:=iPosition+BlockSize;
MyStream.Position:=iPosition;
end;
ADOQ_input.Parameters.ParamByName('ID').LoadFromStream(MyStream,ftTypedBinary);
ADOQ_input.ExecSQL;
FileStream.Free;
MyStream.Free;
showmessage('数据导入成功');
end;
//读取
procedure LoadWordFromSQL;
var
FileName:Olevariant;
verfield:string;
MyStream,FileStream:TMemoryStream;
filen:string;
path:string;
size: Cardinal;
iPosition: Cardinal;
blocksize:Cardinal;
begin
blocksize:=1024; //1M
MyStream:=TMemoryStream.Create();
FileStream:=TMemoryStream.Create();
ADOQ_file.Close;
ADOQ_file.SQL.Clear;
ADOQ_file.SQL.Add('select file_ver from file_ver where uid=''1''');
ADOQ_file.Open;
ADOQ_file.ExecSQL;
if ADOQ_file.RecordCount<>0 then
begin
TBlobField(ADOQ_file.FieldByName('file_ver')).SaveToStream(FileStream);
FileStream.Position:=0;
size:=FileStream.Size;
iPosition := 0;
while iPosition<size do
begin
application.ProcessMessages;
FileStream.Position:=iPosition;
if (iPosition+BlockSize)<=size then
MyStream.CopyFrom(FileStream,BlockSize)
else
MyStream.CopyFrom(FileStream,Size-iPosition);
iPosition:=iPosition+BlockSize;
MyStream.Position:=iPosition;
end;
MyStream.SaveToFile(FileName);
end;
MyStream.Free;
FileStream.Free;
end;
//给分,HOHO...