Преглед изворни кода

Comparison: removed fields
modified: TurboBird.lpi
modified: TurboBird.lpr
modified: comparison.lfm
modified: comparison.pas
modified: main.pas
modified: querywindow.pas
modified: scriptdb.pas

motaz пре 13 година
родитељ
комит
2672b5cdd7
7 измењених фајлова са 309 додато и 141 уклоњено
  1. 86 84
      TurboBird.lpi
  2. 1 2
      TurboBird.lpr
  3. 59 32
      comparison.lfm
  4. 115 14
      comparison.pas
  5. 31 6
      main.pas
  6. 16 2
      querywindow.pas
  7. 1 1
      scriptdb.pas

+ 86 - 84
TurboBird.lpi

@@ -55,15 +55,15 @@
         <PackageName Value="LCL"/>
       </Item5>
     </RequiredPackages>
-    <Units Count="105">
+    <Units Count="106">
       <Unit0>
         <Filename Value="TurboBird.lpr"/>
         <IsPartOfProject Value="True"/>
         <UnitName Value="TurboBird"/>
         <EditorIndex Value="0"/>
         <WindowIndex Value="0"/>
-        <TopLine Value="1"/>
-        <CursorPos X="12" Y="11"/>
+        <TopLine Value="22"/>
+        <CursorPos X="26" Y="5"/>
         <UsageCount Value="200"/>
         <Loaded Value="True"/>
       </Unit0>
@@ -73,10 +73,11 @@
         <ComponentName Value="fmMain"/>
         <ResourceBaseClass Value="Form"/>
         <UnitName Value="main"/>
-        <EditorIndex Value="8"/>
+        <IsVisibleTab Value="True"/>
+        <EditorIndex Value="7"/>
         <WindowIndex Value="0"/>
-        <TopLine Value="1913"/>
-        <CursorPos X="27" Y="1902"/>
+        <TopLine Value="3734"/>
+        <CursorPos X="1" Y="3738"/>
         <UsageCount Value="200"/>
         <Loaded Value="True"/>
         <LoadedDesigner Value="True"/>
@@ -116,11 +117,10 @@
         <ComponentName Value="fmQueryWindow"/>
         <ResourceBaseClass Value="Form"/>
         <UnitName Value="QueryWindow"/>
-        <IsVisibleTab Value="True"/>
-        <EditorIndex Value="6"/>
+        <EditorIndex Value="5"/>
         <WindowIndex Value="0"/>
-        <TopLine Value="250"/>
-        <CursorPos X="10" Y="255"/>
+        <TopLine Value="542"/>
+        <CursorPos X="42" Y="556"/>
         <UsageCount Value="200"/>
         <Loaded Value="True"/>
         <LoadedDesigner Value="True"/>
@@ -223,7 +223,7 @@
         <ComponentName Value="fmEnterPass"/>
         <ResourceBaseClass Value="Form"/>
         <UnitName Value="EnterPass"/>
-        <EditorIndex Value="9"/>
+        <EditorIndex Value="8"/>
         <WindowIndex Value="0"/>
         <TopLine Value="22"/>
         <CursorPos X="17" Y="46"/>
@@ -456,8 +456,8 @@
         <UnitName Value="SysTables"/>
         <EditorIndex Value="1"/>
         <WindowIndex Value="0"/>
-        <TopLine Value="299"/>
-        <CursorPos X="16" Y="332"/>
+        <TopLine Value="420"/>
+        <CursorPos X="24" Y="427"/>
         <UsageCount Value="200"/>
         <Loaded Value="True"/>
         <LoadedDesigner Value="True"/>
@@ -536,10 +536,10 @@
         <Filename Value="scriptdb.pas"/>
         <IsPartOfProject Value="True"/>
         <UnitName Value="Scriptdb"/>
-        <EditorIndex Value="7"/>
+        <EditorIndex Value="6"/>
         <WindowIndex Value="0"/>
         <TopLine Value="1"/>
-        <CursorPos X="11" Y="15"/>
+        <CursorPos X="1" Y="1"/>
         <UsageCount Value="200"/>
         <Loaded Value="True"/>
       </Unit51>
@@ -579,8 +579,8 @@
         <UnitName Value="TableManage"/>
         <EditorIndex Value="4"/>
         <WindowIndex Value="0"/>
-        <TopLine Value="128"/>
-        <CursorPos X="79" Y="156"/>
+        <TopLine Value="402"/>
+        <CursorPos X="3" Y="406"/>
         <UsageCount Value="200"/>
         <Loaded Value="True"/>
         <LoadedDesigner Value="True"/>
@@ -626,7 +626,7 @@
         <WindowIndex Value="0"/>
         <TopLine Value="13"/>
         <CursorPos X="22" Y="54"/>
-        <UsageCount Value="187"/>
+        <UsageCount Value="192"/>
       </Unit60>
       <Unit61>
         <Filename Value="unitfirebirdservices.pas"/>
