📄 dbbackcp.pas
字号:
//------------------------------------------------------------
// 作者:曾庆顺
// 模块:数据库备份窗口
// 时间:2002.09.17
// 功能介绍:
//-----------------------------------------------------------
unit DbBackcp;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls,registry, Buttons, ExtCtrls,FileCtrl, Db, DBTables;
type
TDbBackupFrm = class(TForm)
Panel1: TPanel;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label7: TLabel;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
Label4: TLabel;
Edit_userid: TEdit;
Edit_Pass: TEdit;
Edit_string: TEdit;
Query1: TQuery;
Databasedh: TDatabase;
procedure FormCreate(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
FDir:string;
//得到ORACLE 的系统路径
Function GetOracleDir:string;
//得到数据库服务器日期
Function GetDbServerDate(DBName:string):string;overload;
public
{ Public declarations }
end;
var
DbBackupFrm: TDbBackupFrm;
implementation
{$R *.DFM}
Function TDbBackupFrm.GetOracleDir:string;
var
Reg: TRegistry;
begin
Reg := TRegistry.Create;
result:='';
try
Reg.RootKey := HKEY_LOCAL_MACHINE;
if Reg.OpenKey('\SOFTWARE\ORACLE', True) then
result:=Reg.ReadString('ORACLE_HOME');
finally
Reg.CloseKey;
Reg.Free;
end;
end;
procedure TDbBackupFrm.FormCreate(Sender: TObject);
begin
Edit_userid.text:='';
Edit_Pass.text :='';
Edit_string.text:='';
FDir:=ExtractFilePath(ParamStr(0))+'data\'+GetDbServerDate('db_vipdl');
if not DirectoryExists(FDir) then ForceDirectories(FDir);
label4.Caption:=FDir+'\db_vipdl.dmp';
end;
procedure TDbBackupFrm.BitBtn1Click(Sender: TObject);
var ftem:string;
begin
//******应该要验证用户名和密码是否正确*********
Try
Databasedh.Connected := false;
Databasedh.Params.Clear;
Databasedh.Params.Add('SERVER NAME='+Edit_string.Text);
Databasedh.Params.Add('USER NAME='+Edit_userid.Text); //用户名和密码固定不变
Databasedh.Params.Add('PASSWORD='+Edit_Pass.Text);
Databasedh.Connected := True;
Except
Application.MessageBox(Pchar('该用户不能进行备份!'), '系统提示', MB_OK+MB_ICONERROR);
Exit;
End;
Databasedh.Connected :=false;
//**********************************************
if trim(Edit_userid.text) = '' then
begin
Application.MessageBox('用户帐号不能为空!','警告',MB_OK+MB_ICONINFORMATION);
edit_userid.SetFocus;
exit;
end;
if trim(Edit_Pass.text) = '' then
begin
Application.MessageBox('用户口令不能为空!','警告',MB_OK+MB_ICONINFORMATION);
edit_pass.SetFocus;
exit;
end;
if trim(Edit_string.text) = '' then
begin
Application.MessageBox('连接串不能为空!','警告',MB_OK+MB_ICONINFORMATION);
edit_string.SetFocus;
exit;
end;
ftem:= GetOracleDir;
if ftem = '' then
begin
Application.MessageBox('本机没有ORACLE 数据库系统,不能进行整个数据备份!','警告',MB_OK+MB_ICONINFORMATION);
exit;
end;
ftem:= GetOracleDir+'\bin\exp.exe';
if not FileExists(ftem) then
begin
ftem:=GetOracleDir+'\bin\exp.exe';
if not FileExists(ftem+'\bin\exp.exe') then
begin
Application.MessageBox('备份工具不存在!','警告',MB_OK+MB_ICONINFORMATION);
exit;
end
end;
if copy(trim(edit_string.text),1,1)='@' then
ftem:=ftem + ' '+trim(edit_userid.text)+'/'+trim(edit_pass.text)+trim(edit_string.text)+' buffer=64000 file='+label4.Caption+' log='+Fdir+'\back.log'
else
ftem:=ftem + ' '+trim(edit_userid.text)+'/'+trim(edit_pass.text)+'@'+trim(edit_string.text)+' buffer=64000 file='+label4.Caption+' log='+Fdir+'\back.log';
winExec(pchar(ftem),SW_MINIMIZE);
close;
end;
function TDbBackupFrm.GetDbServerDate(DBName: string): string;
var query:TQuery;
Present: TDateTime;
Year, Month, Day: Word;
str:string;
begin
try
query:=TQuery.Create(nil);
except
exit;
end;
query.DatabaseName:=DBname;
query.close;
query.sql.Clear;
query.sql.Add('select distinct sysdate from dual');
try
query.open;
except
exit;
end;
query.First;
Present:=Query.Fields[0].AsDateTime;
DecodeDate(Present, Year, Month, Day);
str:=inttostr(year);
if month<10 then str:=str+'0'+inttostr(month)
else str:=str+inttostr(month);
if day<10 then str:=str+'0'+inttostr(day)
else str:=str+inttostr(day);
result:=str;
query.free;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -