Răsfoiți Sursa

Scripting: more correct output of domain integer/decimal data types."DOUBLE PRECISION" data type does not exist in Firebird=>"DOUBLE". Fix possible error from renaming int64=>bigint.

Reinier Olislagers 11 ani în urmă
părinte
comite
3aea34db98
6 a modificat fișierele cu 136 adăugiri și 132 ștergeri
  1. 75 74
      main.pas
  2. 15 15
      newgen.lfm
  3. 18 16
      newgen.lrs
  4. 1 1
      newgen.pas
  5. 6 7
      scriptdb.pas
  6. 21 19
      systables.pas

+ 75 - 74
main.pas

@@ -227,13 +227,15 @@ type
     VersionDate: string;
     Major, Minor, ReleaseVersion: word;
     function GetServerName(DBName: string): string;
-    function RetreiveInputParamFromSP(Body: string): string;
+    function RetrieveInputParamFromSP(Body: string): string;
     function LoadRegisteredDatabases: Boolean;
     function FindQueryWindow(ATitle: string): TComponent;
     function DeleteRegistration(Index: Integer): Boolean;
-    // Returns field type DDL given a RDB$FIELD_TYPE value
-    // todo: extend this to include subtype when necessary; replace subtype code everywhere
-    function GetFBTypeName(Index: 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;
+      SubType: integer=-1; FieldLength: integer=-1;
+      Scale: integer=-1): string;
     function GetPrimaryKeyIndexName(DatabaseIndex: Integer; ATableName: string; var ConstraintName: string): string;
     function GetConstraintFields(ATableName, AIndexName: string; var List: TStringList): Boolean;
     // Get fields information for specified table
@@ -255,8 +257,6 @@ type
     function ChangeQueryToBIDirectional(DatabaseIndex: Integer; ATableName: string; sqQuery: TSQLQuery): Boolean;
     function GetTableNames(dbIndex: Integer): string;
     function CreateNewTrigger(dbIndex: Integer; ATableName: string; OnCommitProcedure: TNotifyEvent = nil): Boolean;
-    // Get field type DDL given Firebird field type and subtype etc info
-    function GetNumericFieldType(FieldType, SubType, FieldLength, Scale: Integer): string;
     function AddToSQLHistory(DatabaseTitle: string; SQLType, SQLStatement: string): Boolean;
     function SaveAndCloseSQLHistory: Boolean;
     function OpenSQLHistory(DatabaseTitle: string): Boolean;
@@ -632,7 +632,7 @@ begin
   begin
     AProcName:= SelNode.Text;
     Body:= GetStoredProcBody(SelNode.Parent.Parent.OverlayIndex, AProcName, SPOwner);
-    Params:= RetreiveInputParamFromSP(Body);
+    Params:= RetrieveInputParamFromSP(Body);
     withParams:= Params <> '';
     with fmCallProc do
     begin
@@ -1418,34 +1418,6 @@ begin
     inherited SetFocus;
 end;
 
-function TfmMain.GetNumericFieldType(FieldType, SubType, FieldLength,
-  Scale: Integer): string;
-begin
-  if SubType = 0 then
-  begin
-    case FieldType of
-      7: Result:= 'SMALLINT';
-      8: Result:= 'INTEGER';
-      16: Result:= 'BIGINT';
-    end;
-  end
-  else
-  begin
-    if SubType = 1 then
-      Result:= 'Numeric('
-    else
-    if SubType = 2 then
-      Result:= 'Decimal(';
-    case FieldLength of
-      4: Result:= Result + '9,';
-      8: Result:= Result + '18,';
-    else
-      Result:= Result + IntToStr(FieldLength) + ',';
-    end;
-    Result:= Result + IntToStr(Abs(Scale)) + ') ';
-  end;
-end;
-
 
 (* Insert SQL query into database history file *)
 
@@ -1546,7 +1518,7 @@ end;
 
 (* Get input parameters from stored procedure body *)
 
-function TfmMain.RetreiveInputParamFromSP(Body: string): string;
+function TfmMain.RetrieveInputParamFromSP(Body: string): string;
 var
   i: Integer;
   SizeStarted: Boolean;
@@ -2483,7 +2455,7 @@ begin
   Rec:= RegisteredDatabases[DatabaseIndex];
   SetConnection(DatabaseIndex);
   sqlTransaction.Commit;
-  //todo: add Firebird 3.0 beta BOOLEAN datatype number
+  //todo: check all occurrences and rewrite field_type_str with fmMain.GetFBTypeName function
   SQLQuery1.SQL.Text:= 'SELECT r.RDB$FIELD_NAME AS field_name, ' +
       '  r.RDB$DESCRIPTION AS field_description, ' +
       '  r.RDB$DEFAULT_SOURCE AS field_default_value, ' +
@@ -2548,7 +2520,7 @@ var
   ParamName: string;
   FirstOutput: Boolean;
   ParamType: Byte;
-  Seperator: Boolean;
+  Separator: Boolean;
   BodyList: TStringList;
 begin
   try
@@ -2572,36 +2544,34 @@ begin
       FirstOutput:= False;
 
       // Get procedure parameters
-        while not SQLQuery1.EOF do
+      while not SQLQuery1.EOF do
+      begin
+        ParamName:= Trim(SQLQuery1.FieldByName('RDB$Parameter_Name').AsString);
+        ParamType:= SQLQuery1.FieldByName('rdb$parameter_type').AsInteger;
+        Separator:= False;
+        // Output parameter
+        if (not FirstOutput) and (ParamType = 1) then
         begin