@@ -692,7 +692,7 @@
         <WindowIndex Value="0"/>
         <TopLine Value="3"/>
         <CursorPos X="71" Y="7"/>
-        <UsageCount Value="157"/>
+        <UsageCount Value="162"/>
       </Unit68>
       <Unit69>
         <Filename Value="changepass.pas"/>
@@ -703,7 +703,7 @@
         <WindowIndex Value="0"/>
         <TopLine Value="3"/>
         <CursorPos X="88" Y="14"/>
-        <UsageCount Value="156"/>
+        <UsageCount Value="161"/>
       </Unit69>
       <Unit70>
         <Filename Value="permissionmanage.pas"/>
@@ -714,7 +714,7 @@
         <WindowIndex Value="0"/>
         <TopLine Value="341"/>
         <CursorPos X="54" Y="343"/>
-        <UsageCount Value="154"/>
+        <UsageCount Value="159"/>
       </Unit70>
       <Unit71>
         <Filename Value="sqlhistory.pas"/>
@@ -725,7 +725,7 @@
         <WindowIndex Value="0"/>
         <TopLine Value="1"/>
         <CursorPos X="35" Y="66"/>
-        <UsageCount Value="139"/>
+        <UsageCount Value="144"/>
       </Unit71>
       <Unit72>
         <Filename Value="../../lazarus/lazarus/lcl/include/menuitem.inc"/>
@@ -750,7 +750,7 @@
         <WindowIndex Value="0"/>
         <TopLine Value="18"/>
         <CursorPos X="1" Y="44"/>
-        <UsageCount Value="110"/>
+        <UsageCount Value="115"/>
       </Unit74>
       <Unit75>
         <Filename Value="/usr/lib/lazarus/0.9.30/lcl/comctrls.pp"/>
@@ -942,7 +942,7 @@
         <WindowIndex Value="0"/>
         <TopLine Value="20"/>
         <CursorPos X="22" Y="41"/>
-        <UsageCount Value="78"/>
+        <UsageCount Value="83"/>
       </Unit98>
       <Unit99>
         <Filename Value="../../FromInternet/fpc2.4/fpc-2.4.4/packages/ibase/src/ibase60dyn.pp"/>
@@ -975,20 +975,18 @@
         <UnitName Value="Comparison"/>
         <EditorIndex Value="2"/>
         <WindowIndex Value="0"/>
-        <TopLine Value="1396"/>
-        <CursorPos X="81" Y="1423"/>
-        <UsageCount Value="65"/>
+        <TopLine Value="693"/>
+        <CursorPos X="104" Y="710"/>
+        <UsageCount Value="70"/>
         <Loaded Value="True"/>
         <LoadedDesigner Value="True"/>
       </Unit102>
       <Unit103>
         <Filename Value="/usr/share/fpcsrc/2.6.0/rtl/inc/systemh.inc"/>
-        <EditorIndex Value="5"/>
         <WindowIndex Value="0"/>
         <TopLine Value="815"/>
         <CursorPos X="11" Y="832"/>
-        <UsageCount Value="22"/>
-        <Loaded Value="True"/>
+        <UsageCount Value="23"/>
       </Unit103>
       <Unit104>
         <Filename Value="/usr/share/fpcsrc/2.6.0/rtl/inc/sstrings.inc"/>
@@ -997,128 +995,132 @@
         <CursorPos X="3" Y="352"/>
         <UsageCount Value="10"/>
       </Unit104>
+      <Unit105>
+        <Filename Value="../../../lazarus/fpc/2.6.1/source/packages/fcl-base/src/custapp.pp"/>
+        <UnitName Value="CustApp"/>
+        <WindowIndex Value="0"/>
+        <TopLine Value="2"/>
+        <CursorPos X="63" Y="24"/>
+        <UsageCount Value="10"/>
+      </Unit105>
     </Units>
-    <JumpHistory Count="30" HistoryIndex="29">
+    <JumpHistory Count="29" HistoryIndex="28">
       <Position1>
-        <Filename Value="querywindow.pas"/>
-        <Caret Line="419" Column="32" TopLine="420"/>
+        <Filename Value="comparison.pas"/>
+        <Caret Line="325" Column="36" TopLine="319"/>
       </Position1>
       <Position2>
-        <Filename Value="querywindow.pas"/>
-        <Caret Line="468" Column="20" TopLine="422"/>
+        <Filename Value="comparison.pas"/>
+        <Caret Line="433" Column="79" TopLine="425"/>
       </Position2>
       <Position3>
-        <Filename Value="querywindow.pas"/>
-        <Caret Line="582" Column="14" TopLine="559"/>
+        <Filename Value="comparison.pas"/>
+        <Caret Line="442" Column="15" TopLine="350"/>
       </Position3>
       <Position4>
-        <Filename Value="querywindow.pas"/>
-        <Caret Line="240" Column="3" TopLine="238"/>
+        <Filename Value="comparison.pas"/>
+        <Caret Line="495" Column="31" TopLine="485"/>
       </Position4>
       <Position5>
