Parcourir la source

Further domain check support (in db comparison). Part of issue #16

Reinier Olislagers il y a 11 ans
Parent
commit
62e446b04d
2 fichiers modifiés avec 18 ajouts et 8 suppressions
  1. 15 5
      comparison.pas
  2. 3 3
      scriptdb.pas

+ 15 - 5
comparison.pas

@@ -1,5 +1,5 @@
 unit Comparison;
-//todo: add support for check constraints
+
 {$mode objfpc}{$H+}
 
 interface
@@ -439,12 +439,22 @@ begin
       for i:= 0 to dbObjectsList[x].Count - 1 do
       begin
         dmSysTables.GetDomainInfo(fdbIndex, dbObjectsList[x].Strings[i], DomainType, DomainSize, DefaultValue, CheckConstraint, Collation);
-        //todo: add support for collations and character sets and check constraints
 
         Line:= 'Create Domain ' + dbObjectsList[x].Strings[i] + ' as ' + DomainType;
-          if Pos('CHAR', DomainType) > 0 then
-            Line:= Line + '(' + IntToStr(DomainSize) + ')';
-          Line:= Line + ' ' + DefaultValue + ';';
+        // String size
+        if Pos('CHAR', DomainType) > 0 then
+          Line:= Line + '(' + IntToStr(DomainSize) + ')';
+        // Default value, if any
+        if DefaultValue<>'' then
+          Line:= Line + ' ' + DefaultValue;
+        //todo: domain comparison: verify if this collate/constraint works
+        // Check constraint, if any:
+        if CheckConstraint <> '' then
+          Line:= Line + ' ' + CheckConstraint;
+        // Collation for text types, if any:
+        if Collation <> '' then
+          Line:= Line + ' COLLATE ' +  Collation;
+        Line:= Line+' ;';
 
         fQueryWindow.meQuery.Lines.Add(Line);
         fQueryWindow.meQuery.Lines.Add('');

+ 3 - 3
scriptdb.pas

@@ -172,7 +172,7 @@ var
   CheckConstraint: string;
   DefaultValue: string;
 begin
-  //todo: add support for character set
+  //todo: script domains: add support for character set
   List.CommaText:= dmSysTables.GetDBObjectNames(dbIndex, 8, Count);
   // Get domains in dependency order (if dependencies can exist between domains)
   dmSysTables.SortDependencies(List);
@@ -184,10 +184,10 @@ begin
     if (Pos('CHAR', DomainType) > 0) or (Pos('CSTRING', DomainType) > 0) then
       List[i]:= List[i] + '(' + IntToStr(DomainSize) + ')';
     List[i]:= List[i] + ' ' + DefaultValue;
-    // Check constraint
+    // Check constraint, if any:
     if CheckConstraint <> '' then
       List[i]:= List[i] + ' ' + CheckConstraint;
-    // Collation for text types:
+    // Collation for text types, if any:
     if Collation <> '' then
       List[i]:= List[i] + ' COLLATE ' +  Collation;
     // Close off create clause: