在程式中壓縮sql server2000的Database Backup檔案的代碼

來源:互聯網
上載者:User

怎樣壓縮sql server2000的Database Backup檔案,像rar一樣?小弟有一7m的sql server2000
Database Backup檔案,在程式中怎樣壓縮啊? 複製代碼 代碼如下:procedure TForm1.Button2Click(Sender: TObject);
var
SHExecInfo: SHELLEXECUTEINFO;
begin
SHExecInfo.cbSize := sizeof(SHELLEXECUTEINFO);
SHExecInfo.fMask := SEE_MASK_NOCLOSEPROCESS;
SHExecInfo.Wnd := Handle;
SHExecInfo.lpVerb := nil;
SHExecInfo.lpFile := 'WinRAR.exe';
SHExecInfo.lpParameters := 'a e:\qwqw.rar e:\qwqw';
SHExecInfo.lpDirectory := nil;
SHExecInfo.nShow := SW_SHOW;
SHExecInfo.hInstApp := Handle;
ShellExecuteEx(@SHExecInfo);
WaitForSingleObject(SHExecInfo.hProcess, INFINITE);
CloseHandle(SHExecInfo.hProcess);
ShellExecute(application.MainForm.Handle,'open','winrar.exe',PChar('a e:\zqzq.rar e:\zqzq'),'',SW_show);
ShowMessage('壓縮完畢!'); }

這是一段壓縮圖片的代碼,壓縮檔原理相同,只需稍做改動即可。 複製代碼 代碼如下:var
mss: TMemoryStream;
zip: TDeCompressionStream;
zip1: TCompressionStream;
fs : TFileStream;
fBuf: Array[0..16383] of Byte;
flen: Integer;
//從資料庫中取出圖片
//...寫出SQL語句以取得有圖片的記錄,此處從略
mss := TMemoryStream.Create;
fs := TFileStream.Create('filename.jpg',fmCreate or fmOpenWrite);
try
TBlobField(Que.FieldByName('pic')).SaveToStream(mss);
zip := TDeCompressionStream.Create(fs);
try
flen := zip.Read(fbuf, SizeOf(fBuf));
while flen > 0 do begin
fs.Write(fbuf, flen);
flen := zip.Read(fbuf, SizeOf(fBuf));
end;
finally
FreeAndNil(zip);
end;
finally
mss.Free;
fs.Free;
end;
//將檔案filename.jpg中的圖片儲存到資料庫
//...寫出SQL語句,開啟Que,並定位到要儲存圖片的記錄,此處從略
fs := TFileStream.Create('filename.jpg',fmOpenRead);
mss := TMemoryStream.Create;
try
zip1 := TCompressionStream.Create(clDefault,mss);
try
flen := fs.Read(fbuf, SizeOf(fBuf));
while flen > 0 do begin
zip1.Write(fbuf, flen);
flen := fs.Read(fbuf, SizeOf(fBuf));
end;
//儲存到資料庫
TBlobField(Que.FieldByName('pic')).LoadFromStream(mss);
Que.UpdateBatch();
//...
finally
zip1.Free;
end;
finally
fs.Free;
mss.Free;
end;

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.