Sfoglia il codice sorgente

Compare constraints
modified: TurboBird.lpi
modified: TurboBird.lpr
modified: comparison.pas
modified: systables.pas

motaz 13 anni fa
parent
commit
3f396c28b4
4 ha cambiato i file con 211 aggiunte e 92 eliminazioni
  1. 61 65
      TurboBird.lpi
  2. 1 1
      TurboBird.lpr
  3. 89 23
      comparison.pas
  4. 60 3
      systables.pas

+ 61 - 65
TurboBird.lpi

@@ -62,8 +62,8 @@
         <UnitName Value="TurboBird"/>
         <EditorIndex Value="1"/>
         <WindowIndex Value="0"/>
-        <TopLine Value="31"/>
-        <CursorPos X="1" Y="51"/>
+        <TopLine Value="1"/>
+        <CursorPos X="33" Y="6"/>
         <UsageCount Value="200"/>
         <Loaded Value="True"/>
       </Unit0>
@@ -449,8 +449,8 @@
         <UnitName Value="SysTables"/>
         <EditorIndex Value="2"/>
         <WindowIndex Value="0"/>
-        <TopLine Value="660"/>
-        <CursorPos X="28" Y="669"/>
+        <TopLine Value="257"/>
+        <CursorPos X="33" Y="267"/>
         <UsageCount Value="200"/>
         <Loaded Value="True"/>
         <LoadedDesigner Value="True"/>
@@ -531,8 +531,8 @@
         <UnitName Value="Scriptdb"/>
         <EditorIndex Value="5"/>
         <WindowIndex Value="0"/>
-        <TopLine Value="356"/>
-        <CursorPos X="1" Y="382"/>
+        <TopLine Value="393"/>
+        <CursorPos X="41" Y="399"/>
         <UsageCount Value="200"/>
         <Loaded Value="True"/>
       </Unit51>
@@ -554,7 +554,7 @@
         <WindowIndex Value="0"/>
         <TopLine Value="6"/>
         <CursorPos X="8" Y="34"/>
-        <UsageCount Value="182"/>
+        <UsageCount Value="185"/>
       </Unit53>
       <Unit54>
         <Filename Value="/usr/lib/lazarus/0.9.29/ide/lazarus.pp"/>
@@ -573,7 +573,7 @@
         <WindowIndex Value="0"/>
         <TopLine Value="303"/>
         <CursorPos X="20" Y="311"/>
-        <UsageCount Value="165"/>
+        <UsageCount Value="168"/>
       </Unit55>
       <Unit56>
         <Filename Value="/usr/lib/lazarus/0.9.29/lcl/grids.pas"/>
@@ -616,7 +616,7 @@
         <WindowIndex Value="0"/>
         <TopLine Value="13"/>
         <CursorPos X="22" Y="54"/>
-        <UsageCount Value="151"/>
+        <UsageCount Value="154"/>
       </Unit60>
       <Unit61>
         <Filename Value="unitfirebirdservices.pas"/>
@@ -682,7 +682,7 @@
         <WindowIndex Value="0"/>
         <TopLine Value="3"/>
         <CursorPos X="71" Y="7"/>
-        <UsageCount Value="121"/>
+        <UsageCount Value="124"/>
       </Unit68>
       <Unit69>
         <Filename Value="changepass.pas"/>
@@ -693,7 +693,7 @@
         <WindowIndex Value="0"/>
         <TopLine Value="3"/>
         <CursorPos X="88" Y="14"/>
-        <UsageCount Value="120"/>
+        <UsageCount Value="123"/>
       </Unit69>
       <Unit70>
         <Filename Value="permissionmanage.pas"/>
@@ -704,7 +704,7 @@
         <WindowIndex Value="0"/>
         <TopLine Value="61"/>
         <CursorPos X="44" Y="83"/>
-        <UsageCount Value="118"/>
+        <UsageCount Value="121"/>
       </Unit70>
       <Unit71>
         <Filename Value="sqlhistory.pas"/>
@@ -715,7 +715,7 @@
         <WindowIndex Value="0"/>
         <TopLine Value="1"/>
         <CursorPos X="18" Y="39"/>
