O
oiget
Unregistered / Unconfirmed
GUEST, unregistred user!
三层中(Midas控件),要把一个.exe文件保存到Oracle表的Blob字段中,以下代码应该没什么问题的了,测试通过,而且保存文本文件的流都成功!但保存exe等文件,无论文件大小,保存到数据库后字节数都要比源文件小!!难道真的是ClientDataSet[MIDAS]的Bug么,可以解决的么?非常感谢!!!【开发版本Delphi7】代码:
代码:
procedure TF_UpGrade.UpLoadPro(FileName: string); const BufSize = $F000; var Counter, N: Integer; Buffer: PAnsiChar; FieldStrm: TStream; ExeFileStream:TFileStream; size_tmp: Double; Fname,gv: string; begin if Filename='' then Fname:=extractFileName(application.ExeName) else Fname:=FileName; gv:=GetVersion(Fname,true);//取得exe文件的版本号 //with qry do begin qry.Open; //qry为clientdataset qry.Edit; try ExeFileStream:=TFileStream.Create(Fname,fmopenRead); //打开文件 FieldStrm := qry.CreateBlobStream(qry.FieldByName('PC'), bmWrite); GetMem(Buffer, BufSize); try Counter := ExeFileStream.Size; size_tmp := ExeFileStream.Size; ProgressBar1.Position := 0; ProgressBar1.Max := Counter div BufSize; //每次上传文件流为61440 byte = $F000 while Counter <> 0 do begin if Counter > BufSize then N := BufSize else N := Counter; ExeFileStream.ReadBuffer(Buffer^, N); FieldStrm.WriteBuffer(Buffer^, N); Dec(Counter, N); ProgressBar1.Position := ProgressBar1.Position + 1; Application.ProcessMessages; end; cmd.Params.Clear; cmd.CommandText:='update upGrade set PC=:spc,PV=:spv where Rtrim(pname) ='+quotedStr(Fname); cmd.Params.ParamByName('spc').LoadFromStream(FieldStrm,ftBlob); //FieldStrm(二进制流)被保存到数据库后就都变小了,晕啊!!! cmd.Params.ParamByName('spv').Value:=gv; cmd.ExecSQL; finally FreeMem(Buffer, BufSize); FieldStrm.Free; end; Application.MessageBox('新版本程序上传至服务器成功!','提示',MB_OK+MB_IconInformation); finally ProgressBar1.Position := ProgressBar1.Max; ExeFileStream.Free; end; end; end;