Kaynağa Gözat

Merge branch 'master' of https://github.com/motaz/turbobird

motaz 11 yıl önce
ebeveyn
işleme
6c4a5a634d
3 değiştirilmiş dosya ile 123 ekleme ve 104 silme
  1. 32 20
      main.pas
  2. 64 69
      querywindow.pas
  3. 27 15
      systables.pas

+ 32 - 20
main.pas

@@ -1411,11 +1411,10 @@ begin
   if SubType = 0 then
   begin
     case FieldType of
-        7: Result:= 'SMALLINT';
-        8: Result:= 'INTEGER';
-        16: Result:= 'BIGINT';
+      7: Result:= 'SMALLINT';
+      8: Result:= 'INTEGER';
+      16: Result:= 'BIGINT';
     end;
-
   end
   else
   begin
@@ -1425,10 +1424,10 @@ begin
     if SubType = 2 then
       Result:= 'Decimal(';
     case FieldLength of
-        4: Result:= Result + '9,';
-        8: Result:= Result + '18,';
-      else
-        Result:= Result + IntToStr(FieldLength) + ',';
+      4: Result:= Result + '9,';
+      8: Result:= Result + '18,';
+    else
+      Result:= Result + IntToStr(FieldLength) + ',';
     end;
     Result:= Result + IntToStr(Abs(Scale)) + ') ';
   end;
@@ -2507,27 +2506,30 @@ begin
       '  f.RDB$FIELD_SUB_TYPE AS field_subtype, ' +
       '  coll.RDB$COLLATION_NAME AS field_collation, ' +
       '  cset.RDB$CHARACTER_SET_NAME AS field_charset, ' +
-      ' f.RDB$COMPUTED_Source AS Computed_Source ' +
+      ' f.RDB$COMPUTED_Source AS Computed_Source, ' +
+      ' dim.RDB$UPPER_BOUND AS Array_Upper_Bound ' +
       ' FROM RDB$RELATION_FIELDS r ' +
       ' LEFT JOIN RDB$FIELDS f ON r.RDB$FIELD_SOURCE = f.RDB$FIELD_NAME ' +
       ' LEFT JOIN RDB$COLLATIONS coll ON f.RDB$COLLATION_ID = coll.RDB$COLLATION_ID ' +
       ' LEFT JOIN RDB$CHARACTER_SETS cset ON f.RDB$CHARACTER_SET_ID = cset.RDB$CHARACTER_SET_ID ' +
+      ' LEFT JOIN RDB$FIELD_DIMENSIONS dim ON f.RDB$FIELD_NAME = dim.RDB$FIELD_NAME ' +
       ' WHERE r.RDB$RELATION_NAME=''' + ATableName + '''  ' +
       ' ORDER BY r.RDB$FIELD_POSITION;';
 
-    SQLQuery1.Open;
-    if FieldsList <> nil then
+  SQLQuery1.Open;
+  // Fill field list if needed
+  if FieldsList <> nil then
+  begin
+    FieldsList.Clear;
+    while not SQLQuery1.EOF do
     begin
-      FieldsList.Clear;
-      while not SQLQuery1.EOF do
-      begin
-        FieldName:= Trim(SQLQuery1.FieldByName('field_name').AsString);
-        if FieldsList.IndexOf(FieldName) = -1 then
-          FieldsList.Add(FieldName);
-        SQLQuery1.Next;
-      end;
-      SQLQuery1.First;
+      FieldName:= Trim(SQLQuery1.FieldByName('field_name').AsString);
+      if FieldsList.IndexOf(FieldName) = -1 then
+        FieldsList.Add(FieldName);
+      SQLQuery1.Next;
     end;
+  end;
+  SQLQuery1.First;
 end;
 
 (**********  Get Stored Proc body  ****************)
@@ -3093,6 +3095,16 @@ begin
         else
           Cells[2, RowCount - 1]:= Trim(FieldByName('Field_Type_Str').AsString);
 
+        // Correct field type if it is an array type
+        // Array should really be [upper_bound dim0,upperbound dim1,..]
+        // but for now don't bother as arrays are not supported anyway
+        // Assume dimension 0, just fill in upper bound
+        if not(FieldByName('Array_Upper_Bound').IsNull) then
+          Cells[2, RowCount - 1]:=Cells[2, RowCount - 1] +
+            ' [' +
+            SQLQuery1.FieldByName('Array_Upper_Bound').AsString +
+            ']';
+
         // Computed fields (Calculated)
         if FieldByName('Computed_Source').AsString <> '' then
           Cells[2, RowCount - 1]:= FieldByName('Computed_Source').AsString;

+ 64 - 69
querywindow.pas

@@ -412,66 +412,66 @@ begin
         // Check modified fields
         for i:= Low(ModifiedRecords[TabIndex]) to High(ModifiedRecords[TabIndex]) do
         begin
-         FieldsSQL:= '';
-         RecordSet.RecNo:= ModifiedRecords[TabIndex][i];
-         for x:= 0 to RecordSet.Fields.Count - 1 do
-         if FieldsList.IndexOf(RecordSet.Fields[x].FieldName) <> -1 then // Field exist in origional table
+          FieldsSQL:= '';
+          RecordSet.RecNo:= ModifiedRecords[TabIndex][i];
+          for x:= 0 to RecordSet.Fields.Count - 1 do
+          begin
+            if (FieldsList.IndexOf(RecordSet.Fields[x].FieldName) <> -1) and  // Field exist in origional table
+              (RecordSet.Fields[x].NewValue <> RecordSet.Fields[x].OldValue) then // field data has been modified
+            begin
+              if FieldsSQL <> '' then
+                FieldsSQL += ',';
+              FieldsSQL += RecordSet.Fields[x].FieldName + '=';
+
+              // Typecast field values according to thier main type
+              case RecordSet.Fields[x].DataType of
+                ftInteger, ftSmallint: FieldsSQL += IntToStr(RecordSet.Fields[x].NewValue);
+                ftFloat: FieldsSQL += FloatToStr(RecordSet.Fields[x].NewValue);
+                ftTimeStamp, ftDateTime: FieldsSQL += '''' + DateTimeToStr(RecordSet.Fields[x].NewValue) + '''';
+                ftTime: FieldsSQL += '''' + TimeToStr(RecordSet.Fields[x].NewValue) + '''';
+                ftDate: FieldsSQL += '''' + DateToStr(RecordSet.Fields[x].NewValue) + '''';
+              else // Other types like string
+                FieldsSQL += '''' + RecordSet.Fields[x].NewValue + '''';
+              end;
+            end;
+          end;
 
-         if (RecordSet.Fields[x].NewValue <> RecordSet.Fields[x].OldValue) then // field data has been modified
-         begin
+          // Update current record
           if FieldsSQL <> '' then
-              FieldsSQL += ',';
-            FieldsSQL += RecordSet.Fields[x].FieldName + '=';
+          begin
+            aQuery.Close;
+            aQuery.SQL.Text:= 'update ' + aTableName + ' set ' + FieldsSQL;
 
-            // Typecast field values according to thier main type
-            case RecordSet.Fields[x].DataType of
-             ftInteger, ftSmallint: FieldsSQL += IntToStr(RecordSet.Fields[x].NewValue);
-             ftFloat: FieldsSQL += FloatToStr(RecordSet.Fields[x].NewValue);
-             ftTimeStamp, ftDateTime: FieldsSQL += '''' + DateTimeToStr(RecordSet.Fields[x].NewValue) + '''';
-             ftTime: FieldsSQL += '''' + TimeToStr(RecordSet.Fields[x].NewValue) + '''';
-             ftDate: FieldsSQL += '''' + DateToStr(RecordSet.Fields[x].NewValue) + '''';
+            WhereClause:= 'where ';
+            // where clause
+            for x:= 0 to KeyList.Count - 1 do
+            begin
+              if Trim(KeyList[x]) <> '' then
+              begin
+                WhereClause += KeyList[x] + ' = ';
+
+                // Typecast index values
+                case RecordSet.Fields[x].DataType of
+                  ftInteger, ftSmallint: WhereClause += IntToStr(RecordSet.Fields[x].OldValue);
+                  ftFloat: WhereClause += FloatToStr(RecordSet.Fields[x].OldValue);
+                else
+                  WhereClause += '''' + RecordSet.Fields[x].OldValue + '''';
+                end;
+                if x < KeyList.Count - 1 then
+                  WhereClause += ' and ';
+              end;
+            end;
 
-            else // Other types like string
-               FieldsSQL += '''' + RecordSet.Fields[x].NewValue + '''';
+            aQuery.SQL.Add(WhereClause);
+            aQuery.ExecSQL;
+            (Sender as TBitBtn).Visible:= False;
 
+            // Auto commit
+            if cxAutoCommit.Checked then
+              SqlTrans.CommitRetaining
+            else
+              EnableCommitButton;
           end;
-         end;
-
-
-         // Update current record
-         if FieldsSQL <> '' then
-         begin
-           aQuery.Close;
-           aQuery.SQL.Text:= 'update ' + aTableName + ' set ' + FieldsSQL;
-
-           WhereClause:= 'where ';
-           // where clause
-           for x:= 0 to KeyList.Count - 1 do
-           if Trim(KeyList[x]) <> '' then
-           begin
-             WhereClause += KeyList[x] + ' = ';
-
-             // Typecase index values
-             case RecordSet.Fields[x].DataType of
-              ftInteger, ftSmallint: WhereClause += IntToStr(RecordSet.Fields[x].OldValue);
-              ftFloat: WhereClause += FloatToStr(RecordSet.Fields[x].OldValue);
-             else
-                WhereClause += '''' + RecordSet.Fields[x].OldValue + '''';
-             end;
-             if x < KeyList.Count - 1 then
-               WhereClause += ' and ';
-           end;
-
-           aQuery.SQL.Add(WhereClause);
-           aQuery.ExecSQL;
-           (Sender as TBitBtn).Visible:= False;
-
-           // Auto commit
-           if cxAutoCommit.Checked then
-             SqlTrans.CommitRetaining
-           else
-             EnableCommitButton;
-         end;
         end;
 
         // Reset ModifedRecords pointer
@@ -485,16 +485,12 @@ begin
     end
     else
       ShowMessage('There is no primary key on the table: ' + aTableName);
-
-
   except
-  on e: exception do
-  begin
-    ShowMessage('Error in save data: ' + e.Message);
-  end;
-
+    on e: exception do
+    begin
+      ShowMessage('Error in save data: ' + e.Message);
+    end;
   end;
-
 end;
 
 { EnableApplyButton: enable save updates button when records have been modified }
@@ -670,14 +666,13 @@ begin
     Error:= False;
     DoJob;
     fTerminated:= True;
-
   except
-  on e: exception do
-  begin
-    Error:= True;
-    ErrorMsg:= e.Message;
-    fTerminated:= True;
-  end;
+    on e: exception do
+    begin
+      Error:= True;
+      ErrorMsg:= e.Message;
+      fTerminated:= True;
+    end;
   end;
 end;
 

+ 27 - 15
systables.pas

@@ -659,7 +659,6 @@ begin
     Result:= 8
   else
     Result:= GetDomainTypeSize(dbIndex, TypeName);
-
 end;
 
 function TdmSysTables.GetDomainTypeSize(dbIndex: Integer; DomainTypeName: string): Integer;
@@ -700,29 +699,41 @@ begin
       '    WHEN 37 THEN ''VARCHAR'' ' +
       '    ELSE ''UNKNOWN'' ' +
       '  END AS field_type_Str, ' +
-      '  f.RDB$FIELD_SUB_TYPE AS field_subtype, ' +
-      '  coll.RDB$COLLATION_NAME AS field_collation, ' +
-      '  cset.RDB$CHARACTER_SET_NAME AS field_charset, ' +
-      ' f.RDB$COMPUTED_Source AS Computed_Source ' +
+      ' f.RDB$FIELD_SUB_TYPE AS field_subtype, ' +
+      ' coll.RDB$COLLATION_NAME AS field_collation, ' +
+      ' cset.RDB$CHARACTER_SET_NAME AS field_charset, ' +
+      ' f.RDB$COMPUTED_Source AS Computed_Source, ' +
+      ' dim.RDB$UPPER_BOUND AS Array_Upper_Bound ' +
       ' FROM RDB$RELATION_FIELDS r ' +
       ' LEFT JOIN RDB$FIELDS f ON r.RDB$FIELD_SOURCE = f.RDB$FIELD_NAME ' +
       ' LEFT JOIN RDB$COLLATIONS coll ON f.RDB$COLLATION_ID = coll.RDB$COLLATION_ID ' +
       ' LEFT JOIN RDB$CHARACTER_SETS cset ON f.RDB$CHARACTER_SET_ID = cset.RDB$CHARACTER_SET_ID ' +
+      ' LEFT JOIN RDB$FIELD_DIMENSIONS dim on f.RDB$FIELD_NAME = dim.RDB$FIELD_NAME '+
       ' WHERE r.RDB$RELATION_NAME=''' + TableName + '''  and Trim(r.RDB$FIELD_NAME) = ''' + UpperCase(FieldName) + ''' ' +
-      ' ORDER BY r.RDB$FIELD_POSITION';
+      ' ORDER BY r.RDB$FIELD_POSITION ';
   sqQuery.Open;
   Result:= sqQuery.RecordCount > 0;
   if Result then
-  with sqQuery do
   begin
-    FieldType:= Trim(FieldByName('Field_Type_Str').AsString);
-    if FieldByName('Field_Type_int').AsInteger = 37 then // VarChar
-      FieldSize:= FieldByName('Character_Leng').AsInteger
-    else
-      FieldSize:= FieldByName('Field_Length').AsInteger;
-    NotNull:= FieldByName('Field_not_null_constraint').AsString = '1';
-    DefaultValue:= FieldByName('Field_Default_Value').AsString;
-    Description:= FieldByName('Field_Description').AsString;
+    with sqQuery do
+    begin
+      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
+      // Assume 0 dimension, 1 lower bound; just fill in upper bound
+      if not(FieldByName('Array_Upper_Bound').IsNull) then
+        FieldType := FieldType +
+          ' [' +
+          FieldByName('Array_Upper_Bound').AsString +
+          ']';
+      if FieldByName('Field_Type_int').AsInteger = 37 then // VarChar
+        FieldSize:= FieldByName('Character_Leng').AsInteger
+      else
+        FieldSize:= FieldByName('Field_Length').AsInteger;
+      NotNull:= FieldByName('Field_not_null_constraint').AsString = '1';
+      DefaultValue:= FieldByName('Field_Default_Value').AsString;
+      Description:= FieldByName('Field_Description').AsString;
+    end;
   end;
   sqQuery.Close;
 end;
@@ -925,6 +936,7 @@ begin
 
     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);