-        <UsageCount Value="103"/>
+        <UsageCount Value="106"/>
       </Unit71>
       <Unit72>
         <Filename Value="../../lazarus/lazarus/lcl/include/menuitem.inc"/>
@@ -740,7 +740,7 @@
         <WindowIndex Value="0"/>
         <TopLine Value="18"/>
         <CursorPos X="1" Y="44"/>
-        <UsageCount Value="74"/>
+        <UsageCount Value="77"/>
       </Unit74>
       <Unit75>
         <Filename Value="/usr/lib/lazarus/0.9.30/lcl/comctrls.pp"/>
@@ -932,7 +932,7 @@
         <WindowIndex Value="0"/>
         <TopLine Value="20"/>
         <CursorPos X="22" Y="41"/>
-        <UsageCount Value="42"/>
+        <UsageCount Value="45"/>
       </Unit98>
       <Unit99>
         <Filename Value="../../FromInternet/fpc2.4/fpc-2.4.4/packages/ibase/src/ibase60dyn.pp"/>
@@ -966,134 +966,130 @@
         <IsVisibleTab Value="True"/>
         <EditorIndex Value="3"/>
         <WindowIndex Value="0"/>
-        <TopLine Value="240"/>
-        <CursorPos X="4" Y="257"/>
-        <UsageCount Value="29"/>
+        <TopLine Value="53"/>
+        <CursorPos X="1" Y="134"/>
+        <UsageCount Value="32"/>
         <Loaded Value="True"/>
         <LoadedDesigner Value="True"/>
       </Unit102>
     </Units>
-    <JumpHistory Count="30" HistoryIndex="29">
+    <JumpHistory Count="29" HistoryIndex="28">
       <Position1>
         <Filename Value="systables.pas"/>
-        <Caret Line="53" Column="7" TopLine="35"/>
+        <Caret Line="57" Column="14" TopLine="40"/>
       </Position1>
       <Position2>
         <Filename Value="systables.pas"/>
-        <Caret Line="619" Column="15" TopLine="612"/>
+        <Caret Line="1" Column="1" TopLine="1"/>
       </Position2>
       <Position3>
         <Filename Value="systables.pas"/>
-        <Caret Line="52" Column="14" TopLine="16"/>
+        <Caret Line="29" Column="29" TopLine="1"/>
       </Position3>
       <Position4>
-        <Filename Value="main.pas"/>
-        <Caret Line="2858" Column="66" TopLine="2852"/>
+        <Filename Value="systables.pas"/>
+        <Caret Line="33" Column="23" TopLine="5"/>
       </Position4>
       <Position5>
-        <Filename Value="main.pas"/>
-        <Caret Line="205" Column="62" TopLine="205"/>
+        <Filename Value="systables.pas"/>
+        <Caret Line="55" Column="85" TopLine="27"/>
       </Position5>
       <Position6>
-        <Filename Value="main.pas"/>
-        <Caret Line="1068" Column="17" TopLine="1039"/>
+        <Filename Value="systables.pas"/>
+        <Caret Line="251" Column="44" TopLine="236"/>
       </Position6>
       <Position7>
         <Filename Value="systables.pas"/>
-        <Caret Line="609" Column="16" TopLine="609"/>
+        <Caret Line="252" Column="4" TopLine="251"/>
       </Position7>
       <Position8>
         <Filename Value="systables.pas"/>
-        <Caret Line="52" Column="70" TopLine="24"/>
+        <Caret Line="253" Column="52" TopLine="252"/>
       </Position8>
       <Position9>
         <Filename Value="systables.pas"/>
-        <Caret Line="639" Column="41" TopLine="622"/>
+        <Caret Line="310" Column="8" TopLine="280"/>
       </Position9>
       <Position10>
         <Filename Value="systables.pas"/>
-        <Caret Line="642" Column="13" TopLine="622"/>
+        <Caret Line="252" Column="43" TopLine="245"/>
       </Position10>
       <Position11>
         <Filename Value="systables.pas"/>
