浏览代码

Replace magic numbers with enumeration/enumerated type

Reinier Olislagers 11 年之前
父节点
当前提交
5a6f783307
共有 13 个文件被更改,包括 202 次插入162 次删除
  1. 2 2
      backuprestore.lfm
  2. 45 45
      backuprestore.lrs
  3. 5 3
      backuprestore.pas
  4. 61 51
      comparison.pas
  5. 4 3
      copytable.pas
  6. 2 2
      createuser.pas
  7. 16 21
      main.pas
  8. 1 1
      newgen.pas
  9. 8 7
      permissionmanage.pas
  10. 11 11
      scriptdb.pas
  11. 15 14
      systables.pas
  12. 2 2
      tablemanage.pas
  13. 30 0
      turbocommon.pas

+ 2 - 2
backuprestore.lfm

@@ -68,14 +68,14 @@ object fmBackupRestore: TfmBackupRestore
       OnEditingDone = edBackupEditingDone
       OnEditingDone = edBackupEditingDone
       TabOrder = 3
       TabOrder = 3
     end
     end
-    object SpeedButton1: TSpeedButton
+    object sbBroseBackupFile: TSpeedButton
       Left = 416
       Left = 416
       Height = 22
       Height = 22
       Top = 133
       Top = 133
       Width = 23
       Width = 23
       Anchors = [akTop, akRight]
       Anchors = [akTop, akRight]
       Caption = '...'
       Caption = '...'
-      OnClick = SpeedButton1Click
+      OnClick = sbBroseBackupFileClick
     end
     end
     object bbStart: TBitBtn
     object bbStart: TBitBtn
       Left = 354
       Left = 354

+ 45 - 45
backuprestore.lrs

@@ -18,51 +18,51 @@ LazarusResources.Add('TfmBackupRestore','FORMDATA',[
   +#3#137#0#5'Width'#2'5'#7'Caption'#6#11'Backup File'#11'ParentColor'#8#0#0#5
   +#3#137#0#5'Width'#2'5'#7'Caption'#6#11'Backup File'#11'ParentColor'#8#0#0#5
   +'TEdit'#8'edBackup'#4'Left'#2'f'#6'Height'#2#21#3'Top'#3#137#0#5'Width'#3'1'
   +'TEdit'#8'edBackup'#4'Left'#2'f'#6'Height'#2#21#3'Top'#3#137#0#5'Width'#3'1'
   +#1#7'Anchors'#11#5'akTop'#6'akLeft'#7'akRight'#0#13'OnEditingDone'#7#19'edBa'
   +#1#7'Anchors'#11#5'akTop'#6'akLeft'#7'akRight'#0#13'OnEditingDone'#7#19'edBa'
-  +'ckupEditingDone'#8'TabOrder'#2#3#0#0#12'TSpeedButton'#12'SpeedButton1'#4'Le'
-  +'ft'#3#160#1#6'Height'#2#22#3'Top'#3#133#0#5'Width'#2#23#7'Anchors'#11#5'akT'
-  +'op'#7'akRight'#0#7'Caption'#6#3'...'#7'OnClick'#7#17'SpeedButton1Click'#0#0
-  +#7'TBitBtn'#7'bbStart'#4'Left'#3'b'#1#6'Height'#2'('#3'Top'#3#1#1#5'Width'#3
-  +#131#0#7'Caption'#6#5'Start'#5'Color'#4#219#242#247#0#4'Kind'#7#5'bkAll'#7'O'
-  +'nClick'#7#12'bbStartClick'#8'TabOrder'#2#6#0#0#5'TEdit'#16'edTargetDatabase'
-  +#4'Left'#3#142#0#6'Height'#2#21#3'Top'#2'V'#5'Width'#3#8#1#7'Anchors'#11#5'a'
-  +'kTop'#6'akLeft'#7'akRight'#0#14'ParentBidiMode'#8#13'OnEditingDone'#7#27'ed'
-  +'TargetDatabaseEditingDone'#8'TabOrder'#2#2#0#0#12'TSpeedButton'#16'sbBrowse'
-  +'Targetdb'#4'Left'#3#160#1#6'Height'#2#22#3'Top'#2'U'#5'Width'#2#23#7'Anchor'
-  +'s'#11#5'akTop'#7'akRight'#0#7'Caption'#6#3'...'#7'OnClick'#7#21'sbBrowseTar'
-  +'getdbClick'#0#0#6'TLabel'#6'Label4'#4'Left'#2#14#6'Height'#2#13#3'Top'#3#176
-  +#0#5'Width'#2'3'#7'Caption'#6#9'User name'#11'ParentColor'#8#0#0#5'TEdit'#10
-  +'edUserName'#4'Left'#2'f'#6'Height'#2#21#3'Top'#3#176#0#5'Width'#3#145#0#8'T'
-  +'abOrder'#2#4#0#0#6'TLabel'#6'Label5'#4'Left'#2#12#6'Height'#2#13#3'Top'#3
-  +#216#0#5'Width'#2'.'#7'Caption'#6#8'Password'#11'ParentColor'#8#0#0#5'TEdit'
-  +#10'edPassword'#4'Left'#2'f'#6'Height'#2#21#3'Top'#3#216#0#5'Width'#3#145#0#8
-  +'EchoMode'#7#10'emPassword'#12'PasswordChar'#6#1'-'#8'TabOrder'#2#5#0#0#6'TL'
-  +'abel'#6'Label6'#4'Left'#2#14#6'Height'#2#13#3'Top'#2'0'#5'Width'#2#22#7'Cap'
-  +'tion'#6#4'Host'#11'ParentColor'#8#0#0#5'TEdit'#6'edHost'#4'Left'#3#142#0#6
-  +'Height'#2#21#3'Top'#2'0'#5'Width'#3#6#1#7'Anchors'#11#5'akTop'#6'akLeft'#7
-  +'akRight'#0#14'ParentBidiMode'#8#8'TabOrder'#2#1#0#0#6'TImage'#6'Image1'#4'L'
-  +'eft'#3#152#1#6'Height'#2'L'#3'Top'#2#0#5'Width'#2'O'#12'Picture.Data'#10#166
-  +#20#0#0#23'TPortableNetworkGraphic'#138#20#0#0#137'PNG'#13#10#26#10#0#0#0#13
-  +'IHDR'#0#0#0'H'#0#0#0'H'#8#6#0#0#0'U'#237#179'G'#0#0#0#4'sBIT'#8#8#8#8'|'#8
-  +'d'#136#0#0#0#9'pHYs'#0#0#15#146#0#0#15#146#1#4#168'~'#160#0#0#0#25'tEXtSoft'
-  +'ware'#0'www.inkscape.org'#155#238'<'#26#0#0#0#25'tEXtTitle'#0'DataBase (2 B'
-  +'locks)ne'#254#165#0#0#0#24'tEXtAuthor'#0'Jean-Victor Balin'#236'J'#17'L'#0#0
-  +#0'''tEXtDescription'#0'[email protected]'#216#218#231'Q'#0#0#0#24
-  +'tEXtCreation Time'#0'2009-11-09b%w,'#0#0#0'ItEXtCopyright'#0'Public Domain '
-  +'http://creativecommons.org/licenses/publicdomain/Y'#195#254#202#0#0#19#18'I'
-  +'DATx'#156#237'\[l\'#215'u]'#251#156's'#31#243' 9'#148'8|'#201#146'('#217#150
-  +#31#138#31'q\'#191#146'8J'#147#166'V'#13#168'I]'#165#8#144#254#4#133#209'~'
-  +#20'H'#220'&'#1#250#209#140#16#160'('#250#213#244#171'-'#242'B'#2'''m'#245#19
-  +#164'i'#131#166#142#205'8~6'#150#237#216#154#216#150#173'GD'#153#20'9$g'#200
-  +'y'#221#199'9{'#247'c'#134#20')Q'#145'-'#139#164'>'#178#128#11#14'f'#238#229
-  +#217'w'#205#222#251#156#189#206#190'C"'#130#223#226#226'P'#155'm'#192#213#142
-  +#223#18't'#9#152#203#189#240#200#145'''>'#208#138#232'o'#172#179#187#156#181
-  +#131#214#185'^v.t'#206#25#199#142#156'c0;q'#214'9'#235'\'#228#156#173';'#230
-  +#138#136#156#18#197'_'#251#179'?'#253#243#199#175#228#141#172#23'h'#173#28'D'
-  +'D'#4#0#165'R'#137'V'#190#255#208'C'#7'nu"'#255#20''''#209#221#173'V'#203'w'
-  +#206#129#153#225#152#193#29'B'#192#204#157#247#28'/'#191'fv`'#215'='#175'{'
-  +#164#137#181'Z'#211#203'a&x'#228#248#177#211'O'#175#28#167'T*'#9#0#200'U'#144
-  +' '#215'"'#136'>'#253#233'O'#171'J'#165'B{'#246#236'!'#0#248#171'/}'#225'['
-  +#237#168'y'#176#213'l'#249#214#185#229#27'^&'#227'2'#8'Z:'#191#243#158#164
+  +'ckupEditingDone'#8'TabOrder'#2#3#0#0#12'TSpeedButton'#17'sbBroseBackupFile'
+  +#4'Left'#3#160#1#6'Height'#2#22#3'Top'#3#133#0#5'Width'#2#23#7'Anchors'#11#5
+  +'akTop'#7'akRight'#0#7'Caption'#6#3'...'#7'OnClick'#7#22'sbBroseBackupFileCl'
+  +'ick'#0#0#7'TBitBtn'#7'bbStart'#4'Left'#3'b'#1#6'Height'#2'('#3'Top'#3#1#1#5
+  +'Width'#3#131#0#7'Caption'#6#5'Start'#5'Color'#4#219#242#247#0#4'Kind'#7#5'b'
+  +'kAll'#7'OnClick'#7#12'bbStartClick'#8'TabOrder'#2#6#0#0#5'TEdit'#16'edTarge'
+  +'tDatabase'#4'Left'#3#142#0#6'Height'#2#21#3'Top'#2'V'#5'Width'#3#8#1#7'Anch'
+  +'ors'#11#5'akTop'#6'akLeft'#7'akRight'#0#14'ParentBidiMode'#8#13'OnEditingDo'
+  +'ne'#7#27'edTargetDatabaseEditingDone'#8'TabOrder'#2#2#0#0#12'TSpeedButton'
+  +#16'sbBrowseTargetdb'#4'Left'#3#160#1#6'Height'#2#22#3'Top'#2'U'#5'Width'#2
+  +#23#7'Anchors'#11#5'akTop'#7'akRight'#0#7'Caption'#6#3'...'#7'OnClick'#7#21
+  +'sbBrowseTargetdbClick'#0#0#6'TLabel'#6'Label4'#4'Left'#2#14#6'Height'#2#13#3
+  +'Top'#3#176#0#5'Width'#2'3'#7'Caption'#6#9'User name'#11'ParentColor'#8#0#0#5
+  +'TEdit'#10'edUserName'#4'Left'#2'f'#6'Height'#2#21#3'Top'#3#176#0#5'Width'#3
+  +#145#0#8'TabOrder'#2#4#0#0#6'TLabel'#6'Label5'#4'Left'#2#12#6'Height'#2#13#3
+  +'Top'#3#216#0#5'Width'#2'.'#7'Caption'#6#8'Password'#11'ParentColor'#8#0#0#5
+  +'TEdit'#10'edPassword'#4'Left'#2'f'#6'Height'#2#21#3'Top'#3#216#0#5'Width'#3
+  +#145#0#8'EchoMode'#7#10'emPassword'#12'PasswordChar'#6#1'-'#8'TabOrder'#2#5#0
+  +#0#6'TLabel'#6'Label6'#4'Left'#2#14#6'Height'#2#13#3'Top'#2'0'#5'Width'#2#22
+  +#7'Caption'#6#4'Host'#11'ParentColor'#8#0#0#5'TEdit'#6'edHost'#4'Left'#3#142
+  +#0#6'Height'#2#21#3'Top'#2'0'#5'Width'#3#6#1#7'Anchors'#11#5'akTop'#6'akLeft'
+  +#7'akRight'#0#14'ParentBidiMode'#8#8'TabOrder'#2#1#0#0#6'TImage'#6'Image1'#4
+  +'Left'#3#152#1#6'Height'#2'L'#3'Top'#2#0#5'Width'#2'O'#12'Picture.Data'#10
+  +#166#20#0#0#23'TPortableNetworkGraphic'#138#20#0#0#137'PNG'#13#10#26#10#0#0#0
+  +#13'IHDR'#0#0#0'H'#0#0#0'H'#8#6#0#0#0'U'#237#179'G'#0#0#0#4'sBIT'#8#8#8#8'|'
+  +#8'd'#136#0#0#0#9'pHYs'#0#0#15#146#0#0#15#146#1#4#168'~'#160#0#0#0#25'tEXtSo'
+  +'ftware'#0'www.inkscape.org'#155#238'<'#26#0#0#0#25'tEXtTitle'#0'DataBase (2'
+  +' Blocks)ne'#254#165#0#0#0#24'tEXtAuthor'#0'Jean-Victor Balin'#236'J'#17'L'#0
+  +#0#0'''tEXtDescription'#0'[email protected]'#216#218#231'Q'#0#0#0
+  +#24'tEXtCreation Time'#0'2009-11-09b%w,'#0#0#0'ItEXtCopyright'#0'Public Doma'
+  +'in http://creativecommons.org/licenses/publicdomain/Y'#195#254#202#0#0#19#18
+  +'IDATx'#156#237'\[l\'#215'u]'#251#156's'#31#243' 9'#148'8|'#201#146'('#217
+  +#150#31#138#31'q\'#191#146'8J'#147#166'V'#13#168'I]'#165#8#144#254#4#133#209
+  +'~'#20'H'#220'&'#1#250#209#140#16#160'('#250#213#244#171'-'#242'B'#2'''m'#245
+  +#19#164'i'#131#166#142#205'8~6'#150#237#216#154#216#150#173'GD'#153#20'9$g'
+  +#200'y'#221#199'9{'#247'c'#134#20')Q'#145'-'#139#164'>'#178#128#11#14'f'#238
+  +#229#217'w'#205#222#251#156#189#206#190'C"'#130#223#226#226'P'#155'm'#192#213
+  +#142#223#18't'#9#152#203#189#240#200#145'''>'#208#138#232'o'#172#179#187#156
+  +#181#131#214#185'^v.t'#206#25#199#142#156'c0;q'#214'9'#235'\'#228#156#173';'
+  +#230#138#136#156#18#197'_'#251#179'?'#253#243#199#175#228#141#172#23'h'#173
+  +#28'DD'#4#0#165'R'#137'V'#190#255#208'C'#7'nu"'#255#20''''#209#221#173'V'#203
+  +'w'#206#129#153#225#152#193#29'B'#192#204#157#247#28'/'#191'fv`'#215'='#175
+  +'{'#164#137#181'Z'#211#203'a&x'#228#248#177#211'O'#175#28#167'T*'#9#0#200'U'
+  +#144' '#215'"'#136'>'#253#233'O'#171'J'#165'B{'#246#236'!'#0#248#171'/}'#225
+  +'['#237#168'y'#176#213'l'#249#214#185#229#27'^&'#227'2'#8'Z:'#191#243#158#164
   +#185'\'#246''''#245'Z'#235#161#163'G'#143#242#177'c'#199#164'X,'#202#222#189
   +#185'\'#246''''#245'Z'#235#161#163'G'#143#242#177'c'#199#164'X,'#202#222#189
   +'{'#165'T*'#201'f'#18#181#28'bDD"'#192#161'C%'#221'h4'#244#216#216#24'}'#230
   +'{'#165'T*'#201'f'#18#181#28'bDD"'#192#161'C%'#221'h4'#244#216#216#24'}'#230
   ,'3'#127'4'#186'm'#251#206#23'j'#139#213'~'#231#28#214#207'N'#241#234#139#245
   ,'3'#127'4'#186'm'#251#206#23'j'#139#213'~'#231#28#214#207'N'#241#234#139#245

+ 5 - 3
backuprestore.pas

@@ -34,14 +34,14 @@ type
     meLog: TMemo;
     meLog: TMemo;
     OpenDialog1: TOpenDialog;
     OpenDialog1: TOpenDialog;
     SaveDialog1: TSaveDialog;
     SaveDialog1: TSaveDialog;
-    SpeedButton1: TSpeedButton;
+    sbBroseBackupFile: TSpeedButton;
     sbBrowseTargetdb: TSpeedButton;
     sbBrowseTargetdb: TSpeedButton;
     procedure bbStartClick(Sender: TObject);
     procedure bbStartClick(Sender: TObject);
     procedure edBackupEditingDone(Sender: TObject);
     procedure edBackupEditingDone(Sender: TObject);
     procedure edTargetDatabaseEditingDone(Sender: TObject);
     procedure edTargetDatabaseEditingDone(Sender: TObject);
     procedure FormCreate(Sender: TObject);
     procedure FormCreate(Sender: TObject);
     procedure sbBrowseTargetdbClick(Sender: TObject);
     procedure sbBrowseTargetdbClick(Sender: TObject);
-    procedure SpeedButton1Click(Sender: TObject);
+    procedure sbBroseBackupFileClick(Sender: TObject);
   private
   private
     { private declarations }
     { private declarations }
     FDatabase: string; //doesn't really seem to be used anywhere
     FDatabase: string; //doesn't really seem to be used anywhere
@@ -77,7 +77,7 @@ end;
 {$ENDIF}
 {$ENDIF}
 
 
 
 
-procedure TfmBackupRestore.SpeedButton1Click(Sender: TObject);
+procedure TfmBackupRestore.sbBroseBackupFileClick(Sender: TObject);
 begin
 begin
   SaveDialog1.DefaultExt:= '.fbk';
   SaveDialog1.DefaultExt:= '.fbk';
   if ((cbOperation.ItemIndex = 0) and (SaveDialog1.Execute)) or
   if ((cbOperation.ItemIndex = 0) and (SaveDialog1.Execute)) or
@@ -162,6 +162,7 @@ begin
   TempDir:= GetTempDir(false);
   TempDir:= GetTempDir(false);
   FireBirdServices:= TFirebirdServices.Create;
   FireBirdServices:= TFirebirdServices.Create;
   try
   try
+    Screen.Cursor := crHourglass; // inform user of long-running operation
     FireBirdServices.VerboseOutput:= True;
     FireBirdServices.VerboseOutput:= True;
     meLog.Clear;
     meLog.Clear;
     with FireBirdServices do
     with FireBirdServices do
@@ -264,6 +265,7 @@ begin
       end;
       end;
     end;
     end;
   finally
   finally
+    Screen.Cursor := crDefault;
     FireBirdServices.Free;
     FireBirdServices.Free;
   end;
   end;
 end;
 end;

+ 61 - 51
comparison.pas

@@ -6,12 +6,8 @@ interface
 
 
 uses
 uses
   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
-  Buttons, ComCtrls, IBConnection, sqldb, QueryWindow, LCLType;
+  Buttons, ComCtrls, IBConnection, sqldb, QueryWindow, LCLType, turbocommon;
 
 
-const
-  NumObjects = 13; //number of different objects in dbObjects array below
-  dbObjects: array [1 .. NumObjects] of string = ('Tables', 'Generators', 'Triggers', 'Views', 'Stored Procedures', 'UDFs',
-    'Sys Tables', 'Domains', 'Roles', 'Exceptions', 'Users', 'Indices', 'Constraints');
 
 
 type
 type
 
 
@@ -582,42 +578,51 @@ procedure TfmComparison.CheckMissingDBObjects;
 var
 var
   List, ComparedList: TStringList;
   List, ComparedList: TStringList;
   Count: Integer;
   Count: Integer;
-  x, i: Integer;
+  ObjectType: TObjectType;
+  i: Integer;
 begin
 begin
   List:= TStringList.Create;
   List:= TStringList.Create;
   ComparedList:= TStringList.Create;
   ComparedList:= TStringList.Create;
   try
   try
-    for x:= 1 to 11 do
-    if ((x = 1) and cxTables.Checked) or
-       ((x = 2) and cxGenerators.Checked) or
-       ((x = 3) and cxTriggers.Checked) or
-       ((x = 4) and cxViews.Checked) or
-       ((x = 5) and cxStoredProcs.Checked) or
-       ((x = 6) and cxUDFs.Checked) or
-       ((x = 8) and cxDomains.Checked) or
-       ((x = 9) and cxRoles.Checked) then
+    for ObjectType:= Low(TObjectType) to High(TObjectType) do
     begin
     begin
-      meLog.Lines.Add('');
-      meLog.Lines.Add('Checking Missing ' + dbObjects[x] + ':');
-
-      List.CommaText:= dmSysTables.GetDBObjectNames(FDBIndex, x, Count);
-
-      Application.ProcessMessages;
-      if FCanceled then
-        Exit;
-      ComparedList.CommaText:= dmSysTables.GetDBObjectNames(cbComparedDatabase.ItemIndex, x, Count);
-      FDBObjectsList[x].Clear;
-      FDBExistingObjectsList[x].Clear;
-      for i:= 0 to List.Count -1 do
-      if ComparedList.IndexOf(List[i]) = -1 then  // Not exist
+      if ((ObjectType = otTables) and cxTables.Checked) or
+         ((ObjectType = otGenerators) and cxGenerators.Checked) or
+         ((ObjectType = otTriggers) and cxTriggers.Checked) or
+         ((ObjectType = otViews) and cxViews.Checked) or
+         ((ObjectType = otStoredProcedures) and cxStoredProcs.Checked) or
+         ((ObjectType = otUDF) and cxUDFs.Checked) or
+         {otSystemTables: system tables are not compared }
+         ((ObjectType = otDomains) and cxDomains.Checked) or
+         ((ObjectType = otRoles) and cxRoles.Checked)
+         {otExceptions, otUsers are not checked;
+         constraints and indexes probably indirectly}
+         //todo: check otExceptions in CheckMissingDBObjects
+         then
       begin
       begin
-        meLog.Lines.Add(' ' + List[i]);
-        FDBObjectsList[x].Add(List[i]);
-        Inc(FDiffCount);
-      end
-      else                                        // Exist
-        FDBExistingObjectsList[x].Add(List[i]);
+        meLog.Lines.Add('');
+        meLog.Lines.Add('Checking Missing ' + dbObjects[ord(ObjectType)] + ':');
+
+        List.CommaText:= dmSysTables.GetDBObjectNames(FDBIndex, ObjectType, Count);
 
 
+        Application.ProcessMessages;
+        if FCanceled then
+          Exit;
+        ComparedList.CommaText:= dmSysTables.GetDBObjectNames(cbComparedDatabase.ItemIndex, ObjectType, Count);
+        FDBObjectsList[ord(ObjectType)].Clear;
+        FDBExistingObjectsList[ord(ObjectType)].Clear;
+        for i:= 0 to List.Count -1 do
+        begin
+          if ComparedList.IndexOf(List[i]) = -1 then  // Does not exist
+          begin
+            meLog.Lines.Add(' ' + List[i]);
+            FDBObjectsList[ord(ObjectType)].Add(List[i]);
+            Inc(FDiffCount);
+          end
+          else                                        // Exists
+            FDBExistingObjectsList[ord(ObjectType)].Add(List[i]);
+        end;
+      end;
     end;
     end;
     laScript.Enabled:= True;
     laScript.Enabled:= True;
   finally
   finally
@@ -630,36 +635,41 @@ procedure TfmComparison.CheckRemovedDBObjects;
 var
 var
   List, ComparedList: TStringList;
   List, ComparedList: TStringList;
   Count: Integer;
   Count: Integer;
-  x, i: Integer;
+  ObjectType: TObjectType;
+  i: Integer;
 begin
 begin
   List:= TStringList.Create;
   List:= TStringList.Create;
   ComparedList:= TStringList.Create;
   ComparedList:= TStringList.Create;
   try
   try
-    for x:= 1 to 11 do
-    if ((x = 1) and cxTables.Checked) or
-       ((x = 2) and cxGenerators.Checked) or
-       ((x = 3) and cxTriggers.Checked) or
-       ((x = 4) and cxViews.Checked) or
-       ((x = 5) and cxStoredProcs.Checked) or
-       ((x = 6) and cxUDFs.Checked) or
-       ((x = 8) and cxDomains.Checked) then
+    for ObjectType:= Low(TObjectType) to High(TObjectType) do
+    if ((ObjectType = otTables) and cxTables.Checked) or
+       ((ObjectType = otGenerators) and cxGenerators.Checked) or
+       ((ObjectType = otTriggers) and cxTriggers.Checked) or
+       ((ObjectType = otViews) and cxViews.Checked) or
+       ((ObjectType = otStoredProcedures) and cxStoredProcs.Checked) or
+       ((ObjectType = otUDF) and cxUDFs.Checked) or
+       {otSystemTables: system tables are not compared }
+       ((ObjectType = otDomains) and cxDomains.Checked)
+       {otRoles, otExceptions, otUsers are not checked;
+         constraints and indexes probably indirectly}
+       //todo: check otExceptions in CheckRemovedDBObjects
+       then
     begin
     begin
       meLog.Lines.Add('');
       meLog.Lines.Add('');
-      meLog.Lines.Add('Checking Removed ' + dbObjects[x] + ':');
+      meLog.Lines.Add('Checking Removed ' + dbObjects[ord(ObjectType)] + ':');
 
 
-      List.CommaText:= dmSysTables.GetDBObjectNames(FDBIndex, x, Count);
+      List.CommaText:= dmSysTables.GetDBObjectNames(FDBIndex, ObjectType, Count);
 
 
-      ComparedList.CommaText:= dmSysTables.GetDBObjectNames(cbComparedDatabase.ItemIndex, x, Count);
-      FDBRemovedObjectsList[x].Clear;
+      ComparedList.CommaText:= dmSysTables.GetDBObjectNames(cbComparedDatabase.ItemIndex, ObjectType, Count);
+      FDBRemovedObjectsList[ord(ObjectType)].Clear;
 
 
       for i:= 0 to ComparedList.Count -1 do
       for i:= 0 to ComparedList.Count -1 do
       if List.IndexOf(ComparedList[i]) = -1 then  // Removed
       if List.IndexOf(ComparedList[i]) = -1 then  // Removed
       begin
       begin
         meLog.Lines.Add(' ' + ComparedList[i]);
         meLog.Lines.Add(' ' + ComparedList[i]);
-        FDBRemovedObjectsList[x].Add(ComparedList[i]);
+        FDBRemovedObjectsList[ord(ObjectType)].Add(ComparedList[i]);
         Inc(FDiffCount);
         Inc(FDiffCount);
       end;
       end;
-
     end;
     end;
     CheckRemovedIndices;
     CheckRemovedIndices;
     CheckRemovedConstraints;
     CheckRemovedConstraints;
@@ -1885,7 +1895,7 @@ begin
   ComparedList:= TStringList.Create;
   ComparedList:= TStringList.Create;
   TablesList:= TStringList.Create;
   TablesList:= TStringList.Create;
   try
   try
-    TablesList.CommaText:= dmSysTables.GetDBObjectNames(FDBIndex, 1, Count);
+    TablesList.CommaText:= dmSysTables.GetDBObjectNames(FDBIndex, otTables, Count);
 
 
     meLog.Lines.Add('');
     meLog.Lines.Add('');
     meLog.Lines.Add('Missing Indices:');
     meLog.Lines.Add('Missing Indices:');
@@ -1948,7 +1958,7 @@ begin
   ComparedList:= TStringList.Create;
   ComparedList:= TStringList.Create;
   TablesList:= TStringList.Create;
   TablesList:= TStringList.Create;
   try
   try
-    TablesList.CommaText:= dmSysTables.GetDBObjectNames(FDBIndex, 1, Count);
+    TablesList.CommaText:= dmSysTables.GetDBObjectNames(FDBIndex, otTables, Count);
     FExistConstraintsList.Clear;
     FExistConstraintsList.Clear;
 
 
     meLog.Lines.Add('');
     meLog.Lines.Add('');

+ 4 - 3
copytable.pas

@@ -6,7 +6,7 @@ interface
 
 
 uses
 uses
   Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
   Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
-  StdCtrls, Buttons, SynEdit, SynHighlighterSQL, sqldb;
+  StdCtrls, Buttons, SynEdit, SynHighlighterSQL, sqldb, turbocommon;
 
 
 type
 type
 
 
@@ -56,7 +56,7 @@ begin
   laDatabase.Caption:= fmMain.RegisteredDatabases[cbDestDatabase.ItemIndex].RegRec.DatabaseName;
   laDatabase.Caption:= fmMain.RegisteredDatabases[cbDestDatabase.ItemIndex].RegRec.DatabaseName;
   cbDestDatabase.SetFocus;
   cbDestDatabase.SetFocus;
   dmSysTables.Init(cbDestDatabase.ItemIndex);
   dmSysTables.Init(cbDestDatabase.ItemIndex);
-  cbDestTable.Items.CommaText:= dmSysTables.GetDBObjectNames(cbDestDatabase.ItemIndex, 0, count);
+  cbDestTable.Items.CommaText:= dmSysTables.GetDBObjectNames(cbDestDatabase.ItemIndex, otTables, count);
   if cbDestTable.Items.IndexOf(cbSourceTable.Text) <> -1 then
   if cbDestTable.Items.IndexOf(cbSourceTable.Text) <> -1 then
     cbDestTable.Text:= cbSourceTable.Text;
     cbDestTable.Text:= cbSourceTable.Text;
 end;
 end;
@@ -184,7 +184,8 @@ begin
   for i:= 0 to High(fmMain.RegisteredDatabases) do
   for i:= 0 to High(fmMain.RegisteredDatabases) do
     cbDestDatabase.Items.Add(fmMain.RegisteredDatabases[i].RegRec.Title);
     cbDestDatabase.Items.Add(fmMain.RegisteredDatabases[i].RegRec.Title);
   laDatabase.Caption:= '';
   laDatabase.Caption:= '';
-  cbSourceTable.Items.CommaText:= dmSysTables.GetDBObjectNames(SourceIndex, 1, count);
+
+  cbSourceTable.Items.CommaText:= dmSysTables.GetDBObjectNames(SourceIndex, otTables, count);
   cbSourceTable.Text:= ATableName;
   cbSourceTable.Text:= ATableName;
   SynSQLSyn1.TableNames.Text:= cbSourceTable.Text;
   SynSQLSyn1.TableNames.Text:= cbSourceTable.Text;
   cbSourceTableChange(nil);
   cbSourceTableChange(nil);

+ 2 - 2
createuser.pas

@@ -6,7 +6,7 @@ interface
 
 
 uses
 uses
   Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
   Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
-  StdCtrls, Buttons, ExtCtrls;
+  StdCtrls, Buttons, ExtCtrls, turbocommon;
 
 
 type
 type
 
 
@@ -49,7 +49,7 @@ procedure TfmCreateUser.Init(dbIndex: Integer);
 var
 var
   Count: Integer;
   Count: Integer;
 begin
 begin
-  cbRoles.Items.CommaText:= dmSysTables.GetDBObjectNames(dbIndex, 9, Count);
+  cbRoles.Items.CommaText:= dmSysTables.GetDBObjectNames(dbIndex, otRoles, Count);
 end;
 end;
 
 
 initialization
 initialization

+ 16 - 21
main.pas

@@ -708,7 +708,7 @@ begin
   // So check SavePassword instead of Password itself.
   // So check SavePassword instead of Password itself.
   if (ForceConnectDialog=false) and Rec.SavePassword then
   if (ForceConnectDialog=false) and Rec.SavePassword then
   try
   try
-    fmEnterPass.cbRole.Items.CommaText:= dmSysTables.GetDBObjectNames(dbIndex, 9, Count);
+    fmEnterPass.cbRole.Items.CommaText:= dmSysTables.GetDBObjectNames(dbIndex, otRoles, Count);
     fmEnterPass.cbRole.ItemIndex:= -1;
     fmEnterPass.cbRole.ItemIndex:= -1;
     fmEnterPass.cbRole.Text:= '';
     fmEnterPass.cbRole.Text:= '';
     Result:= True; //this works, no need to go through a retry attempt below
     Result:= True; //this works, no need to go through a retry attempt below
@@ -921,7 +921,7 @@ begin
   SelNode:= tvMain.Selected;
   SelNode:= tvMain.Selected;
   DBIndex:= SelNode.Parent.OverlayIndex;
   DBIndex:= SelNode.Parent.OverlayIndex;
 
 
-  TableNames:= dmSysTables.GetDBObjectNames(DBIndex, 1, Count);
+  TableNames:= dmSysTables.GetDBObjectNames(DBIndex, otTables, Count);
   fmCreateTrigger.cbTables.Items.CommaText:= TableNames;
   fmCreateTrigger.cbTables.Items.CommaText:= TableNames;
   CreateNewTrigger(DBIndex, '');
   CreateNewTrigger(DBIndex, '');
 end;
 end;
@@ -1640,7 +1640,7 @@ begin
   begin
   begin
     fmEnterPass.edPassword.Clear;
     fmEnterPass.edPassword.Clear;
     try
     try
-      fmEnterPass.cbRole.Items.CommaText:= dmSysTables.GetDBObjectNames(dbIndex, 9, Count);
+      fmEnterPass.cbRole.Items.CommaText:= dmSysTables.GetDBObjectNames(dbIndex, otRoles, Count);
     except
     except
     end;
     end;
     if fmEnterPass.ShowModal = mrOk then
     if fmEnterPass.ShowModal = mrOk then
@@ -2873,7 +2873,7 @@ begin
       // Tables
       // Tables
       if ANodeText = 'Tables' then
       if ANodeText = 'Tables' then
       begin
       begin
-        Objects.CommaText:= dmSysTables.GetDBObjectNames(DBIndex, 1, Count);
+        Objects.CommaText:= dmSysTables.GetDBObjectNames(DBIndex, otTables, Count);
         TableNode:= Node;
         TableNode:= Node;
         Node.Text:= ANodeText + ' (' + IntToStr(Count) + ')';
         Node.Text:= ANodeText + ' (' + IntToStr(Count) + ')';
 
 
@@ -2892,7 +2892,7 @@ begin
       if ANodeText = 'Generators' then
       if ANodeText = 'Generators' then
       begin
       begin
         GenNode:= Node;
         GenNode:= Node;
-        Objects.CommaText:= dmSysTables.GetDBObjectNames(DBIndex, 2, Count);
+        Objects.CommaText:= dmSysTables.GetDBObjectNames(DBIndex, otGenerators, Count);
         Node.Text:= ANodeText + ' (' + IntToStr(Count) + ')';
         Node.Text:= ANodeText + ' (' + IntToStr(Count) + ')';
         GenNode.DeleteChildren;
         GenNode.DeleteChildren;
         for i:= 0 to Objects.Count - 1 do
         for i:= 0 to Objects.Count - 1 do
@@ -2908,7 +2908,7 @@ begin
       if Node.Text = 'Triggers' then
       if Node.Text = 'Triggers' then
       begin
       begin
         TrigNode:= Node;
         TrigNode:= Node;
-        Objects.CommaText:= dmSysTables.GetDBObjectNames(DBIndex, 3, Count);
+        Objects.CommaText:= dmSysTables.GetDBObjectNames(DBIndex, otTriggers, Count);
         Node.Text:= ANodeText + ' (' + IntToStr(Count) + ')';
         Node.Text:= ANodeText + ' (' + IntToStr(Count) + ')';
         TrigNode.DeleteChildren;
         TrigNode.DeleteChildren;
         for i:= 0 to Objects.Count - 1 do
         for i:= 0 to Objects.Count - 1 do
@@ -2917,14 +2917,13 @@ begin
           Item.ImageIndex:= 8;
           Item.ImageIndex:= 8;
           Item.SelectedIndex:= 8;
           Item.SelectedIndex:= 8;
         end;
         end;
-
       end
       end
       else
       else
         // Views
         // Views
       if Node.Text = 'Views' then
       if Node.Text = 'Views' then
       begin
       begin
         ViewsNode:= Node;
         ViewsNode:= Node;
-        Objects.CommaText:= dmSysTables.GetDBObjectNames(DBIndex, 4, Count);
+        Objects.CommaText:= dmSysTables.GetDBObjectNames(DBIndex, otViews, Count);
         Node.Text:= ANodeText + ' (' + IntToStr(Count) + ')';
         Node.Text:= ANodeText + ' (' + IntToStr(Count) + ')';
         ViewsNode.DeleteChildren;
         ViewsNode.DeleteChildren;
         for i:= 0 to Objects.Count - 1 do
         for i:= 0 to Objects.Count - 1 do
@@ -2933,14 +2932,13 @@ begin
           Item.ImageIndex:= 10;
           Item.ImageIndex:= 10;
           Item.SelectedIndex:= 10;
           Item.SelectedIndex:= 10;
         end;
         end;
-
       end
       end
       else
       else
         // Stored Procedures
         // Stored Procedures
       if Node.Text = 'Stored Procedures' then
       if Node.Text = 'Stored Procedures' then
       begin
       begin
         StoredProcNode:= Node;
         StoredProcNode:= Node;
-        Objects.CommaText:= dmSysTables.GetDBObjectNames(DBIndex, 5, Count);
+        Objects.CommaText:= dmSysTables.GetDBObjectNames(DBIndex, otStoredProcedures, Count);
         Node.Text:= ANodeText + ' (' + IntToStr(Count) + ')';
         Node.Text:= ANodeText + ' (' + IntToStr(Count) + ')';
         StoredProcNode.DeleteChildren;
         StoredProcNode.DeleteChildren;
         for i:= 0 to Objects.Count - 1 do
         for i:= 0 to Objects.Count - 1 do
@@ -2949,14 +2947,13 @@ begin
           Item.ImageIndex:= 12;
           Item.ImageIndex:= 12;
           Item.SelectedIndex:= 12;
           Item.SelectedIndex:= 12;
         end;
         end;
-
       end
       end
       else
       else
         // UDF (Functions)
         // UDF (Functions)
       if Node.Text = 'Functions' then
       if Node.Text = 'Functions' then
       begin
       begin
         UDFNode:= Node;
         UDFNode:= Node;
-        Objects.CommaText:= dmSysTables.GetDBObjectNames(DBIndex, 6, Count);
+        Objects.CommaText:= dmSysTables.GetDBObjectNames(DBIndex, otUDF, Count);
         Node.Text:= ANodeText + ' (' + IntToStr(Count) + ')';
         Node.Text:= ANodeText + ' (' + IntToStr(Count) + ')';
         UDFNode.DeleteChildren;
         UDFNode.DeleteChildren;
         for i:= 0 to Objects.Count - 1 do
         for i:= 0 to Objects.Count - 1 do
@@ -2965,14 +2962,13 @@ begin
           Item.ImageIndex:= 14;
           Item.ImageIndex:= 14;
           Item.SelectedIndex:= 14;
           Item.SelectedIndex:= 14;
         end;
         end;
-
       end
       end
       else
       else
         // System Tables
         // System Tables
       if Node.Text = 'System Tables' then
       if Node.Text = 'System Tables' then
       begin
       begin
         SysTableNode:= Node;
         SysTableNode:= Node;
-        Objects.CommaText:= dmSysTables.GetDBObjectNames(DBIndex, 7, Count);
+        Objects.CommaText:= dmSysTables.GetDBObjectNames(DBIndex, otSystemTables, Count);
         Node.Text:= ANodeText + ' (' + IntToStr(Count) + ')';
         Node.Text:= ANodeText + ' (' + IntToStr(Count) + ')';
         SysTableNode.DeleteChildren;
         SysTableNode.DeleteChildren;
         for i:= 0 to Objects.Count - 1 do
         for i:= 0 to Objects.Count - 1 do
@@ -2981,14 +2977,13 @@ begin
           Item.ImageIndex:= 16;
           Item.ImageIndex:= 16;
           Item.SelectedIndex:= 16;
           Item.SelectedIndex:= 16;
         end;
         end;
-
       end
       end
       else
       else
         // Domains
         // Domains
       if Node.Text = 'Domains' then
       if Node.Text = 'Domains' then
       begin
       begin
         DomainsNode:= Node;
         DomainsNode:= Node;
-        Objects.CommaText:= dmSysTables.GetDBObjectNames(DBIndex, 8, Count);
+        Objects.CommaText:= dmSysTables.GetDBObjectNames(DBIndex, otDomains, Count);
         Node.Text:= ANodeText + ' (' + IntToStr(Count) + ')';
         Node.Text:= ANodeText + ' (' + IntToStr(Count) + ')';
         DomainsNode.DeleteChildren;
         DomainsNode.DeleteChildren;
         for i:= 0 to Objects.Count - 1 do
         for i:= 0 to Objects.Count - 1 do
@@ -2997,14 +2992,13 @@ begin
           Item.ImageIndex:= 18;
           Item.ImageIndex:= 18;
           Item.SelectedIndex:= 18;
           Item.SelectedIndex:= 18;
         end;
         end;
-
       end
       end
       else
       else
         // Roles
         // Roles
       if Node.Text = 'Roles' then
       if Node.Text = 'Roles' then
       begin
       begin
         RoleNode:= Node;
         RoleNode:= Node;
-        Objects.CommaText:= dmSysTables.GetDBObjectNames(DBIndex, 9, Count);
+        Objects.CommaText:= dmSysTables.GetDBObjectNames(DBIndex, otRoles, Count);
         Node.Text:= ANodeText + ' (' + IntToStr(Count) + ')';
         Node.Text:= ANodeText + ' (' + IntToStr(Count) + ')';
         RoleNode.DeleteChildren;
         RoleNode.DeleteChildren;
         for i:= 0 to Objects.Count - 1 do
         for i:= 0 to Objects.Count - 1 do
@@ -3019,7 +3013,7 @@ begin
       if Node.Text = 'Exceptions' then
       if Node.Text = 'Exceptions' then
       begin
       begin
         ExceptionNode:= Node;
         ExceptionNode:= Node;
-        Objects.CommaText:= dmSysTables.GetDBObjectNames(DBIndex, 10, Count);
+        Objects.CommaText:= dmSysTables.GetDBObjectNames(DBIndex, otExceptions, Count);
         Node.Text:= ANodeText + ' (' + IntToStr(Count) + ')';
         Node.Text:= ANodeText + ' (' + IntToStr(Count) + ')';
         ExceptionNode.DeleteChildren;
         ExceptionNode.DeleteChildren;
         for i:= 0 to Objects.Count - 1 do
         for i:= 0 to Objects.Count - 1 do
@@ -3034,7 +3028,7 @@ begin
       if Node.Text = 'Users' then
       if Node.Text = 'Users' then
       begin
       begin
         UserNode:= Node;
         UserNode:= Node;
-        Objects.CommaText:= dmSysTables.GetDBObjectNames(DBIndex, 11, Count);
+        Objects.CommaText:= dmSysTables.GetDBObjectNames(DBIndex, otUsers, Count);
         Node.Text:= ANodeText + ' (' + IntToStr(Count) + ')';
         Node.Text:= ANodeText + ' (' + IntToStr(Count) + ')';
         UserNode.DeleteChildren;
         UserNode.DeleteChildren;
         for i:= 0 to Objects.Count - 1 do
         for i:= 0 to Objects.Count - 1 do
@@ -3981,6 +3975,7 @@ begin
           CNode:= tvMain.Items.AddChild(MainNode, 'Query Window');
           CNode:= tvMain.Items.AddChild(MainNode, 'Query Window');
           CNode.ImageIndex:= 1;
           CNode.ImageIndex:= 1;
           CNode.SelectedIndex:= 1;
           CNode.SelectedIndex:= 1;
+
           CNode:= tvMain.Items.AddChild(MainNode, 'Tables');
           CNode:= tvMain.Items.AddChild(MainNode, 'Tables');
           CNode.ImageIndex:= 2;
           CNode.ImageIndex:= 2;
           CNode.SelectedIndex:= 2;
           CNode.SelectedIndex:= 2;
@@ -4203,7 +4198,7 @@ function TfmMain.GetTableNames(dbIndex: Integer): string;
 var
 var
   Count: Integer;
   Count: Integer;
 begin
 begin
-  Result:= dmSysTables.GetDBObjectNames(dbIndex, 1, Count);
+  Result:= dmSysTables.GetDBObjectNames(dbIndex, otTables, Count);
 end;
 end;
 
 
 initialization
 initialization

+ 1 - 1
newgen.pas

@@ -123,7 +123,7 @@ var
   Count: Integer;
   Count: Integer;
 begin
 begin
   FDBIndex:= dbIndex;
   FDBIndex:= dbIndex;
-  TableNames:= dmSysTables.GetDBObjectNames(dbIndex, 1, Count);
+  TableNames:= dmSysTables.GetDBObjectNames(dbIndex, otTables, Count);
 
 
   fmNewGen.cbTables.Items.CommaText:= TableNames;
   fmNewGen.cbTables.Items.CommaText:= TableNames;
 
 

+ 8 - 7
permissionmanage.pas

@@ -6,7 +6,7 @@ interface
 
 
 uses
 uses
   Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
   Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
-  ComCtrls, StdCtrls, Buttons, CheckLst;
+  ComCtrls, StdCtrls, Buttons, CheckLst, turbocommon;
 
 
 type
 type
 
 
@@ -251,7 +251,7 @@ begin
   clbRoles.Clear;
   clbRoles.Clear;
   if cbRolesUser.Text <> '' then
   if cbRolesUser.Text <> '' then
   begin
   begin
-    clbRoles.Items.CommaText:= dmSysTables.GetDBObjectNames(FDBIndex, 9, Count);
+    clbRoles.Items.CommaText:= dmSysTables.GetDBObjectNames(FDBIndex, otRoles, Count);
     FRoleList.Clear;
     FRoleList.Clear;
     FRoleList.CommaText:= dmSysTables.GetUserObjects(FDBIndex, cbRolesUser.Text, 13);
     FRoleList.CommaText:= dmSysTables.GetUserObjects(FDBIndex, cbRolesUser.Text, 13);
     SetLength(FRoleGrant, clbRoles.Count);
     SetLength(FRoleGrant, clbRoles.Count);
@@ -564,14 +564,15 @@ begin
   PageControl1.ActivePageIndex:= 0;
   PageControl1.ActivePageIndex:= 0;
   FDBIndex := dbIndex;
   FDBIndex := dbIndex;
   cbUsers.Text := AUserName;
   cbUsers.Text := AUserName;
-  cbTables.Items.CommaText:= dmSysTables.GetDBObjectNames(dbIndex, 1, Count);
-  cbViews.Items.CommaText:= dmSysTables.GetDBObjectNames(dbIndex, 4, Count);
+  cbTables.Items.CommaText:= dmSysTables.GetDBObjectNames(dbIndex, otTables, Count);
+  cbViews.Items.CommaText:= dmSysTables.GetDBObjectNames(dbIndex, otViews, Count);
   cbTables.Text:= ATableName;
   cbTables.Text:= ATableName;
   cbProcUsers.Text:= AUserName;
   cbProcUsers.Text:= AUserName;
   cbViewsUsers.Text:= AUserName;
   cbViewsUsers.Text:= AUserName;
 
 
-  cbUsers.Items.CommaText:= dmSysTables.GetDBObjectNames(dbIndex, 9, Count) + ',' +
-    dmSysTables.GetDBObjectNames(dbIndex, 11, Count);
+  // For users, add roles and users
+  cbUsers.Items.CommaText:= dmSysTables.GetDBObjectNames(dbIndex, otRoles, Count) + ',' +
+    dmSysTables.GetDBObjectNames(dbIndex, otUsers, Count);
   cbProcUsers.Items.CommaText:= cbUsers.Items.CommaText;
   cbProcUsers.Items.CommaText:= cbUsers.Items.CommaText;
   cbViewsUsers.Items.CommaText:= cbUsers.Items.CommaText;
   cbViewsUsers.Items.CommaText:= cbUsers.Items.CommaText;
 
 
@@ -590,7 +591,7 @@ begin
     cbRolesUser.Text:= AUserName;
     cbRolesUser.Text:= AUserName;
     UpdateRolePermissions;
     UpdateRolePermissions;
   end;
   end;
-  cbRolesUser.Items.CommaText:= dmSysTables.GetDBObjectNames(dbIndex, 11, Count);
+  cbRolesUser.Items.CommaText:= dmSysTables.GetDBObjectNames(dbIndex, otUsers, Count);
 end;
 end;
 
 
 initialization
 initialization

+ 11 - 11
scriptdb.pas

@@ -73,7 +73,7 @@ var
   Count: Integer;
   Count: Integer;
   i: Integer;
   i: Integer;
 begin
 begin
-  List.CommaText:= dmSysTables.GetDBObjectNames(dbIndex, 9, Count);
+  List.CommaText:= dmSysTables.GetDBObjectNames(dbIndex, otRoles, Count);
   { todo: (low priority) wrap create role RDB$Admin statement - in FB 2.5+ this role is present
   { todo: (low priority) wrap create role RDB$Admin statement - in FB 2.5+ this role is present
   by default, in lower dbs it isn't. No way to find out in advance when writing
   by default, in lower dbs it isn't. No way to find out in advance when writing
   a script. No support in FB yet for CREATE OR UPDATE ROLE so probably best
   a script. No support in FB yet for CREATE OR UPDATE ROLE so probably best
@@ -109,7 +109,7 @@ var
   ModuleName, EntryPoint, Params: string;
   ModuleName, EntryPoint, Params: string;
 begin
 begin
   FunctionsList:= TStringList.Create;
   FunctionsList:= TStringList.Create;
-  FunctionsList.CommaText:= dmSysTables.GetDBObjectNames(dbIndex, 6, Count);
+  FunctionsList.CommaText:= dmSysTables.GetDBObjectNames(dbIndex, otUDF, Count);
   // Get functions in dependency order:
   // Get functions in dependency order:
   dmSysTables.SortDependencies(FunctionsList);
   dmSysTables.SortDependencies(FunctionsList);
   List.Clear;
   List.Clear;
@@ -139,7 +139,7 @@ var
   Description,Message: string; {not actually used here}
   Description,Message: string; {not actually used here}
   i: Integer;
   i: Integer;
 begin
 begin
-  List.CommaText:= dmSysTables.GetDBObjectNames(dbIndex, 10, Count);
+  List.CommaText:= dmSysTables.GetDBObjectNames(dbIndex, otExceptions, Count);
   for i:= 0 to List.Count - 1 do
   for i:= 0 to List.Count - 1 do
   begin
   begin
     dmSysTables.GetExceptionInfo(List[i],Message, Description, CreateStatement);
     dmSysTables.GetExceptionInfo(List[i],Message, Description, CreateStatement);
@@ -155,7 +155,7 @@ var
   Count: Integer;
   Count: Integer;
   i: Integer;
   i: Integer;
 begin
 begin
-  List.CommaText:= dmSysTables.GetDBObjectNames(dbIndex, 2, Count);
+  List.CommaText:= dmSysTables.GetDBObjectNames(dbIndex, otGenerators, Count);
   for i:= 0 to List.Count - 1 do
   for i:= 0 to List.Count - 1 do
     List[i]:= 'Create Generator ' + List[i] + ' ;';
     List[i]:= 'Create Generator ' + List[i] + ' ;';
   Result:= List.Count > 0;
   Result:= List.Count > 0;
@@ -175,7 +175,7 @@ var
   CheckConstraint: string;
   CheckConstraint: string;
   DefaultValue: string;
   DefaultValue: string;
 begin
 begin
-  List.CommaText:= dmSysTables.GetDBObjectNames(dbIndex, 8, Count);
+  List.CommaText:= dmSysTables.GetDBObjectNames(dbIndex, otDomains, Count);
   // Get domains in dependency order (if dependencies can exist between domains)
   // Get domains in dependency order (if dependencies can exist between domains)
   dmSysTables.SortDependencies(List);
   dmSysTables.SortDependencies(List);
   for i:= 0 to List.Count - 1 do
   for i:= 0 to List.Count - 1 do
@@ -350,7 +350,7 @@ begin
   TablesList:= TStringList.Create;
   TablesList:= TStringList.Create;
   TableScript:= TStringList.Create;
   TableScript:= TStringList.Create;
   try
   try
-    TablesList.CommaText:= dmSysTables.GetDBObjectNames(dbIndex, 1, Count);
+    TablesList.CommaText:= dmSysTables.GetDBObjectNames(dbIndex, otTables, Count);
     List.Clear;
     List.Clear;
     for i:= 0 to TablesList.Count - 1 do
     for i:= 0 to TablesList.Count - 1 do
     begin
     begin
@@ -378,7 +378,7 @@ begin
   ProceduresList:= TStringList.Create;
   ProceduresList:= TStringList.Create;
   ProcedureScript:= TStringList.Create;
   ProcedureScript:= TStringList.Create;
   try
   try
-    ProceduresList.CommaText:= dmSysTables.GetDBObjectNames(dbIndex, 5, Count);
+    ProceduresList.CommaText:= dmSysTables.GetDBObjectNames(dbIndex, otStoredProcedures, Count);
     // Get procedures in dependency order:
     // Get procedures in dependency order:
     dmSysTables.SortDependencies(ProceduresList);
     dmSysTables.SortDependencies(ProceduresList);
     List.Clear;
     List.Clear;
@@ -415,7 +415,7 @@ begin
   ViewsList:= TStringList.Create;
   ViewsList:= TStringList.Create;
   ViewsBodyList:= TStringList.Create;
   ViewsBodyList:= TStringList.Create;
   try
   try
-    ViewsList.CommaText:= dmSysTables.GetDBObjectNames(dbIndex, 4, Count);
+    ViewsList.CommaText:= dmSysTables.GetDBObjectNames(dbIndex, otViews, Count);
     // Get procedures in dependency order:
     // Get procedures in dependency order:
     dmSysTables.SortDependencies(ViewsList);
     dmSysTables.SortDependencies(ViewsList);
     List.Clear;
     List.Clear;
@@ -448,7 +448,7 @@ begin
   TriggersList:= TStringList.Create;
   TriggersList:= TStringList.Create;
   TriggerScript:= TStringList.Create;
   TriggerScript:= TStringList.Create;
   try
   try
-    TriggersList.CommaText:= dmSysTables.GetDBObjectNames(dbIndex, 3, Count);
+    TriggersList.CommaText:= dmSysTables.GetDBObjectNames(dbIndex, otTriggers, Count);
     List.Clear;
     List.Clear;
     for i:= 0 to TriggersList.Count - 1 do
     for i:= 0 to TriggersList.Count - 1 do
     begin
     begin
@@ -479,7 +479,7 @@ begin
   TablesList:= TStringList.Create;
   TablesList:= TStringList.Create;
   FieldsList:= TStringList.Create;
   FieldsList:= TStringList.Create;
   try
   try
-    TablesList.CommaText:= dmSysTables.GetDBObjectNames(dbIndex, 1, Count);
+    TablesList.CommaText:= dmSysTables.GetDBObjectNames(dbIndex, otTables, Count);
     List.Clear;
     List.Clear;
     for i:= 0 to TablesList.Count - 1 do
     for i:= 0 to TablesList.Count - 1 do
     begin
     begin
@@ -585,7 +585,7 @@ var
 begin
 begin
   TablesList:= TStringList.Create;
   TablesList:= TStringList.Create;
   try
   try
-    TablesList.CommaText:= dmSysTables.GetDBObjectNames(dbIndex, 1, Count);
+    TablesList.CommaText:= dmSysTables.GetDBObjectNames(dbIndex, otTables, Count);
     // Get tables in dependency order - probably won't matter much in this case:
     // Get tables in dependency order - probably won't matter much in this case:
     dmSysTables.SortDependencies(TablesList);
     dmSysTables.SortDependencies(TablesList);
     List.Clear;
     List.Clear;

+ 15 - 14
systables.pas

@@ -35,7 +35,7 @@ type
     procedure Init(dbIndex: Integer);
     procedure Init(dbIndex: Integer);
     // Gets list of object names that have type specified by TVIndex
     // Gets list of object names that have type specified by TVIndex
     // Returns Count of objects in Count
     // Returns Count of objects in Count
-    function GetDBObjectNames(DatabaseIndex, TVIndex: Integer; var Count: Integer): string;
+    function GetDBObjectNames(DatabaseIndex: integer; ObjectType: TObjectType; var Count: Integer): string;
     // Returns object list (list of object names, i.e. tables, views) sorted by dependency
     // Returns object list (list of object names, i.e. tables, views) sorted by dependency
     // Limits sorting within one category (e.g. views)
     // Limits sorting within one category (e.g. views)
     procedure SortDependencies(var ObjectList: TStringList);
     procedure SortDependencies(var ObjectList: TStringList);
@@ -155,44 +155,45 @@ end;
 
 
 (*****  GetDBObjectNames, like Table names, Triggers, Generators, etc according to TVIndex  ****)
 (*****  GetDBObjectNames, like Table names, Triggers, Generators, etc according to TVIndex  ****)
 
 
-function TdmSysTables.GetDBObjectNames(DatabaseIndex, TVIndex: Integer;
+function TdmSysTables.GetDBObjectNames(DatabaseIndex: integer;
+  ObjectType: TObjectType;
   var Count: Integer): string;
   var Count: Integer): string;
 begin
 begin
   Init(DatabaseIndex);
   Init(DatabaseIndex);
   sqQuery.Close;
   sqQuery.Close;
-  if TVIndex = 1 then // Tables
+  if ObjectType = otTables then // Tables
     sqQuery.SQL.Text:= 'select rdb$relation_name from rdb$relations where rdb$view_blr is null ' +
     sqQuery.SQL.Text:= 'select rdb$relation_name from rdb$relations where rdb$view_blr is null ' +
       ' and (rdb$system_flag is null or rdb$system_flag = 0) order by rdb$relation_name'
       ' and (rdb$system_flag is null or rdb$system_flag = 0) order by rdb$relation_name'
   else
   else
-  if TVIndex = 2 then // Generators
+  if ObjectType = otGenerators then // Generators
     sqQuery.SQL.Text:= 'select RDB$GENERATOR_Name from RDB$GENERATORS where RDB$SYSTEM_FLAG = 0 order by rdb$generator_Name'
     sqQuery.SQL.Text:= 'select RDB$GENERATOR_Name from RDB$GENERATORS where RDB$SYSTEM_FLAG = 0 order by rdb$generator_Name'
   else
   else
-  if TVIndex = 3 then // Triggers
+  if ObjectType = otTriggers then // Triggers
     sqQuery.SQL.Text:= 'SELECT rdb$Trigger_Name FROM RDB$TRIGGERS WHERE RDB$SYSTEM_FLAG=0 order by rdb$Trigger_Name'
     sqQuery.SQL.Text:= 'SELECT rdb$Trigger_Name FROM RDB$TRIGGERS WHERE RDB$SYSTEM_FLAG=0 order by rdb$Trigger_Name'
   else
   else
-  if TVIndex = 4 then // Views
+  if ObjectType = otViews then // Views
     sqQuery.SQL.Text:= 'SELECT DISTINCT RDB$VIEW_NAME FROM RDB$VIEW_RELATIONS order by rdb$View_Name'
     sqQuery.SQL.Text:= 'SELECT DISTINCT RDB$VIEW_NAME FROM RDB$VIEW_RELATIONS order by rdb$View_Name'
   else
   else
-  if TVIndex = 5 then // Stored Procedures
+  if ObjectType = otStoredProcedures then // Stored Procedures
     sqQuery.SQL.Text:= 'SELECT RDB$Procedure_Name FROM RDB$PROCEDURES order by rdb$Procedure_Name'
     sqQuery.SQL.Text:= 'SELECT RDB$Procedure_Name FROM RDB$PROCEDURES order by rdb$Procedure_Name'
   else
   else
-  if TVIndex = 6 then // UDF
+  if ObjectType = otUDF then // UDF
     sqQuery.SQL.Text:= 'SELECT RDB$FUNCTION_NAME FROM RDB$FUNCTIONS where RDB$SYSTEM_FLAG=0 order by rdb$Function_Name'
     sqQuery.SQL.Text:= 'SELECT RDB$FUNCTION_NAME FROM RDB$FUNCTIONS where RDB$SYSTEM_FLAG=0 order by rdb$Function_Name'
   else
   else
-  if TVIndex = 7 then // System Tables
+  if ObjectType = otSystemTables then // System Tables
     sqQuery.SQL.Text:= 'SELECT RDB$RELATION_NAME FROM RDB$RELATIONS where RDB$SYSTEM_FLAG=1 ' +
     sqQuery.SQL.Text:= 'SELECT RDB$RELATION_NAME FROM RDB$RELATIONS where RDB$SYSTEM_FLAG=1 ' +
       'order by RDB$RELATION_NAME'
       'order by RDB$RELATION_NAME'
   else
   else
-  if TVIndex = 8 then // Domains, excluding system-defined domains
+  if ObjectType = otDomains then // Domains, excluding system-defined domains
     sqQuery.SQL.Text:= 'select RDB$FIELD_NAME from RDB$FIELDS where RDB$Field_Name not like ''RDB$%''  order by rdb$Field_Name'
     sqQuery.SQL.Text:= 'select RDB$FIELD_NAME from RDB$FIELDS where RDB$Field_Name not like ''RDB$%''  order by rdb$Field_Name'
   else
   else
-  if TVIndex = 9 then // Roles
+  if ObjectType = otRoles then // Roles
     sqQuery.SQL.Text:= 'select RDB$ROLE_NAME from RDB$ROLES order by rdb$Role_Name'
     sqQuery.SQL.Text:= 'select RDB$ROLE_NAME from RDB$ROLES order by rdb$Role_Name'
   else
   else
-  if TVIndex = 10 then // Exceptions
+  if ObjectType = otExceptions then // Exceptions
     sqQuery.SQL.Text:= 'select RDB$EXCEPTION_NAME from RDB$EXCEPTIONS order by rdb$Exception_Name'
     sqQuery.SQL.Text:= 'select RDB$EXCEPTION_NAME from RDB$EXCEPTIONS order by rdb$Exception_Name'
   else
   else
-  if TVIndex = 11 then // Users
+  if ObjectType = otUsers then // Users
     sqQuery.SQL.Text:= 'select distinct RDB$User from RDB$USER_PRIVILEGES where RDB$User_Type = 8 order by rdb$User';
     sqQuery.SQL.Text:= 'select distinct RDB$User from RDB$USER_PRIVILEGES where RDB$User_Type = 8 order by rdb$User';
 
 
   // Put the result list as comma delimited string
   // Put the result list as comma delimited string
@@ -846,7 +847,7 @@ procedure TdmSysTables.GetDomainTypes(dbIndex: Integer; List: TStrings);
 var
 var
   Count: Integer;
   Count: Integer;
 begin
 begin
-  List.CommaText:= List.CommaText + ',' + GetDBObjectNames(dbIndex, 8, Count);
+  List.CommaText:= List.CommaText + ',' + GetDBObjectNames(dbIndex, otDomains, Count);
 end;
 end;
 
 
 function TdmSysTables.GetDefaultTypeSize(dbIndex: Integer; TypeName: string): Integer;
 function TdmSysTables.GetDefaultTypeSize(dbIndex: Integer; TypeName: string): Integer;

+ 2 - 2
tablemanage.pas

@@ -6,7 +6,7 @@ interface
 
 
 uses
 uses
   Classes, SysUtils, sqldb, IBConnection, FileUtil, LResources, Forms, Controls,
   Classes, SysUtils, sqldb, IBConnection, FileUtil, LResources, Forms, Controls,
-  Graphics, Dialogs, ComCtrls, Grids, Buttons, StdCtrls, CheckLst, LCLType;
+  Graphics, Dialogs, ComCtrls, Grids, Buttons, StdCtrls, CheckLst, LCLType, turbocommon;
 
 
 type
 type
 
 
@@ -345,7 +345,7 @@ begin
   fmNewConstraint.edNewName.Text:= 'FK_' + FTableName + '_' + IntToStr(sgConstraints.RowCount);
   fmNewConstraint.edNewName.Text:= 'FK_' + FTableName + '_' + IntToStr(sgConstraints.RowCount);
 
 
   // Foreign tables
   // Foreign tables
-  fmNewConstraint.cbTables.Items.CommaText:= dmSysTables.GetDBObjectNames(FDBIndex, 1, Count);
+  fmNewConstraint.cbTables.Items.CommaText:= dmSysTables.GetDBObjectNames(FDBIndex, otTables, Count);
   fmNewConstraint.DatabaseIndex:= FDBIndex;
   fmNewConstraint.DatabaseIndex:= FDBIndex;
 
 
   fmNewConstraint.laTable.Caption:= FTableName;
   fmNewConstraint.laTable.Caption:= FTableName;

+ 30 - 0
turbocommon.pas

@@ -229,6 +229,36 @@ const
     ('WIN_PTBR','WIN1252')
     ('WIN_PTBR','WIN1252')
     );
     );
 
 
+type
+  // Types of objects in database
+  // Note: the order and count must match the array below
+  // Also, do not assign values to the individual enums; code depends
+  // on them starting with 0 and being contiguous
+  TObjectType = (
+    otTables,
+    otGenerators,
+    otTriggers,
+    otViews,
+    otStoredProcedures,
+    otUDF {User-Defined functions},
+    otSystemTables,
+    otDomains {excludes system domains},
+    otRoles,
+    otExceptions,
+    otUsers,
+    otIndexes,
+    otConstraints
+    );
+
+const
+  NumObjects = 13; //number of different objects in dbObjects array below
+  dbObjects: array [0 .. NumObjects-1] of string =
+    ('Tables', 'Generators', 'Triggers',
+    'Views', 'Stored Procedures', 'UDFs',
+    'Sys Tables', 'Domains', 'Roles',
+    'Exceptions', 'Users', 'Indices',
+    'Constraints');
+
 // Retrieve available collations for specified Characterset into Collations
 // Retrieve available collations for specified Characterset into Collations
 function GetCollations(const Characterset: string; var Collations: TStringList): boolean;
 function GetCollations(const Characterset: string; var Collations: TStringList): boolean;