⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dmdirt.pas

📁 是一个delphi的流程制作软件
💻 PAS
📖 第 1 页 / 共 2 页
字号:
unit dmDirt;
{DISCLAIMER
--------------------
This source code is the property of Core Software.  You may use and distrubute
this source code at your own risk.  Warantee as to the to the completeness,
robustness, timliness, or any issue relevant to this source code whatsoever is
not expressed or implied in any way.

FREE INFORMATION
--------------------
Most companies disallow any religious content to be published in articles or
submitted material which is made public.  This is illegal.  I have a constitutional
right to practice my religion, which includes bringing the news of Jesus Christ
to the world.  It is not my intention to invade anyone's privacy, insult, or offend
any person - religious or not.

Jesus Loves You!


Core Software
CTO, Jason 'Wedge' Perry
534 Denver Ave
Chesapeake, VA 23322
jason.perry@home.com
AOL Instant Messager : GuiOOP
ICQ Pager Address : 37953032
}

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  Dialogs, SQLDMO_TLB, ComObj, ComCtrls;

type
  TboDirt = class(TDataModule)
  private
    FCompareUI: TStrings;
    procedure SetCompareUI(const Value: TStrings);
    procedure Banner(sName : string);
    procedure ServerInfo(oServer : _SQLServer);
    procedure DBInfo(oDB : _Database);
  public
    SQLDMO_Source : _SQLServer;
    SQLDMO_Dest : _SQLServer;
    DB_Source : _Database;
    DB_Dest : _Database;
    function ConnectSource(sServerName : string) : boolean;
    function ConnectDest(sServerName : string) : boolean;
    function ConnectDBSource(sDBName : string) : boolean;
    function ConnectDBDest(sDBName : string) : boolean;
    procedure DisconnectSource;
    procedure DisconnectDest;
    procedure CompareTables;
    procedure CompareStoredProcs;

    procedure SourceServerInfo;
    procedure DestServerInfo;

    procedure SourceDBInfo;
    procedure DestDBInfo;

    property CompareUI : TStrings read FCompareUI write SetCompareUI;
  end;

var
  boDirt: TboDirt;

implementation

{$R *.DFM}

{ TboDirt }

{
Spin thru the source tables.  Look up the dest table.
Compare the attributes, etc.
}
procedure TboDirt.CompareTables;
var
  lcv, lcv2, lcv3 : integer;
  oSourceTable, oDestTable : _Table;
  lFound, lColErr : boolean;
begin
  if not(assigned(SQLDMO_Source)) or not(assigned(SQLDMO_Dest)) then exit;

  Banner('Table Discrepencies');
  for lcv := 1 to DB_Source.Tables.Count do begin
    // Get the first table's name.
    oSourceTable := DB_Source.Tables.Item(lcv, DB_Source);
    oDestTable := nil;

    // Update the UI;
    if assigned(CompareUI) then CompareUI.Add('-------------------------------');
    if assigned(CompareUI) then CompareUI.Add('Table: ' + oSourceTable.Name);
    //if assigned(CompareUI) then Application.Processmessages;

    // See if the number of tables is consistent.
    if DB_Source.Tables.Count > DB_Dest.Tables.Count then begin
        if assigned(CompareUI) then
          CompareUI.Add('   ** There are additional tables in Source.');
    end else if DB_Source.Tables.Count < DB_Dest.Tables.Count then begin
        if assigned(CompareUI) then
          CompareUI.Add('   ** There are missing tables in Source.');
    end else if  DB_Source.Tables.Count = DB_Dest.Tables.Count then begin
        if assigned(CompareUI) then
          CompareUI.Add('   Table Counts Match');
    end;

    // 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.Tables.Count do begin
      oDestTable := DB_Dest.Tables.Item(oSourceTable.name, DB_Dest);

      // In case the table doesn't exist.
      if not (assigned(oDestTable)) then begin
        if assigned(CompareUI) then
          CompareUI.Add('   ** Missing Table: ' + oSourceTable.Name);
        break;
      end;

      // Looking for the same table.
      if uppercase(oSourceTable.Name) = uppercase(oDestTable.Name) then begin
        lFound := True;

        // Check the script first.
        {if compareText(oSourceTable.Script(SQLDMOScript_Default, null, null, SQLDMOScript2_Default),
                       oDestTable.Script(SQLDMOScript_Default, null, null, SQLDMOScript2_Default)) <> 0 then begin
          if assigned(CompareUI) then CompareUI.Add('   ** Script Text Inconsistency');
        end else begin
          if assigned(CompareUI) then CompareUI.Add('   Script Text Matches');
        end;}

        // Check each column.
        if assigned(CompareUI) then CompareUI.Add('   Column Discrepencies');
        if assigned(CompareUI) then CompareUI.Add('   --------------------');
        lColErr := false;
        for lcv3 := 1 to oSourceTable.Columns.count do begin

          // Test the data type
          if oSourceTable.Columns.Item(lcv3).Datatype <>
             oDestTable.Columns.Item(lcv3).Datatype then begin
            if assigned(CompareUI) then CompareUI.Add('   Datatype: ' +
                                                      oSourceTable.Columns.Item(lcv3).name +
                                                      oSourceTable.Columns.Item(lcv3).datatype +
                                                      ' ' +
                                                      oDestTable.Columns.Item(lcv3).datatype);

            lColErr := True;
          end;

          // Test the physical data type
          if oSourceTable.Columns.Item(lcv3).PhysicalDatatype <>
             oDestTable.Columns.Item(lcv3).PhysicalDatatype then begin
            if assigned(CompareUI) then CompareUI.Add('   PhysicalDatatype: ' +
                                                      oSourceTable.Columns.Item(lcv3).name +
                                                      oSourceTable.Columns.Item(lcv3).PhysicalDatatype +
                                                      ' ' +
                                                      oDestTable.Columns.Item(lcv3).PhysicalDatatype);

            lColErr := True;
          end;

          // Test the allownull property
          if oSourceTable.Columns.Item(lcv3).AllowNulls <>
             oDestTable.Columns.Item(lcv3).AllowNulls then begin
            if assigned(CompareUI) then CompareUI.Add('   AllowNulls: ' +
                                                      oSourceTable.Columns.Item(lcv3).name +
                                                      inttostr(ord(boolean(oSourceTable.Columns.Item(lcv3).AllowNulls))) +
                                                      ' ' +
                                                      inttostr(ord(boolean(oDestTable.Columns.Item(lcv3).AllowNulls))));

            lColErr := True;
          end;

          // Test the length property
          if oSourceTable.Columns.Item(lcv3).Length <>
             oDestTable.Columns.Item(lcv3).Length then begin
            if assigned(CompareUI) then CompareUI.Add('   Length: ' +
                                                      oSourceTable.Columns.Item(lcv3).name +
                                                      inttostr(oSourceTable.Columns.Item(lcv3).Length) +
                                                      ' ' +
                                                      inttostr(oDestTable.Columns.Item(lcv3).Length));

            lColErr := True;
          end;

          break;
        end;
        // If no errors, then put a NONE in.
        if not lColErr then
          if assigned(CompareUI) then CompareUI.Add('   NONE');

      end;
    end;
    if not lFound then begin
      // Update the UI;
      if assigned(CompareUI) then CompareUI.Add('   **Table: ' +
                                                oSourceTable.name +
                                                ' Not found in destination database.');
    end;
//  end;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -