📄 dmdirt.pas
字号:
end;
procedure TboDirt.CompareStoredProcs;
var
lcv, lcv2 :integer;
oSourceProc, oDestProc : _StoredProcedure;
lFound : boolean;
begin
if not(assigned(SQLDMO_Source)) or not(assigned(SQLDMO_Dest)) then exit;
Banner('Stored Procedure Discrepencies');
for lcv := 1 to DB_Source.StoredProcedures.Count do begin
// Get the first table's name.
oSourceProc := DB_Source.StoredProcedures.Item(lcv, DB_Source);
oDestProc := nil;
// Update the UI;
if assigned(CompareUI) then CompareUI.Add('-------------------------------');
if assigned(CompareUI) then CompareUI.Add('Stored Proc: ' + oSourceProc.Name);
if assigned(CompareUI) then Application.Processmessages;
// Look for that table name in the destination database.
// Note that the table could be out of order. If it is
// not found, the table should be noted as missing.
lFound := false;
for lcv2 := 1 to DB_Dest.StoredProcedures.Count do begin
oDestProc := DB_Dest.StoredProcedures.Item(lcv2, DB_Dest);
if uppercase(oSourceProc.Name) = uppercase(oDestProc.Name) then begin
lFound := True;
// Check the script.
if oSourceProc.Script(null, null, null) <>
oDestProc.Script(null, null, null) then begin
if assigned(CompareUI) then CompareUI.Add(' ** Script Text Inconsistency');
end else begin
if assigned(CompareUI) then CompareUI.Add(' Script Text Matches');
end;
break;
end;
end;
if not lFound then begin
// Update the UI;
if assigned(CompareUI) then CompareUI.Add(' **Stored Proc: ' +
oSourceProc.name +
' Not found in destination database.');
end;
end;
end;
function TboDirt.ConnectDest(sServerName: string): boolean;
begin
SQLDMO_Dest := coSQLServer.Create;//createOLEObject('SQLDMO.SQLServer');
SQLDMO_Dest.Name := sServerName;
// Use NT Authentication (as opposed to SQL Server Authentication).
SQLDMO_Dest.LoginSecure := true;
// Set a reasonable timeout.
SQLDMO_Dest.LoginTimeout := 30;
// Autoreconnect is connection is lost.
SQLDMO_Dest.AutoReconnect := true;
// Assign application name so server knows who i am.
SQLDMO_Dest.ApplicationName := 'D.I.R.T. - Dest';
// Now connect.
SQLDMO_Dest.Connect(SServerName, '', '');
// Test the connection.
result := SQLDMO_Dest.VerifyConnection(SQLDMOConn_ReconnectIfDead);
if result <> null then windows.beep(600, 100);
end;
function TboDirt.ConnectSource(sServerName: string): boolean;
begin
SQLDMO_Source := coSQLServer.Create;//createOLEObject('SQLDMO.SQLServer');
SQLDMO_Source.Name := sServerName;
// Use NT Authentication (as opposed to SQL Server Authentication).
SQLDMO_Source.LoginSecure := true;
// Set a reasonable timeout.
SQLDMO_Source.LoginTimeout := 30;
// Autoreconnect is connection is lost.
SQLDMO_Source.AutoReconnect := true;
// Assign application name so server knows who i am.
SQLDMO_Source.ApplicationName := 'D.I.R.T. - Source';
// Now connect.
SQLDMO_Source.Connect(SServerName, '', '');
// Test the connection.
result := SQLDMO_Source.VerifyConnection(SQLDMOConn_ReconnectIfDead);
if result <> null then windows.beep(600, 100);
end;
function TboDirt.ConnectDBDest(sDBName: string): boolean;
var
lcv : integer;
begin
DB_Dest := nil;
for lcv := 1 to SQLDMO_Dest.Databases.Count do begin
if uppercase(SQLDMO_Dest.Databases.Item(lcv, SQLDMO_Dest).Name) = uppercase(sDBName) then begin
DB_Dest := SQLDMO_Dest.Databases.Item(lcv, SQLDMO_Dest);
end;
end;
result := assigned(DB_Dest);
end;
function TboDirt.ConnectDBSource(sDBName: string): boolean;
var
lcv : integer;
begin
DB_Source := nil;
for lcv := 1 to SQLDMO_Source.Databases.Count do begin
if uppercase(SQLDMO_Source.Databases.Item(lcv, SQLDMO_Source).Name) = uppercase(sDBName) then begin
DB_Source := SQLDMO_Source.Databases.Item(lcv, SQLDMO_Source);
end;
end;
result := assigned(DB_Source);
end;
procedure TboDirt.DisconnectDest;
begin
if assigned(SQLDMO_Dest) then SQLDMO_Dest := nil;
end;
procedure TboDirt.DisconnectSource;
begin
if assigned(SQLDMO_Source) then SQLDMO_Source := nil;
end;
procedure TboDirt.SetCompareUI(const Value: TStrings);
begin
FCompareUI := Value;
end;
{
A simple way to add a consistent banner to the top
of each discrepency listing.
}
procedure TboDirt.Banner(sName : string);
begin
if assigned(CompareUI) then begin
CompareUI.Add('');
CompareUI.Add('************************************************************');
CompareUI.Add(sName + ' ' + FormatdateTime('mm/dd/yyyy hh:mm', now));
CompareUI.Add('************************************************************');
CompareUI.Add('');
end;
end;
procedure TboDirt.DestServerInfo;
begin
ServerInfo(SQLDMO_Dest);
end;
procedure TboDirt.SourceServerInfo;
begin
ServerInfo(SQLDMO_Source);
end;
procedure TboDirt.ServerInfo(oServer: _SQLServer);
begin
if assigned(CompareUI) then begin
Banner(oServer.name + ' General Information');
CompareUI.Add(' Version: ' + oServer.VersionString);
CompareUI.Add(' Databases: ' + inttostr(oServer.Databases.Count));
CompareUI.Add(' Host Name: ' + oServer.HostName);
CompareUI.Add(' Language: ' + oServer.Language);
CompareUI.Add(' Connection Id: ' + inttostr(oServer.ConnectionId));
CompareUI.Add(' Local Network Name: ' + oServer.NetName);
CompareUI.Add(' Login Timeout(sec): ' + inttostr(oServer.LoginTimeout));
CompareUI.Add(' Query Timeout(sec): ' + inttostr(oServer.QueryTimeout));
CompareUI.Add(' Blocking Timeout(ms): ' + inttostr(ord(oServer.BlockingTimeout)));
CompareUI.Add(' Command Terminator: ' + oServer.CommandTerminator);
CompareUI.Add(' This Application Name: ' + oServer.ApplicationName);
CompareUI.Add(' Auto Reconnect Flag: ' + inttostr(ord(oServer.AutoReconnect)));
CompareUI.Add(' Default Null Flag: ' + inttostr(ord(oServer.AnsiNulls)));
CompareUI.Add(' Network Packet Size: ' + inttostr(oServer.NetPacketSize));
end;
end;
procedure TboDirt.DBInfo(oDB: _Database);
begin
if assigned(CompareUI) then begin
Banner(oDB.name + ' General Information');
CompareUI.Add(' Owner: ' + oDB.Owner);
CompareUI.Add(' Tables: ' + inttostr(oDB.tables.Count));
CompareUI.Add(' Views: ' + inttostr(oDB.Views.Count));
CompareUI.Add(' Stored Procs: ' + inttostr(oDB.StoredProcedures.Count));
CompareUI.Add(' Create Date: ' + oDB.CreateDate);
CompareUI.Add(' Database Size(mb): ' + inttostr(oDB.Size));
CompareUI.Add(' Space Avail(kb): ' + inttostr(oDB.SpaceAvailable));
CompareUI.Add(' Data Disk Usage(mb): ' + floattostr(oDB.DataSpaceUsage));
CompareUI.Add(' Index Space Usage(kb): ' + floattostr(oDB.IndexSpaceUsage));
CompareUI.Add(' Database File Path: ' + oDB.PrimaryFilePath);
end;
end;
procedure TboDirt.DestDBInfo;
begin
DBInfo(DB_Dest);
end;
procedure TboDirt.SourceDBInfo;
begin
DBInfo(DB_Source);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -