在程序中压缩sql server2000的数据库备份文件的代码
程序员文章站
2023-08-23 13:09:12
怎样压缩sql server2000的数据库备份文件,像rar一样?小弟有一7m的sql server2000 数据库备份文件,在程序中怎样压缩啊? 复...
怎样压缩sql server2000的数据库备份文件,像rar一样?小弟有一7m的sql server2000
数据库备份文件,在程序中怎样压缩啊?
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;
数据库备份文件,在程序中怎样压缩啊?
复制代码 代码如下:
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;
上一篇: 访问和更改关系数据,使用MSSQL外联接
下一篇: 媳妇躺在床上