-        <Caret Line="640" Column="1" TopLine="625"/>
+        <Caret Line="320" Column="37" TopLine="287"/>
       </Position11>
       <Position12>
         <Filename Value="systables.pas"/>
-        <Caret Line="633" Column="9" TopLine="611"/>
+        <Caret Line="255" Column="1" TopLine="238"/>
       </Position12>
       <Position13>
-        <Filename Value="comparison.pas"/>
-        <Caret Line="268" Column="27" TopLine="221"/>
+        <Filename Value="systables.pas"/>
+        <Caret Line="286" Column="40" TopLine="269"/>
       </Position13>
       <Position14>
-        <Filename Value="main.pas"/>
-        <Caret Line="3924" Column="1" TopLine="3907"/>
+        <Filename Value="systables.pas"/>
+        <Caret Line="15" Column="18" TopLine="1"/>
       </Position14>
       <Position15>
-        <Filename Value="comparison.pas"/>
-        <Caret Line="269" Column="59" TopLine="243"/>
+        <Filename Value="systables.pas"/>
+        <Caret Line="288" Column="1" TopLine="269"/>
       </Position15>
       <Position16>
-        <Filename Value="comparison.pas"/>
-        <Caret Line="267" Column="7" TopLine="252"/>
+        <Filename Value="systables.pas"/>
+        <Caret Line="28" Column="1" TopLine="18"/>
       </Position16>
       <Position17>
-        <Filename Value="comparison.pas"/>
-        <Caret Line="270" Column="60" TopLine="57"/>
+        <Filename Value="systables.pas"/>
+        <Caret Line="32" Column="14" TopLine="18"/>
       </Position17>
       <Position18>
-        <Filename Value="scriptdb.pas"/>
-        <Caret Line="380" Column="48" TopLine="360"/>
+        <Filename Value="systables.pas"/>
+        <Caret Line="33" Column="113" TopLine="16"/>
       </Position18>
       <Position19>
-        <Filename Value="systables.pas"/>
-        <Caret Line="626" Column="18" TopLine="618"/>
+        <Filename Value="scriptdb.pas"/>
+        <Caret Line="419" Column="22" TopLine="397"/>
       </Position19>
       <Position20>
-        <Filename Value="systables.pas"/>
-        <Caret Line="661" Column="10" TopLine="651"/>
+        <Filename Value="scriptdb.pas"/>
+        <Caret Line="410" Column="47" TopLine="393"/>
       </Position20>
       <Position21>
         <Filename Value="systables.pas"/>
-        <Caret Line="660" Column="1" TopLine="641"/>
+        <Caret Line="29" Column="54" TopLine="12"/>
       </Position21>
       <Position22>
-        <Filename Value="scriptdb.pas"/>
-        <Caret Line="367" Column="1" TopLine="350"/>
+        <Filename Value="systables.pas"/>
+        <Caret Line="256" Column="67" TopLine="256"/>
       </Position22>
       <Position23>
         <Filename Value="systables.pas"/>
-        <Caret Line="661" Column="30" TopLine="658"/>
+        <Caret Line="257" Column="4" TopLine="256"/>
       </Position23>
       <Position24>
-        <Filename Value="systables.pas"/>
-        <Caret Line="666" Column="3" TopLine="660"/>
+        <Filename Value="comparison.pas"/>
+        <Caret Line="317" Column="32" TopLine="303"/>
       </Position24>
       <Position25>
         <Filename Value="comparison.pas"/>
-        <Caret Line="229" Column="19" TopLine="194"/>
+        <Caret Line="246" Column="40" TopLine="221"/>
       </Position25>
       <Position26>
         <Filename Value="comparison.pas"/>
-        <Caret Line="245" Column="3" TopLine="291"/>
+        <Caret Line="97" Column="55" TopLine="67"/>
       </Position26>
       <Position27>
         <Filename Value="comparison.pas"/>
-        <Caret Line="326" Column="3" TopLine="297"/>
+        <Caret Line="255" Column="27" TopLine="231"/>
       </Position27>
       <Position28>
         <Filename Value="comparison.pas"/>
-        <Caret Line="285" Column="1" TopLine="272"/>
+        <Caret Line="248" Column="43" TopLine="235"/>
       </Position28>
       <Position29>
         <Filename Value="comparison.pas"/>
-        <Caret Line="257" Column="33" TopLine="240"/>
+        <Caret Line="217" Column="7" TopLine="176"/>
       </Position29>
-      <Position30>
-        <Filename Value="comparison.pas"/>
-        <Caret Line="249" Column="3" TopLine="240"/>
-      </Position30>
     </JumpHistory>
   </ProjectOptions>
   <CompilerOptions>

+ 1 - 1
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      : 12.May.2012                                          }
+{  Last updated      : 14.May.2012                                          }
 {  License           : GPL for GUI, LGPL for Units                          }
 {***************************************************************************}
 

+ 89 - 23
comparison.pas

@@ -9,8 +9,8 @@ uses
   Buttons, IBConnection, sqldb;
 
 const
-  dbObjects: array [1 .. 12] of string = ('Tables', 'Generators', 'Triggers', 'Views', 'Stored Procedures', 'UDFs',
-    'Sys Tables', 'Domains', 'Roles', 'Exceptions', 'Users', 'Indices');
+  dbObjects: array [1 .. 13] of string = ('Tables', 'Generators', 'Triggers', 'Views', 'Stored Procedures', 'UDFs',
+    'Sys Tables', 'Domains', 'Roles', 'Exceptions', 'Users', 'Indices', 'Constraints');
 
 type
 
@@ -41,7 +41,7 @@ type
     procedure laScriptClick(Sender: TObject);
   private
     fdbIndex: Integer;
-    dbObjectsList: array [1 .. 12] of TStringList;
+    dbObjectsList: array [1 .. 13] of TStringList;
     { private declarations }
   public
     procedure Init(dbIndex: Integer);
@@ -93,6 +93,8 @@ var
   ATableName, AIndexName: string;
   FieldsList: TStringList;
   Unique, Ascending: Boolean;
+  KeyName, CurrentTableName, CurrentFieldName,
+  OtherTableName, OtherFieldName, UpdateRule, DeleteRule: string;
 begin
   meLog.Clear;
   ScriptList:= TStringList.Create;
@@ -102,13 +104,14 @@ begin
   QueryWindow.meQuery.ClearAll;
   dmSysTables.Init(fdbIndex);
 
-  for x:= 1 to 12 do
+  for x:= 1 to 13 do
   begin
     if (x = 1) and cxTables.Checked then // Tables
     for i:= 0 to dbObjectsList[x].Count - 1 do
     begin
       ScriptList.Clear;
       Scriptdb.ScriptTableAsCreate(fdbIndex, dbObjectsList[x].Strings[i], ScriptList);
+
       QueryWindow.meQuery.Lines.AddStrings(ScriptList);
       QueryWindow.meQuery.Lines.Add('');
     end
@@ -117,6 +120,7 @@ begin
     for i:= 0 to dbObjectsList[x].Count - 1 do
     begin
       ScriptList.Clear;
+
       QueryWindow.meQuery.Lines.Add('create generator ' + dbObjectsList[x].Strings[i] + ';');
       QueryWindow.meQuery.Lines.Add('');
     end
@@ -126,6 +130,7 @@ begin
     begin
       ScriptList.Clear;
       dmSysTables.ScriptTrigger(fdbIndex, dbObjectsList[x].Strings[i], ScriptList, True);
+
       QueryWindow.meQuery.Lines.AddStrings(ScriptList);
       QueryWindow.meQuery.Lines.Add('');
     end
@@ -135,6 +140,7 @@ begin
     begin
       fmMain.GetViewInfo(fdbIndex, dbObjectsList[x].Strings[i], Columns, ViewBody);
       ScriptList.Text:= Trim(ViewBody);
+
       QueryWindow.meQuery.Lines.Add('CREATE VIEW "' + dbObjectsList[x].Strings[i] + '" (' + Columns + ')');
       QueryWindow.meQuery.Lines.Add('AS');
       ScriptList.Text:= Trim(ViewBody);
@@ -152,6 +158,7 @@ begin
       ScriptList.Add('^');
       ScriptList.Add('SET TERM ; ^');
       ScriptList.Add('');
+
       QueryWindow.meQuery.Lines.AddStrings(ScriptList);
       QueryWindow.meQuery.Lines.Add('');
     end
@@ -218,8 +225,35 @@ begin
         QueryWindow.meQuery.Lines.Add('');
       end;
 
+    end
+    else
+    if (x = 13) and cxTables.Checked then // Constraints
+    for i:= 0 to dbObjectsList[x].Count - 1 do
+    begin
+      Line:= dbObjectsList[x].Strings[i];
+      ATableName:= copy(Line, 1, Pos(',', Line) - 1);
+      System.Delete(Line, 1, Pos(',', Line));
+      AIndexName:= Line;
+      ScriptList.Clear;
+      if dmSysTables.GetConstraintInfo(fdbIndex, ATableName, AIndexName, KeyName, CurrentTableName, CurrentFieldName,
+        OtherTableName, OtherFieldName, UpdateRule, DeleteRule) then
+      begin
+        Line:= 'alter table ' + ATableName + ' add constraint ' + AIndexName +
+          ' foreign key (' + CurrentFieldName + ') references ' +  OtherTableName  +
+          ' (' + dmSysTables.GetConstraintForiegnKeyFields(OtherFieldName, dmSysTables.sqQuery) + ') ';
+        if Trim(UpdateRule) <> 'RESTRICT' then
+          Line:= Line + ' on update ' + Trim(UpdateRule);
+        if Trim(DeleteRule) <> 'RESTRICT' then
+          Line:= Line + ' on delete ' + Trim(DeleteRule);
+
+        QueryWindow.meQuery.Lines.Add(Line);
+        QueryWindow.meQuery.Lines.Add('');
+      end;
+
+
     end;
 
+
   end;
 
 
@@ -237,8 +271,6 @@ var
   x, i, j: Integer;
   TablesList: TStringList;
   PrimaryIndexName: string;
-  SecIndexList: TStringList;
-  ComparedSecIndexList: TStringList;
   ConstraintName: string;
 begin
   List:= TStringList.Create;
@@ -272,45 +304,79 @@ begin
 
   end;
 
-  // Indices
   if cxTables.Checked then
   begin
     TablesList:= TStringList.Create;
     TablesList.CommaText:= dmSysTables.GetDBObjectNames(fdbIndex, 1, Count);
-    SecIndexList:= TStringList.Create;
-    ComparedSecIndexList:= TStringList.Create;
+
+    // Indices
     meLog.Lines.Add('');
     meLog.Lines.Add('Indices:');
     dbObjectsList[12].Clear;
     for i:= 0 to TablesList.Count - 1 do
     begin
       PrimaryIndexName:= dmSysTables.GetPrimaryKeyIndexName(fdbIndex, TablesList[i], ConstraintName);
-      SecIndexList.Clear;
-      dmSysTables.GetIndices(fdbIndex, TablesList[i], PrimaryIndexName, SecIndexList);
-      ComparedSecIndexList.Clear;
-      if dmSysTables.GetIndices(cbComparedDatabase.ItemIndex, TablesList[i], PrimaryIndexName, ComparedSecIndexList) then
+      List.Clear;
+      dmSysTables.GetIndices(fdbIndex, TablesList[i], PrimaryIndexName, List);
+      ComparedList.Clear;
+      if dmSysTables.GetIndices(cbComparedDatabase.ItemIndex, TablesList[i], PrimaryIndexName, ComparedList) then
       begin
-        for j:= 0 to SecIndexList.Count - 1 do
-          if ComparedSecIndexList.IndexOf(SecIndexList[j]) = -1 then
+        for j:= 0 to List.Count - 1 do
+          if ComparedList.IndexOf(List[j]) = -1 then
           begin