-          ParamName:= Trim(SQLQuery1.FieldByName('RDB$Parameter_Name').AsString);
-          ParamType:= SQLQuery1.FieldByName('rdb$parameter_type').AsInteger;
-          Seperator:= False;
-          // Output parameter
-          if (not FirstOutput) and (ParamType = 1) then
-          begin
-            BodyList.Add(')' + #10 + 'RETURNS (');
-            FirstOutput:= True;
-            Seperator:= True;
-          end;
-          Line:= '  ' + ParamName + '    ' +
-            GetFBTypeName(SQLQuery1.FieldByName('RDB$Field_Type').AsInteger);
-          if SQLQuery1.FieldByName('RDB$Field_Type').AsInteger = 37 then
-            Line:= Line + '(' + SQLQuery1.FieldByName('RDB$Character_Length').AsString + ')';
-
-
-          SQLQuery1.Next;
-
-          if (not SQLQuery1.EOF) then
-          if ((FirstOutput) or (SQLQuery1.FieldByName('rdb$parameter_Type').AsInteger = 0)) then
-            Line:= Line + ',';
-
-          BodyList.Add(Line);
+          BodyList.Add(')' + #10 + 'RETURNS (');
+          FirstOutput:= True;
+          Separator:= True;
         end;
+        //todo: verify if getfbtypename needs more parameters here
+        Line:= '  ' + ParamName + '    ' +
+          GetFBTypeName(SQLQuery1.FieldByName('RDB$Field_Type').AsInteger);
+        if SQLQuery1.FieldByName('RDB$Field_Type').AsInteger = 37 then
+          Line:= Line + '(' + SQLQuery1.FieldByName('RDB$Character_Length').AsString + ')';
+        SQLQuery1.Next;
+
+        if (not SQLQuery1.EOF) then
+        if ((FirstOutput) or (SQLQuery1.FieldByName('rdb$parameter_Type').AsInteger = 0)) then
+          Line:= Line + ',';
+
+        BodyList.Add(Line);
+      end;
 
       BodyList.Add(')');
       BodyList.Add('AS');
-
       SQLQuery1.Close;
 
       // Get Procedure body
@@ -2756,6 +2726,7 @@ begin
     while not SQLQuery1.EOF do
     begin
       Params:= Params + #10 + GetFBTypeName(SQLQuery1.FieldByName('RDB$FIELD_TYPE').AsInteger);
+      //todo: verify if getfbtypename needs more parameters here
       if SQLQuery1.FieldByName('RDB$FIELD_TYPE').AsInteger in [14, 37, 40] then
         Params:= Params + '(' + SQLQuery1.FieldByName('RDB$Character_LENGTH').AsString + ')';
       SQLQuery1.Next;
@@ -2774,6 +2745,7 @@ begin
     while not SQLQuery1.EOF do
     begin
       Params:= Params + #10 + GetFBTypeName(SQLQuery1.FieldByName('RDB$FIELD_TYPE').AsInteger);
+      //todo: verify if getfbtypename needs more parameters here
       if SQLQuery1.FieldByName('RDB$FIELD_TYPE').AsInteger in [14, 37, 40] then
         Params:= Params + '(' + SQLQuery1.FieldByName('RDB$Character_LENGTH').AsString + ')';
       SQLQuery1.Next;
@@ -3092,12 +3064,10 @@ begin
         Cells[1, RowCount - 1]:= Trim(FieldByName('Field_Name').AsString);
 
         // Field Type
-        if FieldByName('Field_Type_Int').AsInteger in [7, 8, 16] then
-          Cells[2, RowCount - 1]:= GetNumericFieldType(FieldByName('Field_Type_Int').AsInteger,
-            FieldByName('Field_SubType').AsInteger, FieldByName('Field_Length').AsInteger,
-            FieldByName('Field_Scale').AsInteger)
-        else
-          Cells[2, RowCount - 1]:= Trim(FieldByName('Field_Type_Str').AsString);
+        Cells[2, RowCount - 1]:= GetFBTypeName(FieldByName('Field_Type_Int').AsInteger,
+          FieldByName('Field_SubType').AsInteger,
+          FieldByName('Field_Length').AsInteger,
+          FieldByName('Field_Scale').AsInteger);
 
         // Correct field type if it is an array type
         // Array should really be [upper_bound dim0,upperbound dim1,..]
@@ -4108,8 +4078,12 @@ end;
 
 (**************  Get Firebird Type name  *****************)
 
-function TfmMain.GetFBTypeName(Index: Integer): string;
+function TfmMain.GetFBTypeName(Index: Integer;
+  SubType: integer=-1; FieldLength: integer=-1;
+  Scale: integer=-1
+  ): string;
 begin
+  //todo: add Firebird 3.0 beta BOOLEAN datatype number
   case Index of
     // See also
     // http://firebirdsql.org/manual/migration-mssql-data-types.html
@@ -4117,20 +4091,47 @@ begin
     261 : Result:= 'BLOB';
     14 : Result:= 'CHAR';
     40 : Result:= 'CSTRING';
+    12 : Result:= 'DATE';
     11 : Result:= 'D_FLOAT';
-    16 : Result:= 'BIGINT'; // depending on subtype, BIGINT, NUMERIC or DECIMAL. Probably int64 in Interbase
+    16 : Result:= 'BIGINT'; // Probably int64 in Interbase. Further processed below
     27 : Result:= 'DOUBLE';
     10 : Result:= 'FLOAT';
-    8  : Result:= 'INTEGER';
+    8  : Result:= 'INTEGER'; // further processed below
     9  : Result:= 'QUAD';
-    7  : Result:= 'SMALLINT';
-    12 : Result:= 'DATE';
+    7  : Result:= 'SMALLINT'; // further processed below
     13 : Result:= 'TIME';
     35 : Result:= 'TIMESTAMP';
     37 : Result:= 'VARCHAR';
   else
     Result:= 'Unknown Type';
   end;
+  // Subtypes for numeric types
+  if Index in [7, 8, 16] then
+  begin
+    if SubType = 0 then
+    begin
+      case Index of
+        7: Result:= 'SMALLINT';
+        8: Result:= 'INTEGER';
+        16: Result:= 'BIGINT';
+      end;
+    end
+    else
+    begin
+      if SubType = 1 then
+        Result:= 'Numeric('
+      else
+      if SubType = 2 then
+        Result:= 'Decimal(';
+      case FieldLength of
+        4: Result:= Result + '9,';
+        8: Result:= Result + '18,';
+      else
+        Result:= Result + IntToStr(FieldLength) + ',';
+      end;
+      Result:= Result + IntToStr(Abs(Scale)) + ') ';
+    end;
+  end;
 end;
 
 (*******************  Get Primary Key fields  ************************)

+ 15 - 15
newgen.lfm

@@ -8,18 +8,18 @@ object fmNewGen: TfmNewGen
   ClientHeight = 250
   ClientWidth = 518
   Position = poScreenCenter
-  LCLVersion = '0.9.31'
+  LCLVersion = '1.2.2.0'
   object Label1: TLabel
     Left = 5
-    Height = 18
+    Height = 13
     Top = 23
-    Width = 113
+    Width = 79
     Caption = 'Generator Name'
     ParentColor = False
   end
   object edGenName: TEdit
     Left = 128
-    Height = 27
+    Height = 21
     Top = 16
     Width = 168
     TabOrder = 0
@@ -49,9 +49,9 @@ object fmNewGen: TfmNewGen
   end
   object cxTrigger: TCheckBox
     Left = 8
-    Height = 22
+    Height = 17
     Top = 64
-    Width = 320
+    Width = 234
     Caption = 'Create Auto increment Trigger for generator'
     OnChange = cxTriggerChange
     TabOrder = 3
@@ -63,42 +63,42 @@ object fmNewGen: TfmNewGen
     Width = 494
     Anchors = [akTop, akLeft, akRight, akBottom]
     Caption = 'Trigger for generator'
-    ClientHeight = 97
+    ClientHeight = 98
     ClientWidth = 490
     Enabled = False
     TabOrder = 4
     object Label2: TLabel
       Left = 6
-      Height = 18
+      Height = 13
       Top = 10
-      Width = 58
+      Width = 41
       Caption = 'On table'
       ParentColor = False
     end
     object Label3: TLabel
       Left = 9
-      Height = 18
+      Height = 13
       Top = 53
-      Width = 34
+      Width = 22
       Caption = 'Field'
       ParentColor = False
     end
     object cbTables: TComboBox
       Left = 86
-      Height = 31
+      Height = 21
       Top = 7
       Width = 152
-      ItemHeight = 0
+      ItemHeight = 13
       OnChange = cbTablesChange
       Style = csDropDownList
       TabOrder = 0
     end
     object cbFields: TComboBox
       Left = 87
-      Height = 31
+      Height = 21
       Top = 48
       Width = 151
-      ItemHeight = 0
+      ItemHeight = 13
       Style = csDropDownList
       TabOrder = 1
     end

+ 18 - 16
newgen.lrs

@@ -1,29 +1,31 @@
+{ This is an automatically generated lazarus resource file }
+
 LazarusResources.Add('TfmNewGen','FORMDATA',[
   'TPF0'#9'TfmNewGen'#8'fmNewGen'#4'Left'#3'j'#1#6'Height'#3#250#0#3'Top'#3#201
   +#0#5'Width'#3#6#2#13'ActiveControl'#7#9'edGenName'#7'Caption'#6#20'Create Ne'
   +'w Generator'#12'ClientHeight'#3#250#0#11'ClientWidth'#3#6#2#8'Position'#7#14
-  +'poScreenCenter'#10'LCLVersion'#6#6'0.9.31'#0#6'TLabel'#6'Label1'#4'Left'#2#5
-  +#6'Height'#2#18#3'Top'#2#23#5'Width'#2'q'#7'Caption'#6#14'Generator Name'#11
-  +'ParentColor'#8#0#0#5'TEdit'#9'edGenName'#4'Left'#3#128#0#6'Height'#2#27#3'T'
-  +'op'#2#16#5'Width'#3#168#0#8'TabOrder'#2#0#0#0#7'TBitBtn'#11'bbCreateGen'#4
+  +'poScreenCenter'#10'LCLVersion'#6#7'1.2.2.0'#0#6'TLabel'#6'Label1'#4'Left'#2
+  +#5#6'Height'#2#13#3'Top'#2#23#5'Width'#2'O'#7'Caption'#6#14'Generator Name'
+  +#11'ParentColor'#8#0#0#5'TEdit'#9'edGenName'#4'Left'#3#128#0#6'Height'#2#21#3
+  +'Top'#2#16#5'Width'#3#168#0#8'TabOrder'#2#0#0#0#7'TBitBtn'#11'bbCreateGen'#4
   +'Left'#2#8#6'Height'#2#30#3'Top'#3#217#0#5'Width'#2'x'#7'Anchors'#11#6'akLef'
   +'t'#8'akBottom'#0#7'Caption'#6#6'Script'#5'Color'#4#219#242#247#0#4'Kind'#7#5
   +'bkAll'#7'OnClick'#7#16'bbCreateGenClick'#8'TabOrder'#2#1#0#0#7'TBitBtn'#7'B'
   +'itBtn1'#4'Left'#3#152#1#6'Height'#2#30#3'Top'#3#217#0#5'Width'#2'c'#7'Ancho'
   +'rs'#11#6'akLeft'#8'akBottom'#0#7'Caption'#6#6'&Close'#5'Color'#4#219#242#247
   +#0#4'Kind'#7#7'bkClose'#8'TabOrder'#2#2#0#0#9'TCheckBox'#9'cxTrigger'#4'Left'
-  +#2#8#6'Height'#2#22#3'Top'#2'@'#5'Width'#3'@'#1#7'Caption'#6'+Create Auto in'
-  +'crement Trigger for generator'#8'OnChange'#7#15'cxTriggerChange'#8'TabOrder'
-  +#2#3#0#0#9'TGroupBox'#9'gbTrigger'#4'Left'#2#10#6'Height'#2't'#3'Top'#2']'#5
-  +'Width'#3#238#1#7'Anchors'#11#5'akTop'#6'akLeft'#7'akRight'#8'akBottom'#0#7
-  +'Caption'#6#21'Trigger for generator'#12'ClientHeight'#2'a'#11'ClientWidth'#3
+  +#2#8#6'Height'#2#17#3'Top'#2'@'#5'Width'#3#234#0#7'Caption'#6'+Create Auto i'
+  +'ncrement Trigger for generator'#8'OnChange'#7#15'cxTriggerChange'#8'TabOrde'
+  +'r'#2#3#0#0#9'TGroupBox'#9'gbTrigger'#4'Left'#2#10#6'Height'#2't'#3'Top'#2']'
+  +#5'Width'#3#238#1#7'Anchors'#11#5'akTop'#6'akLeft'#7'akRight'#8'akBottom'#0#7
+  +'Caption'#6#21'Trigger for generator'#12'ClientHeight'#2'b'#11'ClientWidth'#3
   +#234#1#7'Enabled'#8#8'TabOrder'#2#4#0#6'TLabel'#6'Label2'#4'Left'#2#6#6'Heig'
-  +'ht'#2#18#3'Top'#2#10#5'Width'#2':'#7'Caption'#6#8'On table'#11'ParentColor'
-  +#8#0#0#6'TLabel'#6'Label3'#4'Left'#2#9#6'Height'#2#18#3'Top'#2'5'#5'Width'#2
-  +'"'#7'Caption'#6#5'Field'#11'ParentColor'#8#0#0#9'TComboBox'#8'cbTables'#4'L'
-  +'eft'#2'V'#6'Height'#2#31#3'Top'#2#7#5'Width'#3#152#0#10'ItemHeight'#2#0#8'O'
-  +'nChange'#7#14'cbTablesChange'#5'Style'#7#14'csDropDownList'#8'TabOrder'#2#0
-  +#0#0#9'TComboBox'#8'cbFields'#4'Left'#2'W'#6'Height'#2#31#3'Top'#2'0'#5'Widt'
-  +'h'#3#151#0#10'ItemHeight'#2#0#5'Style'#7#14'csDropDownList'#8'TabOrder'#2#1
+  +'ht'#2#13#3'Top'#2#10#5'Width'#2')'#7'Caption'#6#8'On table'#11'ParentColor'
+  +#8#0#0#6'TLabel'#6'Label3'#4'Left'#2#9#6'Height'#2#13#3'Top'#2'5'#5'Width'#2
+  +#22#7'Caption'#6#5'Field'#11'ParentColor'#8#0#0#9'TComboBox'#8'cbTables'#4'L'
+  +'eft'#2'V'#6'Height'#2#21#3'Top'#2#7#5'Width'#3#152#0#10'ItemHeight'#2#13#8
+  +'OnChange'#7#14'cbTablesChange'#5'Style'#7#14'csDropDownList'#8'TabOrder'#2#0
+  +#0#0#9'TComboBox'#8'cbFields'#4'Left'#2'W'#6'Height'#2#21#3'Top'#2'0'#5'Widt'
+  +'h'#3#151#0#10'ItemHeight'#2#13#5'Style'#7#14'csDropDownList'#8'TabOrder'#2#1
   +#0#0#0#0
 ]);

+ 1 - 1
newgen.pas

@@ -97,7 +97,7 @@ begin
     while not fmMain.SQLQuery1.EOF do
     begin
       FType:= Trim(fmMain.SQLQuery1.FieldByName('Field_Type_Str').AsString);
-      if (FType = 'INTEGER') or (FType = 'INT64') or (FType = 'SMALLINT') then
+      if (FType = 'INTEGER') or (FType = 'BIGINT') or (FType = 'SMALLINT') then
         cbFields.Items.Add(Trim(fmMain.SQLQuery1.FieldByName('Field_Name').AsString));
       fmMain.SQLQuery1.Next;
     end;

+ 6 - 7
scriptdb.pas

@@ -123,6 +123,7 @@ begin
   List.CommaText:= dmSysTables.GetDBObjectNames(dbIndex, 8, Count);
   for i:= 0 to List.Count - 1 do
   begin
+    // todo: add support for numeric field types (e.g.
     dmSysTables.GetDomainInfo(dbIndex, List[i], DomainType, DomainSize, DefaultValue);
 
     List[i]:= 'Create Domain ' + List[i] + ' as ' + DomainType;
@@ -168,13 +169,11 @@ begin
         // Field Name
         FieldLine:= Trim(FieldByName('Field_Name').AsString) + ' ';
 
-        // Field Type
-        if FieldByName('Field_Type_Int').AsInteger in [7, 8, 16] then
-          FieldLine:= FieldLine + fmMain.GetNumericFieldType(FieldByName('Field_Type_Int').AsInteger,
-            FieldByName('Field_SubType').AsInteger, FieldByName('Field_Length').AsInteger,
-            FieldByName('Field_Scale').AsInteger)
-        else
-          FieldLine:= FieldLine + Trim(FieldByName('Field_Type_Str').AsString);
+        // Field type
+        FieldLine:= FieldLine + fmMain.GetFBTypeName(FieldByName('Field_Type_Int').AsInteger,
+          FieldByName('Field_SubType').AsInteger,
+          FieldByName('Field_Length').AsInteger,
+          FieldByName('Field_Scale').AsInteger);
 
         if Pos('char', LowerCase(FieldByName('Field_Type_Str').AsString)) > 0 then
           FieldLine:= FieldLine + '(' + FieldByName('Character_Leng').AsString + ') ';

+ 21 - 19
systables.pas

@@ -291,9 +291,6 @@ end;
 function TdmSysTables.GetTableConstraints(ATableName: string; var SqlQuery: TSQLQuery;
    ConstraintsList: TStringList = nil): Boolean;
 begin
-  //todo: rewrite this to return an array of record (constraint name, number of columns)
-  //make another function that checks the array and returns the number of columns for a constraint name
-  //this will allow caching, running the query only once per table to fill the array
   SqlQuery.Close;
 // Note that this query differs from the way constraints are
 // presented in GetConstraintsOfTable.
@@ -567,7 +564,10 @@ begin
 
   if sqQuery.RecordCount > 0 then
   begin
-    DomainType:= fmMain.GetFBTypeName(sqQuery.FieldByName('RDB$FIELD_TYPE').AsInteger);
+    DomainType:= fmMain.GetFBTypeName(sqQuery.FieldByName('RDB$FIELD_TYPE').AsInteger,
+      sqQuery.FieldByName('RDB$FIELD_SUB_TYPE').AsInteger,
+      sqQuery.FieldByName('RDB$FIELD_LENGTH').AsInteger,
+      sqQuery.FieldByName('RDB$FIELD_SCALE').AsInteger);
     DomainSize:= sqQuery.FieldByName('RDB$FIELD_LENGTH').AsInteger;
     DefaultValue:= sqQuery.FieldByName('RDB$DEFAULT_SOURCE').AsString;
   end
@@ -805,7 +805,7 @@ begin
       '    WHEN 14 THEN ''CHAR'' ' +
       '    WHEN 40 THEN ''CSTRING''  ' +
       '    WHEN 11 THEN ''D_FLOAT'' ' +
-      '    WHEN 27 THEN ''DOUBLE Precision'' ' +
+      '    WHEN 27 THEN ''DOUBLE'' ' +
       '    WHEN 10 THEN ''FLOAT'' ' +
       '    WHEN 16 THEN ''BIGINT'' ' +
       '    WHEN 8 THEN ''INTEGER'' ' +
@@ -835,6 +835,7 @@ begin
   begin
     with sqQuery do
     begin
+      // to do: rewrite using function
       FieldType:= Trim(FieldByName('Field_Type_Str').AsString);
       // Array should really be [lowerbound:upperbound] (if dimension is 0)
       // but for now don't bother as arrays are not supported anyway
@@ -1016,6 +1017,8 @@ var
   FieldName: string;
 begin
   Init(dbIndex);
+  //todo: check all references to this query and rewrite using function for field type
+  //instead of field_type_str
   sqQuery.SQL.Text:= 'SELECT r.RDB$FIELD_NAME AS field_name, ' +
       '  r.RDB$DESCRIPTION AS field_description, ' +
       '  r.RDB$DEFAULT_SOURCE AS field_default_value, ' +
@@ -1028,14 +1031,14 @@ begin
       '    WHEN 261 THEN ''BLOB'' ' +
       '    WHEN 14 THEN ''CHAR'' ' +
       '    WHEN 40 THEN ''CSTRING''  ' +
+      '    WHEN 12 THEN ''DATE'' ' +
       '    WHEN 11 THEN ''D_FLOAT'' ' +
-      '    WHEN 27 THEN ''DOUBLE Precision'' ' +
+      '    WHEN 27 THEN ''DOUBLE'' ' +
       '    WHEN 10 THEN ''FLOAT'' ' +
       '    WHEN 16 THEN ''BIGINT'' ' +
       '    WHEN 8 THEN ''INTEGER'' ' +
       '    WHEN 9 THEN ''QUAD'' ' +
       '    WHEN 7 THEN ''SMALLINT'' ' +
-      '    WHEN 12 THEN ''DATE'' ' +
       '    WHEN 13 THEN ''TIME'' ' +
       '    WHEN 35 THEN ''TIMESTAMP'' ' +
       '    WHEN 37 THEN ''VARCHAR'' ' +
@@ -1051,18 +1054,17 @@ begin
       ' LEFT JOIN RDB$CHARACTER_SETS cset ON f.RDB$CHARACTER_SET_ID = cset.RDB$CHARACTER_SET_ID ' +
       ' WHERE r.RDB$RELATION_NAME=''' + ATableName + '''  ' +
       ' ORDER BY r.RDB$FIELD_POSITION;';
-
-    sqQuery.Open;
-    FieldsList.Clear;
-    // Todo: add support for array datatype (see other code referencing RDB$FIELD_DIMENSIONS table)
-    while not sqQuery.EOF do
-    begin
-      FieldName:= Trim(sqQuery.FieldByName('field_name').AsString);
-      if FieldsList.IndexOf(FieldName) = -1 then
-        FieldsList.Add(FieldName);
-      sqQuery.Next;
-    end;
-    sqQuery.Close;
+  sqQuery.Open;
+  FieldsList.Clear;
+  // Todo: add support for array datatype (see other code referencing RDB$FIELD_DIMENSIONS table)
+  while not sqQuery.EOF do
+  begin
+    FieldName:= Trim(sqQuery.FieldByName('field_name').AsString);
+    if FieldsList.IndexOf(FieldName) = -1 then
+      FieldsList.Add(FieldName);
+    sqQuery.Next;
+  end;
+  sqQuery.Close;
 end;
 
 initialization