소스 검색

Support for blob subtype (text, binary, BLR...) in db scripting. Part of issue #16

Reinier Olislagers 11 년 전
부모
커밋
10c343c4fa
2개의 변경된 파일24개의 추가작업 그리고 1개의 파일을 삭제
  1. 16 1
      main.pas
  2. 8 0
      scriptdb.pas

+ 16 - 1
main.pas

@@ -217,6 +217,8 @@ type
     function LoadRegisteredDatabases: Boolean;
     function FindQueryWindow(ATitle: string): TComponent;
     function DeleteRegistration(Index: Integer): Boolean;
+    // Returns BLOB subtype clause depending on subtype
+    function GetBlobSubTypeName(SubType: integer): string;
     // Returns field type DDL given a RDB$FIELD_TYPE value as well
     // as subtype/length/scale (use -1 for empty/unknown values)
     function GetFBTypeName(Index: Integer;
@@ -4104,6 +4106,18 @@ begin
   end;
 end;
 
+function TfmMain.GetBlobSubTypeName(SubType: integer): string;
+begin
+  case SubType of
+    //<0: user-defined
+    0: Result:= 'SUB_TYPE BINARY';
+    1: Result:= 'SUB_TYPE TEXT';
+    2: Result:= 'SUB_TYPE BLR'; //(used for definitions of Firebird procedures, triggers, etc.
+    //>2: reserved by Firebird
+    else Result:= ''; //unknown
+  end;
+end;
+
 (**************  Get Firebird Type name  *****************)
 
 function TfmMain.GetFBTypeName(Index: Integer;
@@ -4136,7 +4150,7 @@ begin
   // Subtypes for numeric types
   if Index in [7, 8, 16] then
   begin
-    if SubType = 0 then
+    if SubType = 0 then {integer}
     begin
       case Index of
         7: Result:= 'SMALLINT';
@@ -4146,6 +4160,7 @@ begin
     end
     else
     begin
+      // Numeric/decimal: use scale
       if SubType = 1 then
         Result:= 'Numeric('
       else

+ 8 - 0
scriptdb.pas

@@ -206,6 +206,7 @@ var
   PKFieldsList: TStringList;
   FieldLine: string;
   Skipped: Boolean;
+  BlobSubType: string;
   ConstraintName: string;
   CalculatedList: TStringList; // for calculated fields
   DefaultValue: string;
@@ -237,6 +238,13 @@ begin
         if (FieldByName('Field_Type_Int').AsInteger) in [CharType, CStringType, VarCharType] then
           FieldLine:= FieldLine + '(' + FieldByName('CharacterLength').AsString + ') ';
 
+        if (FieldByName('Field_Type_Int').AsInteger = BlobType) then
+        begin
+          BlobSubType:= fmMain.GetBlobSubTypeName(FieldByName('Field_Sub_Type').AsInteger);
+          if BlobSubType<>'' then
+            FieldLine:= FieldLine + ' ' + BlobSubType;
+        end;
+
         // Rudimentary support for array datatypes (only covers 0 dimension types):
         {todo: expand to proper array type detection (low priority as arrays are
          virtually unused}