-            meLog.Lines.Add('Missing: ' + SecIndexList[j]);
-            dbObjectsList[12].Add(TablesList[i] + ',' + SecIndexList[j]);
+            meLog.Lines.Add('Missing: ' + List[j]);
+            dbObjectsList[12].Add(TablesList[i] + ',' + List[j]);
           end
       end
       else // Table does not exist, all indices are missing
-      if SecIndexList.Count > 0 then
-      for j:= 0 to SecIndexList.Count - 1 do
+      if List.Count > 0 then
+      for j:= 0 to List.Count - 1 do
+      begin
+        dbObjectsList[12].Add(TablesList[i] + ',' + List[j]);
+        meLog.Lines.Add('Missing: ' + List[j]);
+      end;
+
+    end;
+
+    // Constraints
+    meLog.Lines.Add('');
+    meLog.Lines.Add('Constraints:');
+    dbObjectsList[13].Clear;
+    for i:= 0 to TablesList.Count - 1 do
+    begin
+      PrimaryIndexName:= dmSysTables.GetPrimaryKeyIndexName(fdbIndex, TablesList[i], ConstraintName);
+      dmSysTables.Init(fdbIndex);
+      List.Clear;
+      dmSysTables.GetTableConstraints(TablesList[i], dmSysTables.sqQuery, List);
+      dmSysTables.sqQuery.Close;
+
+      dmSysTables.Init(cbComparedDatabase.ItemIndex);
+      ComparedList.Clear;
+
+      if dmSysTables.GetTableConstraints(TablesList[i], dmSysTables.sqQuery, ComparedList) then
+      begin
+        dmSysTables.sqQuery.Close;
+        for j:= 0 to List.Count - 1 do
+          if ComparedList.IndexOf(List[j]) = -1 then
+          begin
+            meLog.Lines.Add('Missing: ' + List[j]);
+            dbObjectsList[13].Add(TablesList[i] + ',' + List[j]);
+          end
+      end
+      else // Table does not exist, all constraints are missing
+      if List.Count > 0 then
+      for j:= 0 to List.Count - 1 do
       begin
-        dbObjectsList[12].Add(TablesList[i] + ',' + SecIndexList[j]);
-        meLog.Lines.Add('Missing: ' + SecIndexList[j]);
+        dbObjectsList[13].Add(TablesList[i] + ',' + List[j]);
+        meLog.Lines.Add('Missing: ' + List[j]);
       end;
 
     end;
 
+
     TablesList.Free;
-    SecIndexList.Free;
-    ComparedSecIndexList.Free;
   end;
+
   meLog.Visible:= True;
   laScript.Enabled:= True;
   ComparedList.Free;

+ 60 - 3
systables.pas

@@ -26,7 +26,12 @@ type
       var TriggerPosition: Integer): Boolean;
     procedure ScriptTrigger(dbIndex: Integer; ATriggerName: string; List: TStrings;
       AsCreate: Boolean = False);
-    procedure GetTableConstraints(ATableName: string; var SqlQuery: TSQLQuery);
+    function GetTableConstraints(ATableName: string; var SqlQuery: TSQLQuery;
+      ConstraintsList: TStringList = nil): Boolean;
+
+    function GetConstraintInfo(dbIndex: Integer; ATableName, ConstraintName: string; var KeyName,
+        CurrentTableName, CurrentFieldName, OtherTableName, OtherFieldName, UpdateRule, DeleteRule: string): Boolean;
+
     function GetExceptionInfo(ExceptionName: string; var Msg, Description, SqlQuery: string): Boolean;
     procedure GetDomainInfo(dbIndex: Integer; DomainName: string; var DomainType: string;
       var DomainSize: Integer; var DefaultValue: string);
@@ -88,6 +93,7 @@ begin
   with fmMain.RegisteredDatabases[dbIndex] do
   begin
   //  IBConnection.Close;
+    sqQuery.Close;
     IBConnection.DatabaseName:= RegRec.DatabaseName;
     IBConnection.UserName:= RegRec.UserName;
     IBConnection.Password:= RegRec.Password;
@@ -248,10 +254,12 @@ end;
 
 (**********  Get Table Constraints Info  ********************)
 