-        <Filename Value="querywindow.pas"/>
-        <Caret Line="553" Column="17" TopLine="476"/>
+        <Filename Value="comparison.pas"/>
+        <Caret Line="157" Column="32" TopLine="147"/>
       </Position5>
       <Position6>
-        <Filename Value="querywindow.pas"/>
-        <Caret Line="118" Column="1" TopLine="103"/>
+        <Filename Value="comparison.pas"/>
+        <Caret Line="1016" Column="40" TopLine="994"/>
       </Position6>
       <Position7>
-        <Filename Value="querywindow.pas"/>
-        <Caret Line="251" Column="1" TopLine="234"/>
+        <Filename Value="main.pas"/>
+        <Caret Line="1" Column="1" TopLine="1"/>
       </Position7>
       <Position8>
-        <Filename Value="querywindow.pas"/>
-        <Caret Line="468" Column="14" TopLine="444"/>
+        <Filename Value="main.pas"/>
+        <Caret Line="19" Column="30" TopLine="1"/>
       </Position8>
       <Position9>
-        <Filename Value="querywindow.pas"/>
-        <Caret Line="332" Column="3" TopLine="324"/>
+        <Filename Value="main.pas"/>
+        <Caret Line="180" Column="36" TopLine="144"/>
       </Position9>
       <Position10>
         <Filename Value="querywindow.pas"/>
-        <Caret Line="1" Column="1" TopLine="1"/>
+        <Caret Line="851" Column="29" TopLine="845"/>
       </Position10>
       <Position11>
         <Filename Value="querywindow.pas"/>
-        <Caret Line="466" Column="24" TopLine="438"/>
+        <Caret Line="240" Column="3" TopLine="238"/>
       </Position11>
       <Position12>
         <Filename Value="querywindow.pas"/>
-        <Caret Line="519" Column="24" TopLine="491"/>
+        <Caret Line="118" Column="26" TopLine="109"/>
       </Position12>
       <Position13>
         <Filename Value="querywindow.pas"/>
-        <Caret Line="549" Column="16" TopLine="521"/>
+        <Caret Line="241" Column="3" TopLine="239"/>
       </Position13>
       <Position14>
         <Filename Value="querywindow.pas"/>
-        <Caret Line="570" Column="9" TopLine="558"/>
+        <Caret Line="433" Column="24" TopLine="421"/>
       </Position14>
       <Position15>
         <Filename Value="querywindow.pas"/>
-        <Caret Line="1" Column="1" TopLine="1"/>
+        <Caret Line="110" Column="22" TopLine="89"/>
       </Position15>
       <Position16>
         <Filename Value="querywindow.pas"/>
-        <Caret Line="466" Column="24" TopLine="438"/>
+        <Caret Line="240" Column="3" TopLine="238"/>
       </Position16>
       <Position17>
         <Filename Value="querywindow.pas"/>
-        <Caret Line="519" Column="24" TopLine="491"/>
+        <Caret Line="561" Column="1" TopLine="549"/>
       </Position17>
       <Position18>
         <Filename Value="querywindow.pas"/>
-        <Caret Line="549" Column="16" TopLine="521"/>
+        <Caret Line="562" Column="28" TopLine="531"/>
       </Position18>
       <Position19>
-        <Filename Value="querywindow.pas"/>
-        <Caret Line="570" Column="14" TopLine="558"/>
+        <Filename Value="comparison.pas"/>
+        <Caret Line="1009" Column="22" TopLine="993"/>
       </Position19>
       <Position20>
-        <Filename Value="querywindow.pas"/>
-        <Caret Line="1" Column="1" TopLine="1"/>
+        <Filename Value="comparison.pas"/>
+        <Caret Line="468" Column="1" TopLine="451"/>
       </Position20>
       <Position21>
-        <Filename Value="querywindow.pas"/>
-        <Caret Line="466" Column="35" TopLine="438"/>
+        <Filename Value="comparison.pas"/>
+        <Caret Line="703" Column="25" TopLine="693"/>
       </Position21>
       <Position22>
-        <Filename Value="querywindow.pas"/>
-        <Caret Line="519" Column="30" TopLine="491"/>
+        <Filename Value="main.pas"/>
+        <Caret Line="1098" Column="1" TopLine="1061"/>
       </Position22>
       <Position23>
-        <Filename Value="querywindow.pas"/>
-        <Caret Line="549" Column="30" TopLine="521"/>
+        <Filename Value="main.pas"/>
+        <Caret Line="1" Column="1" TopLine="1"/>
       </Position23>
       <Position24>
-        <Filename Value="querywindow.pas"/>
-        <Caret Line="586" Column="29" TopLine="558"/>
+        <Filename Value="main.pas"/>
+        <Caret Line="699" Column="3" TopLine="697"/>
       </Position24>
       <Position25>
-        <Filename Value="querywindow.pas"/>
-        <Caret Line="1" Column="1" TopLine="1"/>
+        <Filename Value="comparison.pas"/>
+        <Caret Line="720" Column="41" TopLine="699"/>
       </Position25>
       <Position26>
