在程序中壓縮sql server2000的數(shù)據(jù)庫備份文件的代碼
更新時(shí)間:2007年03月18日 00:00:00 作者:
怎樣壓縮sql server2000的數(shù)據(jù)庫備份文件,像rar一樣?小弟有一7m的sql server2000
數(shù)據(jù)庫備份文件,在程序中怎樣壓縮啊?
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('壓縮完畢!'); }
這是一段壓縮圖片的代碼,壓縮文件原理相同,只需稍做改動(dòng)即可。
var
mss: TMemoryStream;
zip: TDeCompressionStream;
zip1: TCompressionStream;
fs : TFileStream;
fBuf: Array[0..16383] of Byte;
flen: Integer;
//從數(shù)據(jù)庫中取出圖片
//...寫出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中的圖片保存到數(shù)據(jù)庫
//...寫出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;
//保存到數(shù)據(jù)庫
TBlobField(Que.FieldByName('pic')).LoadFromStream(mss);
Que.UpdateBatch();
//...
finally
zip1.Free;
end;
finally
fs.Free;
mss.Free;
end;
數(shù)據(jù)庫備份文件,在程序中怎樣壓縮啊?
復(fù)制代碼 代碼如下:
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('壓縮完畢!'); }
這是一段壓縮圖片的代碼,壓縮文件原理相同,只需稍做改動(dòng)即可。
復(fù)制代碼 代碼如下:
var
mss: TMemoryStream;
zip: TDeCompressionStream;
zip1: TCompressionStream;
fs : TFileStream;
fBuf: Array[0..16383] of Byte;
flen: Integer;
//從數(shù)據(jù)庫中取出圖片
//...寫出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中的圖片保存到數(shù)據(jù)庫
//...寫出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;
//保存到數(shù)據(jù)庫
TBlobField(Que.FieldByName('pic')).LoadFromStream(mss);
Que.UpdateBatch();
//...
finally
zip1.Free;
end;
finally
fs.Free;
mss.Free;
end;
您可能感興趣的文章:
- sql server通過腳本進(jìn)行數(shù)據(jù)庫壓縮全備份的方法【推薦】
- sql server 2008 壓縮備份數(shù)據(jù)庫(20g)
- mysql數(shù)據(jù)庫備份命令分享(mysql壓縮數(shù)據(jù)庫備份)
- sqlserver 數(shù)據(jù)庫壓縮與數(shù)據(jù)庫日志(ldf)壓縮方法分享
- 自動(dòng)備份mssql server數(shù)據(jù)庫并壓縮的批處理腳本
- DBCC SHRINKDATABASEMS SQL數(shù)據(jù)庫日志壓縮方法
- ms SQL server數(shù)據(jù)庫備份、壓縮與SQL數(shù)據(jù)庫數(shù)據(jù)處理的方法
- MS SQL SERVER 數(shù)據(jù)庫日志壓縮方法與代碼
- SQL Server 2000/2005/2008刪除或壓縮數(shù)據(jù)庫日志的方法
相關(guān)文章
sql根據(jù)表名獲取字段及對(duì)應(yīng)說明
sql根據(jù)表名獲取字段及對(duì)應(yīng)說明,需要的朋友可以參考下。2010-09-09格式導(dǎo)致的Excel導(dǎo)入sql出現(xiàn)異常的解決方法
因?yàn)镋xcel導(dǎo)入到sql的事兒,今天折騰了大半天。2009-03-03SQL?Server日志清理3種實(shí)現(xiàn)方式
這篇文章主要給大家介紹了關(guān)于SQL?Server日志清理3種實(shí)現(xiàn)方式的相關(guān)資料,在數(shù)據(jù)庫使用很久后日志文件會(huì)累計(jì)的越來越大,如果硬盤空間不足可能會(huì)導(dǎo)致宕機(jī),需要的朋友可以參考下2023-09-09動(dòng)態(tài)給表添加刪除字段并同時(shí)修改它的插入更新存儲(chǔ)過程
有一個(gè)表,用戶需要在后臺(tái)操作它,希望能對(duì)它動(dòng)態(tài)進(jìn)行添加刪除字段2011-11-11自動(dòng)定時(shí)備份sqlserver數(shù)據(jù)庫的方法
下面是我已經(jīng)證實(shí)可用的自動(dòng)備份的方法.需要的朋友可以參考下。2011-11-11更改SQL Server更改當(dāng)前數(shù)據(jù)庫的所有者:sp_changedbowner
更改SQL Server更改當(dāng)前數(shù)據(jù)庫的所有者:sp_changedbowner...2007-02-02