-procedure TdmSysTables.GetTableConstraints(ATableName: string; var SqlQuery: TSQLQuery);
+function TdmSysTables.GetTableConstraints(ATableName: string; var SqlQuery: TSQLQuery;
+   ConstraintsList: TStringList = nil): Boolean;
 begin
   SqlQuery.Close;
-  SqlQuery.SQL.Text:= 'select Trim(Refc.RDB$Constraint_Name) as ConstName, Trim(Refc.RDB$CONST_NAME_UQ) as KeyName, ' +
+  SqlQuery.SQL.Text:= 'select Trim(Refc.RDB$Constraint_Name) as ConstName, ' +
+    'Trim(Refc.RDB$CONST_NAME_UQ) as KeyName, ' +
     'Trim(Ind.RDB$Relation_Name) as CurrentTableName, ' +
     'Trim(Seg.RDB$Field_name) as CurrentFieldName, ' +
     'Trim(Con.RDB$Relation_Name) as OtherTableName, ' +
@@ -264,6 +272,55 @@ begin
     '  and Refc.RDB$COnstraint_Name = Seg.RDB$Index_Name' +
     '  and Ind.RDB$Relation_Name = ''' + UpperCase(ATableName) + '''';
   SqlQuery.Open;
+  Result:= SqlQuery.RecordCount > 0;
+  with SqlQuery do
+  if Result and Assigned(ConstraintsList) then
+  begin
+    ConstraintsList.Clear;
+    while not Eof do
+    begin
+      ConstraintsList.Add(FieldByName('ConstName').AsString);
+      Next;
+    end;
+    First;
+  end;
+
+end;
+
+(**********  Get Constraint Info  ********************)
+
+function TdmSysTables.GetConstraintInfo(dbIndex: Integer; ATableName, ConstraintName: string; var KeyName,
+    CurrentTableName, CurrentFieldName, OtherTableName, OtherFieldName, UpdateRule, DeleteRule: string): Boolean;
+begin
+  Init(dbIndex);
+  sqQuery.Close;
+  sqQuery.SQL.Text:= 'select Trim(Refc.RDB$Constraint_Name) as ConstName, Trim(Refc.RDB$CONST_NAME_UQ) as KeyName, ' +
+    'Trim(Ind.RDB$Relation_Name) as CurrentTableName, ' +
+    'Trim(Seg.RDB$Field_name) as CurrentFieldName, ' +
+    'Trim(Con.RDB$Relation_Name) as OtherTableName, ' +
+    'Trim(Ind.RDB$Foreign_key) as OtherFieldName, ' +
+    'RDB$Update_Rule as UpdateRule, RDB$Delete_Rule as DeleteRule ' +
+    'from RDB$RELATION_CONSTRAINTS Con, rdb$REF_Constraints Refc, RDB$INDEX_SEGMENTS Seg, ' +
+    'RDB$INDICES Ind ' +
+    'where Con.RDB$COnstraint_Name = Refc.RDB$Const_Name_UQ ' +
+    '  and Refc.RDB$COnstraint_Name = Ind.RDB$Index_Name' +
+    '  and Refc.RDB$COnstraint_Name = Seg.RDB$Index_Name' +
+    '  and Ind.RDB$Relation_Name = ''' + UpperCase(ATableName) + ''' ' +
+    '  and Refc.RDB$Constraint_Name = ''' + ConstraintName + '''';
+  sqQuery.Open;
+  Result:= sqQuery.RecordCount > 0;
+  with sqQuery do
+  if Result then
+  begin
+    KeyName:= FieldByName('KeyName').AsString;
+    CurrentTableName:= FieldByName('CurrentTableName').AsString;
+    CurrentFieldName:= FieldByName('CurrentFieldName').AsString;
+    OtherTableName:= FieldByName('OtherTableName').AsString;
+    OtherFieldName:= FieldByName('OtherFieldName').AsString;
+    UpdateRule:= FieldByName('UpdateRule').AsString;
+    DeleteRule:= FieldByName('DeleteRule').AsString;
+  end;
+  sqQuery.Close;
 
 end;