-        <Filename Value="querywindow.pas"/>
-        <Caret Line="466" Column="23" TopLine="438"/>
+        <Filename Value="main.pas"/>
+        <Caret Line="699" Column="3" TopLine="697"/>
       </Position26>
       <Position27>
-        <Filename Value="querywindow.pas"/>
-        <Caret Line="584" Column="18" TopLine="569"/>
+        <Filename Value="tablemanage.pas"/>
+        <Caret Line="406" Column="3" TopLine="402"/>
       </Position27>
       <Position28>
-        <Filename Value="querywindow.pas"/>
-        <Caret Line="332" Column="3" TopLine="321"/>
+        <Filename Value="comparison.pas"/>
+        <Caret Line="706" Column="22" TopLine="701"/>
       </Position28>
       <Position29>
-        <Filename Value="querywindow.pas"/>
-        <Caret Line="601" Column="3" TopLine="599"/>
+        <Filename Value="main.pas"/>
+        <Caret Line="699" Column="3" TopLine="697"/>
       </Position29>
-      <Position30>
-        <Filename Value="querywindow.pas"/>
-        <Caret Line="118" Column="14" TopLine="106"/>
-      </Position30>
     </JumpHistory>
   </ProjectOptions>
   <CompilerOptions>

+ 1 - 2
TurboBird.lpr

@@ -2,7 +2,7 @@
 {  TurboBird: FireBird database administration and management tool          }
 {  Developed by: Motaz Abdel Azeem http://code.sd/                          }
 {  Start development :  5.Dec.2009                                          }
-{  Last updated      : 22.May.2012                                          }
+{  Last updated      : 23.May.2012                                          }
 {  License           : GPL for GUI, LGPL for Units                          }
 {***************************************************************************}
 
@@ -77,7 +77,6 @@ begin
   Application.CreateForm(TfmChangePass, fmChangePass);
   Application.CreateForm(TfmSQLHistory, fmSQLHistory);
   Application.CreateForm(TfmCopyTable, fmCopyTable);
-  Application.CreateForm(TfmComparison, fmComparison);
   fmMain.Version:= Version;
   fmMain.VersionDate:= VersionDate;
   SAbout.Free;

+ 59 - 32
comparison.lfm

@@ -1,26 +1,26 @@
 object fmComparison: TfmComparison
-  Left = 447
-  Height = 550
-  Top = 170
-  Width = 623
+  Left = 410
+  Height = 625
+  Top = 127
+  Width = 653
   Caption = 'Database comparison'
-  ClientHeight = 550
-  ClientWidth = 623
+  ClientHeight = 625
+  ClientWidth = 653
   OnClose = FormClose
   Position = poScreenCenter
   LCLVersion = '0.9.31'
   object Label1: TLabel
-    Left = 13
+    Left = 15
     Height = 18
-    Top = 16
-    Width = 129
-    Caption = 'Compare database'
+    Top = 112
+    Width = 125
+    Caption = 'Orgional database'
     ParentColor = False
   end
   object laDatabase: TLabel
-    Left = 156
+    Left = 159
     Height = 18
-    Top = 16
+    Top = 112
     Width = 81
     Caption = 'laDatabase'
     Font.Style = [fsBold]
@@ -28,17 +28,17 @@ object fmComparison: TfmComparison
     ParentFont = False
   end
   object Label2: TLabel
-    Left = 13
+    Left = 16
     Height = 18
-    Top = 47
-    Width = 99
-    Caption = 'With database'
+    Top = 143
+    Width = 138
+    Caption = 'Compared database'
     ParentColor = False
   end
   object cbComparedDatabase: TComboBox
-    Left = 156
+    Left = 159
     Height = 31
-    Top = 38
+    Top = 134
     Width = 460
     ItemHeight = 0
     OnChange = cbComparedDatabaseChange
@@ -46,9 +46,9 @@ object fmComparison: TfmComparison
     TabOrder = 0
   end
   object laComparedDatabase: TLabel
-    Left = 156
+    Left = 159
     Height = 18
-    Top = 74
+    Top = 168
     Width = 12
     Caption = '[]'
     Font.Style = [fsBold]
@@ -58,7 +58,7 @@ object fmComparison: TfmComparison
   object bbStart: TBitBtn
     Left = 13
     Height = 30
-    Top = 240
+    Top = 320
     Width = 154
     Caption = 'Start Comparison'
     OnClick = bbStartClick
@@ -66,12 +66,11 @@ object fmComparison: TfmComparison
   end
   object meLog: TMemo
     Left = 13
-    Height = 238
-    Top = 280
-    Width = 603
+    Height = 233
+    Top = 360
+    Width = 633
     Anchors = [akTop, akLeft, akRight, akBottom]
     Font.Name = 'Courier 10 Pitch'
-    Font.Style = [fsUnderline]
     ParentFont = False
     ReadOnly = True
     ScrollBars = ssAutoBoth
@@ -81,9 +80,9 @@ object fmComparison: TfmComparison
     Cursor = crHandPoint
     Left = 190
     Height = 18
-    Top = 252
-    Width = 301
-    Caption = 'Script missing objects in compared database'
+    Top = 330
+    Width = 273
+    Caption = 'Script differences in compared database'
     Font.Style = [fsUnderline]
     ParentColor = False
     ParentFont = False
@@ -92,7 +91,7 @@ object fmComparison: TfmComparison
   object GroupBox1: TGroupBox
     Left = 15
     Height = 79
-    Top = 101
+    Top = 192
     Width = 601
     Caption = 'Compared objects'
     ClientHeight = 60
@@ -169,8 +168,8 @@ object fmComparison: TfmComparison
   object StatusBar1: TStatusBar
     Left = 0
     Height = 21
-    Top = 529
-    Width = 623
+    Top = 604
+    Width = 653
     Panels = <    
       item
         Width = 50
@@ -180,9 +179,37 @@ object fmComparison: TfmComparison
   object cxRemovedObjects: TCheckBox
     Left = 15
     Height = 24
-    Top = 200
+    Top = 278
     Width = 185
     Caption = 'Check Removed objects'
     TabOrder = 5
   end
+  object bbClose: TBitBtn
+    Left = 626
+    Height = 24
+    Top = 0
+    Width = 27
+    Anchors = [akTop, akRight]
+    Caption = ' X  '
+    Color = 16249563
+    Font.Style = [fsBold]
+    OnClick = bbCloseClick
+    ParentFont = False
+    TabOrder = 6
+  end
+  object Label3: TLabel
+    Left = 8
+    Height = 98
+    Top = 6
+    Width = 608
+    Anchors = [akTop, akLeft, akRight]
+    AutoSize = False
+    Caption = 'Database comparison tool compares origional database structure to another database structure.'#10'It generates script to make compared database structure becomes like origional database.'#10'For instance, origional database could be a development database, and compared database is an old version that'#10'is deployed in customer side. This tool generates script to make customer database structure '#10'resembles developmenent database as much as possible.'
+    Color = clCream
+    Font.Height = -11
+    ParentColor = False
+    ParentFont = False
+    Transparent = False
+    WordWrap = True
+  end
 end

+ 115 - 14
comparison.pas

@@ -17,6 +17,7 @@ type
   { TfmComparison }
 
   TfmComparison = class(TForm)
+    bbClose: TBitBtn;
     bbStart: TBitBtn;
     cbComparedDatabase: TComboBox;
     cxRemovedObjects: TCheckBox;
@@ -31,11 +32,13 @@ type
     GroupBox1: TGroupBox;
     Label1: TLabel;
     Label2: TLabel;
+    Label3: TLabel;
     laScript: TLabel;
     laDatabase: TLabel;
     laComparedDatabase: TLabel;
     meLog: TMemo;
     StatusBar1: TStatusBar;
+    procedure bbCloseClick(Sender: TObject);
     procedure bbStartClick(Sender: TObject);
     procedure cbComparedDatabaseChange(Sender: TObject);
     procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
@@ -63,6 +66,8 @@ type
     ModifiedFunctionsList: TStringList;
     ModifiedDomainsList: TStringList;
 
+    RemovedFieldsList: TStringList;
+
     fQueryWindow: TfmQueryWindow;
 
     procedure CheckRemovedDBObjects;
@@ -84,8 +89,10 @@ type
 
     procedure CheckRemovedIndices;
     procedure CheckRemovedConstraints;
+    procedure CheckRemovedFields;
 
     procedure InitializeQueryWindow;
+
     procedure ScriptMissingFields;
 
     procedure ScriptModifiedFields;
@@ -98,6 +105,7 @@ type
     procedure ScriptModifiedDomains;
 
     procedure ScriptRemovedDBObjects;
+    procedure ScriptRemovedFields;
   public
     procedure Init(dbIndex: Integer);
     { public declarations }
@@ -183,11 +191,22 @@ begin
   if cxRemovedObjects.Checked then
     CheckRemovedDBObjects;
 
+  if cxTables.Checked and cxRemovedObjects.Checked then
+    CheckRemovedFields;
+
   StatusBar1.Color:= clDefault;
   DisplayStatus('Comparison Finished, ' + IntToStr(DiffCount) + ' difference(s) found');
+  if DiffCount = 0 then
+   meLog.Text:= 'No difference';
   meLog.Visible:= True;
 end;
 
+procedure TfmComparison.bbCloseClick(Sender: TObject);
+begin
+  Close;
+  Parent.Free;
+end;
+
 procedure TfmComparison.FormClose(Sender: TObject; var CloseAction: TCloseAction);
 var
   i: Integer;
@@ -217,7 +236,9 @@ begin
   ModifiedProceduresList.Free;
   ModifiedFunctionsList.Free;
   ModifiedDomainsList.Free;
+  RemovedFieldsList.Free;
 
+  CloseAction:= caFree;
 end;
 
 procedure TfmComparison.laScriptClick(Sender: TObject);
@@ -241,11 +262,15 @@ var
   ConstraintName: string;
 begin
   InitializeQueryWindow;
-  meLog.Clear;
   ScriptList:= TStringList.Create;
   FieldsList:= TStringList.Create;
 
-  ScriptRemovedDBObjects;
+  if cxRemovedObjects.Checked then
+  begin
+    ScriptRemovedDBObjects;
+    if cxTables.Checked then
+      ScriptRemovedFields;
+  end;
 
   if cxTables.Checked then
   begin
@@ -405,7 +430,9 @@ begin
 
         fQueryWindow.meQuery.Lines.Add(Line);
         fQueryWindow.meQuery.Lines.Add('');
-      end;
+      end
+      else
+        fQueryWindow.meQuery.Lines.Add('-- Index ' + AIndexName + ' not exist on ' + ATableName);
 
     end
     else
@@ -417,7 +444,7 @@ begin
       System.Delete(Line, 1, Pos(',', Line));
       ConstraintName:= Line;
       ScriptList.Clear;
-      if dmSysTables.GetConstraintInfo(fdbIndex, ATableName, AIndexName, KeyName, CurrentTableName, CurrentFieldName,
+      if dmSysTables.GetConstraintInfo(fdbIndex, ATableName, ConstraintName, KeyName, CurrentTableName, CurrentFieldName,
         OtherTableName, OtherFieldName, UpdateRule, DeleteRule) then
       begin
         Line:= 'alter table ' + ATableName + ' add constraint ' + ConstraintName +
@@ -430,8 +457,9 @@ begin
 
         fQueryWindow.meQuery.Lines.Add(Line + ';');
         fQueryWindow.meQuery.Lines.Add('');
-      end;
-
+      end
+      else
+        fQueryWindow.meQuery.Lines.Add('-- Constraint ' + ConstraintName + ' not exist on ' + ATableName);
 
     end;
 
@@ -440,7 +468,6 @@ begin
   fQueryWindow.Show;
   ScriptList.Free;
   FieldsList.Free;
-  Close;
 
 end;
 
@@ -659,6 +686,8 @@ var
   OtherTablename, OtherFieldName, UpdateRole, DeleteRole: string;
   CKeyName, CCurrentTableName, CCurrentFieldName,
   COtherTablename, COtherFieldName, CUpdateRole, CDeleteRole: string;
+  Exist: Boolean;
+  OtherFieldNames, COtherFieldNames: string;
 begin
   meLog.Lines.Add('');
   meLog.Lines.Add('Modified Constraints');
@@ -671,12 +700,24 @@ begin
     System.Delete(Line, 1, Pos(',', Line));
     AConstraintName:= Line;
 
-    dmSysTables.GetConstraintInfo(fdbIndex, ATableName, AConstraintName, KeyName, CurrentTableName, CurrentFieldName,
-      OtherTablename, OtherFieldName, UpdateRole, DeleteRole);
-    dmSysTables.GetConstraintInfo(cbComparedDatabase.ItemIndex, ATableName, AConstraintName, CKeyName,
+    Exist:= (dmSysTables.GetConstraintInfo(fdbIndex, ATableName, AConstraintName, KeyName, CurrentTableName, CurrentFieldName,
+        OtherTablename, OtherFieldName, UpdateRole, DeleteRole));
+    if Exist then
+      OtherFieldNames:= dmSysTables.GetConstraintForiegnKeyFields(OtherFieldName, dmSysTables.sqQuery);
+
+    if Exist then
+    Exist:= dmSysTables.GetConstraintInfo(cbComparedDatabase.ItemIndex, ATableName, AConstraintName, CKeyName,
       CCurrentTableName, CCurrentFieldName, COtherTablename, COtherFieldName, CUpdateRole, CDeleteRole);
+
+    if Exist then
+      COtherFieldNames:= dmSysTables.GetConstraintForiegnKeyFields(COtherFieldName, dmSysTables.sqQuery);
+
+    if not Exist then
+      meLog.Lines.Add(' -- Error: Constraint: ' + AConstraintName + ' not exist on table: ' + ATableName);
+
+    if Exist then
     if (CurrentTableName <> CCurrentTableName) or (CurrentFieldName <> CCurrentFieldName) or
-       (OtherTablename <> COtherTablename) or (OtherFieldName <> COtherFieldName) or (UpdateRole <> CUpdateRole) or
+       (OtherTablename <> COtherTablename) or (OtherFieldNames <> COtherFieldNames) or (UpdateRole <> CUpdateRole) or
        (DeleteRole <> CDeleteRole) then
     begin
       meLog.Lines.Add(' ' + ExistConstraintsList[i]);
@@ -859,6 +900,7 @@ begin
     begin
       dbRemovedObjectsList[12].Add(CTablesList[i] + ',' + ComparedList[i]);
       meLog.Lines.Add(' ' + CTableslist[i] + ':' + ComparedList[i]);
+      Inc(DiffCount);
     end;
   end;
 
@@ -895,6 +937,7 @@ begin
     begin
       dbRemovedObjectsList[13].Add(CTablesList[i] + ',' + ComparedList[i]);
       meLog.Lines.Add(' ' + CTableslist[i] + ':' + ComparedList[i]);
+      Inc(DiffCount);
     end;
 
   end;
@@ -905,6 +948,37 @@ begin
   CTablesList.Free;
 end;
 
+procedure TfmComparison.CheckRemovedFields;
+var
+  i, j: Integer;
+  FieldsList: TStringList;
+  ComparedList: TStringList;
+begin
+  FieldsList:= TStringList.Create;
+  ComparedList:= TStringList.Create;
+  meLog.Lines.Add('');
+  meLog.Lines.Add('Removed fields');
+  RemovedFieldsList.Clear;
+  for i:= 0 to dbExistingObjectsList[1].Count - 1 do
+  begin
+    dmSysTables.GetTableFields(fdbIndex, dbExistingObjectsList[1].Strings[i], FieldsList);
+    dmSysTables.GetTableFields(cbComparedDatabase.ItemIndex, dbExistingObjectsList[1].Strings[i], ComparedList);
+
+    // Get missing fields
+    for j:= 0 to ComparedList.Count - 1 do
+      if FieldsList.IndexOf(ComparedList[j]) = -1 then // Add to missing list
+      begin
+        meLog.Lines.Add(' ' + dbExistingObjectsList[1].Strings[i] + ': ' + ComparedList[j]);
+        RemovedFieldsList.Add(dbExistingObjectsList[1].Strings[i] + ',' + ComparedList[j]);
+        Inc(DiffCount);
+      end;
+  end;
+
+  FieldsList.Free;
+  ComparedList.Free;
+
+end;
+
 procedure TfmComparison.InitializeQueryWindow;
 begin
   fQueryWindow:= fmMain.ShowQueryWindow(cbComparedDatabase.ItemIndex, 'Database Differences');
@@ -948,9 +1022,11 @@ begin
     if Trim(DefaultValue) <> '' then
     begin
       if (Pos('CHAR', FieldType) > 0) and (Pos('''', DefaultValue) = 0) then
-        Line:= Line + ' ''' + DefaultValue + ''''
-      else
-        Line:= Line + ' ' + DefaultValue;
+        DefaultValue:= ' ''' + DefaultValue + '''';
+      if Pos('default', LowerCase(DefaultValue)) = 0 then
+        DefaultValue:= ' default ' + DefaultValue;
+      Line:= Line + ' ' + DefaultValue;
+
     end;
 
     // Null/Not null
@@ -1498,6 +1574,29 @@ begin
 
 end;
 
+procedure TfmComparison.ScriptRemovedFields;
+var
+  i: Integer;
+  Line, ATableName, AFieldName: string;
+begin
+  if RemovedFieldsList.Count > 0 then
+  begin
+    fQueryWindow.meQuery.Lines.Add('');
+    fQueryWindow.meQuery.Lines.Add('-- Removed Fields');
+  end;
+
+  for i:= 0 to RemovedFieldsList.Count - 1 do
+  begin
+    Line:= RemovedFieldsList[i];
+    ATableName:= copy(Line, 1, Pos(',', Line) - 1);
+    System.Delete(Line, 1, Pos(',', Line));
+    AFieldName:= Line;
+    fQueryWindow.meQuery.Lines.Add('alter table ' + ATableName + ' drop ' + AFieldName + ';');
+  end;
+
+
+end;
+
 procedure TfmComparison.Init(dbIndex: Integer);
 var
   i: Integer;
@@ -1551,6 +1650,8 @@ begin
   ModifiedProceduresList:= TStringList.Create;
   ModifiedFunctionsList:= TStringList.Create;
   ModifiedDomainsList:= TStringList.Create;
+
+  RemovedFieldsList:= TStringList.Create;
 end;
 
 procedure TfmComparison.CheckMissingIndices;

+ 31 - 6
main.pas

@@ -109,7 +109,6 @@ type
     procedure lmAddUserClick(Sender: TObject);
     procedure lmBackupClick(Sender: TObject);
     procedure lmChangePasswordClick(Sender: TObject);
-    procedure lmCloseTabClick(Sender: TObject);
     procedure lmCompareClick(Sender: TObject);
     procedure lmCopyRolePermissionClick(Sender: TObject);
     procedure lmCopyUserPermissionClick(Sender: TObject);
@@ -175,6 +174,7 @@ type
     procedure pmDatabasePopup(Sender: TObject);
     procedure tvMainDblClick(Sender: TObject);
     procedure tvMainExpanded(Sender: TObject; Node: TTreeNode);
+    procedure GlobalException(Sender: TObject; E : Exception);
   private
     ibConnection: TIBConnection;
     sqlTransaction: TSQLTransaction;
@@ -245,6 +245,7 @@ end;
 
 procedure TfmMain.FormCreate(Sender: TObject);
 begin
+  Application.OnException:= @GlobalException;
   fActivated:= False;
   LoadRegisteredDatabases;
 end;
@@ -332,19 +333,37 @@ begin
   end;
 end;
 
-procedure TfmMain.lmCloseTabClick(Sender: TObject);
-begin
-end;
-
 procedure TfmMain.lmCompareClick(Sender: TObject);
 var
   dbIndex: Integer;
+  Title: string;
+  ATab: TTabSheet;
 begin
   dbIndex:= tvMain.Selected.OverlayIndex;
 
   if (RegisteredDatabases[dbIndex].RegRec.Password <> '') or
   ConnectToDBAs(dbIndex) then
   begin
+    Title:= RegisteredDatabases[dbIndex].RegRec.Title + ': Database Comparison';
+    fmComparison:= FindCustomForm(Title, TfmComparison) as TfmComparison;
+    if fmComparison = nil then
+    begin
+      fmComparison:= TfmComparison.Create(Application);
+      ATab:= TTabSheet.Create(nil);
+      ATab.Parent:= PageControl1;
+      fmComparison.Parent:= ATab;
+      fmComparison.Left:= 0;
+      fmComparison.Top:= 0;
+      fmComparison.BorderStyle:= bsNone;
+      fmComparison.Align:= alClient;
+      fmComparison.Caption:= Title;
+    end
+    else
+      ATab:= fmComparison.Parent as TTabSheet;
+
+    PageControl1.ActivePage:= ATab;
+    ATab.Tag:= dbIndex;
+    ATab.Caption:= Title;
     fmComparison.Init(dbIndex);
     fmComparison.Show;
   end;
@@ -3676,7 +3695,8 @@ begin
   end
   else
   if Node.Level = 4 then // Table fields (Edit)
-    lmEditFieldClick(nil)
+    lmEditFieldClick(nil);
+
 end;
 
 (**************    Expanded     *****************)
@@ -3711,6 +3731,11 @@ begin
   end;
 end;
 
+procedure TfmMain.GlobalException(Sender: TObject; E : Exception);
+begin
+  MessageDlg('Exception', e.Message, mtError, [mbOk], 0);
+end;
+
 (**********************             Load databases            *********************************)
 
 function TfmMain.LoadRegisteredDatabases: Boolean;

+ 16 - 2
querywindow.pas

@@ -429,8 +429,10 @@ var
   Command: string;
   IsDDL: Boolean;
   Affected: Integer;
+  ModifyCount: Integer;
 begin
   try
+    ModifyCount:= 0;
     RemoveControls;
     Query:= Trim(GetQuery);
 
@@ -443,6 +445,7 @@ begin
     if (QueryType = 3) then
     begin
       ExecuteScript(Query);
+      Inc(ModifyCount);
       SqlType:= GetSQLType(Query, Command);
       fmMain.AddToSQLHistory(RegRec.Title, SqlType, Query);
     end
@@ -509,6 +512,7 @@ begin
               SqlQuery.ExecSQL;
               Affected:= sqlQuery.RowsAffected;
             end;
+            Inc(ModifyCount);
 
             fmMain.AddToSQLHistory(RegRec.Title, SQLType, QueryPart);
             meResult.Visible:= True;
@@ -545,10 +549,20 @@ begin
         begin
           if ExecuteScript(QueryPart) then
           begin
+            Inc(ModifyCount);
             SqlType:= GetSQLType(QueryPart, Command);
             fmMain.AddToSQLHistory(RegRec.Title, SqlType, Query);
           end;
         end;
+        if (ModifyCount > 50) then
+        if (MessageDlg('Commit', 'There are too many transactions, did you want to commit',
+          mtConfirmation, [mbYes, mbNo], 0) = mrYes) then
+        begin
+          SqlTrans.CommitRetaining;
+          ModifyCount:= 0;
+        end
+        else
+          ModifyCount:= 0;
 
         Application.ProcessMessages;
       until StartLine >= List.Count;
@@ -848,12 +862,12 @@ begin
   RemoveControls;
   if SqlTrans.Active then
   begin
-    SqlTrans.Commit;
+    SqlTrans.CommitRetaining;
     if OnCommit <> nil then
       OnCommit(self);
     OnCommit:= nil;
   end;
-  IBConnection.Close;
+  //IBConnection.Close;
   CloseAction:= caFree;
 end;
 

+ 1 - 1
scriptdb.pas

@@ -219,7 +219,7 @@ begin
   if PKeyName <> '' then
   begin
     fmMain.GetConstraintFields(ATableName, PKeyName, PKFieldsList);
-    FieldLine:= 'constraint ' + ConstraintName + ' primary key (';
+    FieldLine:= 'constraint ' + PKeyName + ' primary key (';
     for i:= 0 to PKFieldsList.Count - 1 do
       FieldLine:= FieldLine + PKFieldsList[i] + ', ';
     if PKFieldsList.Count > 0 then