Przeglądaj źródła

Use LineEnding instead of hardcoded #10 so SQL errors are more comprehensible on Windows

Reinier Olislagers 11 lat temu
rodzic
commit
279eff1b00
10 zmienionych plików z 60 dodań i 63 usunięć
  1. 4 4
      comparison.pas
  2. 1 1
      copytable.pas
  3. 18 19
      main.pas
  4. 7 7
      neweditfield.pas
  5. 4 4
      newtable.pas
  6. 5 5
      permissionmanage.pas
  7. 1 6
      querywindow.pas
  8. 3 0
      scriptdb.pas
  9. 14 14
      systables.pas
  10. 3 3
      tablemanage.pas

+ 4 - 4
comparison.pas

@@ -470,8 +470,8 @@ begin
         begin
           if IsPrimary then
           begin
-            Line:= 'alter table ' + ATableName + #13#10 +
-            'add constraint ' + AIndexName + #13#10 +
+            Line:= 'alter table ' + ATableName + LineEnding +
+            'add constraint ' + AIndexName + LineEnding +
             'primary key (' + FieldsList.CommaText + ');';
 
           end
@@ -1323,8 +1323,8 @@ begin
         begin
           fQueryWindow.meQuery.Lines.Add('alter table AAAA DROP constraint ' + ConstraintName + ';');
 
-          Line:= 'alter table ' + ATableName + #13#10 +
-          'add constraint ' + AIndexName + #13#10 +
+          Line:= 'alter table ' + ATableName + LineEnding +
+          'add constraint ' + AIndexName + LineEnding +
           'primary key (' + FieldsList.CommaText + ')';
 
         end

+ 1 - 1
copytable.pas

@@ -151,7 +151,7 @@ begin
           Next;
         end;
         SQLTrans.Commit;
-        ShowMessage(IntToStr(Num) + ' record(s) has been copied' + #10 + 'Don''t forget to set the Generator to the new value, ' +
+        ShowMessage(IntToStr(Num) + ' record(s) has been copied' + LineEnding + 'Don''t forget to set the Generator to the new value, ' +
           'if it does exists');
         dmSysTables.sqQuery.Close;
         Close;

+ 18 - 19
main.pas

@@ -795,12 +795,12 @@ begin
   QWindow.meQuery.ClearAll;
   QWindow.OnCommit:= OnCommitProcedure;
   repeat
-    if Pos(#10, AQueryText) > 0 then
-      Part:= Copy(AQueryText, 1, Pos(#10, AQueryText))
+    if Pos(LineEnding, AQueryText) > 0 then
+      Part:= Copy(AQueryText, 1, Pos(LineEnding, AQueryText))
     else
       Part:= AQueryText;
     Delete(AQueryText, 1, Length(Part));
-    Part:= StringReplace(Part, #10, ' ', [rfReplaceAll]);
+    Part:= StringReplace(Part, LineEnding, ' ', [rfReplaceAll]);
 
     QWindow.meQuery.Lines.Add(Part);
   until AQueryText = '';
@@ -1798,7 +1798,6 @@ begin
         Lines.Add('--     Functions (UDF)');
         Lines.Add('');
         ScriptAllFunctions(dbIndex, List);
-        List.Text:= StringReplace(List.Text, #10, #13#10, [rfReplaceAll]);
         Lines.AddStrings(List);
 
         Lines.Add('');
@@ -2538,7 +2537,7 @@ begin
           end;
           SQLQuery1.Next;
         end;
-        BodyList.Add(')' + #10);
+        BodyList.Add(')' + LineEnding);
       end;
 
       // Get output parameters
@@ -2566,7 +2565,7 @@ begin
           end;
           SQLQuery1.Next;
         end;
-        BodyList.Add(')' + #10);
+        BodyList.Add(')' + LineEnding);
       end;
       SQLQuery1.Close;
 
@@ -2675,15 +2674,15 @@ function TfmMain.GetIndexFields(ATableName, AIndexName: string;
   AQuery: TSQLQuery; var FieldsList: TStringList): Boolean;
 begin
   AQuery.Close;
-  AQuery.SQL.Text:= 'SELECT RDB$INDEX_SEGMENTS.RDB$FIELD_NAME AS field_name, ' + #10 +
-     'RDB$INDICES.RDB$DESCRIPTION AS description, ' +#10 +
-     '(RDB$INDEX_SEGMENTS.RDB$FIELD_POSITION + 1) AS field_position ' +#10 +
-     'FROM RDB$INDEX_SEGMENTS ' +#10 +
-     'LEFT JOIN RDB$INDICES ON RDB$INDICES.RDB$INDEX_NAME = RDB$INDEX_SEGMENTS.RDB$INDEX_NAME ' +#10 +
-     'LEFT JOIN RDB$RELATION_CONSTRAINTS ON RDB$RELATION_CONSTRAINTS.RDB$INDEX_NAME = RDB$INDEX_SEGMENTS.RDB$INDEX_NAME ' +#10 +
-     ' WHERE UPPER(RDB$INDICES.RDB$RELATION_NAME)=''' + UpperCase(ATablename) + '''         -- table name ' +#10 +
-     '  AND UPPER(RDB$INDICES.RDB$INDEX_NAME)=''' + UpperCase(AIndexName) + ''' -- index name ' +#10 +
-     '--  AND RDB$RELATION_CONSTRAINTS.RDB$CONSTRAINT_TYPE IS NULL ' +#10 +
+  AQuery.SQL.Text:= 'SELECT RDB$INDEX_SEGMENTS.RDB$FIELD_NAME AS field_name, ' + LineEnding +
+     'RDB$INDICES.RDB$DESCRIPTION AS description, ' +LineEnding +
+     '(RDB$INDEX_SEGMENTS.RDB$FIELD_POSITION + 1) AS field_position ' +LineEnding +
+     'FROM RDB$INDEX_SEGMENTS ' +LineEnding +
+     'LEFT JOIN RDB$INDICES ON RDB$INDICES.RDB$INDEX_NAME = RDB$INDEX_SEGMENTS.RDB$INDEX_NAME ' +LineEnding +
+     'LEFT JOIN RDB$RELATION_CONSTRAINTS ON RDB$RELATION_CONSTRAINTS.RDB$INDEX_NAME = RDB$INDEX_SEGMENTS.RDB$INDEX_NAME ' +LineEnding +
+     ' WHERE UPPER(RDB$INDICES.RDB$RELATION_NAME)=''' + UpperCase(ATablename) + '''         -- table name ' +LineEnding +
+     '  AND UPPER(RDB$INDICES.RDB$INDEX_NAME)=''' + UpperCase(AIndexName) + ''' -- index name ' +LineEnding +
+     '--  AND RDB$RELATION_CONSTRAINTS.RDB$CONSTRAINT_TYPE IS NULL ' +LineEnding +
      'ORDER BY RDB$INDEX_SEGMENTS.RDB$FIELD_POSITION;';
   AQuery.Open;
   Result:= AQuery.FieldCount > 0;
@@ -2725,7 +2724,7 @@ begin
     Params:= '';
     while not SQLQuery1.EOF do
     begin
-      Params:= Params + #10 + GetFBTypeName(SQLQuery1.FieldByName('RDB$FIELD_TYPE').AsInteger,
+      Params:= Params + LineEnding + GetFBTypeName(SQLQuery1.FieldByName('RDB$FIELD_TYPE').AsInteger,
         SQLQuery1.FieldByName('RDB$FIELD_SUB_TYPE').AsInteger,
         SQLQuery1.FieldByName('RDB$FIELD_LENGTH').AsInteger,
         SQLQuery1.FieldByName('RDB$FIELD_SCALE').AsInteger);
@@ -2736,7 +2735,7 @@ begin
         Params:= Params + ', ';
     end;
     SQLQuery1.Close;
-    Params:= Params + ')' + #10 + #10 + 'Returns ';
+    Params:= Params + ')' + LineEnding + LineEnding + 'Returns ';
 
     {todo: return values can't be determined}
 
@@ -2746,7 +2745,7 @@ begin
     SQLQuery1.Open;
     while not SQLQuery1.EOF do
     begin
-      Params:= Params + #10 + GetFBTypeName(SQLQuery1.FieldByName('RDB$FIELD_TYPE').AsInteger,
+      Params:= Params + LineEnding + GetFBTypeName(SQLQuery1.FieldByName('RDB$FIELD_TYPE').AsInteger,
         SQLQuery1.FieldByName('RDB$FIELD_SUB_TYPE').AsInteger,
         SQLQuery1.FieldByName('RDB$FIELD_LENGTH').AsInteger,
         SQLQuery1.FieldByName('RDB$FIELD_SCALE').AsInteger);
@@ -3168,7 +3167,7 @@ begin
 
     GetViewInfo(dbIndex, AViewName, Columns, ViewBody);
     fmViewView.seScript.Lines.Clear;
-    fmViewView.seScript.Lines.Text:= 'create view "' + AviewName + '" (' + Columns + ')' + #13#10 + ViewBody;
+    fmViewView.seScript.Lines.Text:= 'create view "' + AviewName + '" (' + Columns + ')' + LineEnding + ViewBody;
     PageControl1.ActivePage:= ATab;
     fmViewView.Show;
   end;

+ 7 - 7
neweditfield.pas

@@ -98,7 +98,7 @@ begin
     // Check name change
     if UpperCase(Trim(edFieldName.Text)) <> OldFieldName then
       Line:= 'ALTER TABLE ' + fTableName + ' ALTER ' + OldFieldName + ' TO ' +
-      edFieldName.Text + ';' + #10;
+      edFieldName.Text + ';' + LineEnding;
 
     // check type/size change
     if (cbType.Text <> OldFieldType) or (seSize.Value <> OldFieldSize) then
@@ -107,14 +107,14 @@ begin
         + ' TYPE ' + cbType.Text;
 
       if Pos('CHAR', Line) > 0 then
-        Line:= Line + '(' + IntToStr(seSize.Value) + ');' + #10;
+        Line:= Line + '(' + IntToStr(seSize.Value) + ');' + LineEnding;
     end;
 
     // Field Order
     if seOrder.Value <> OldOrder then
     begin
       Line:= Line + 'ALTER TABLE ' + fTableName + ' ALTER ' + edFieldName.Text + ' POSITION ' +
-        IntToStr(seOrder.Value) + ';' + #10;
+        IntToStr(seOrder.Value) + ';' + LineEnding;
     end;
 
     // Allow Null
@@ -124,9 +124,9 @@ begin
         NullFlag:= 'NULL'
       else
         NullFlag:= '1';
-        Line:= Line + 'UPDATE RDB$RELATION_FIELDS SET RDB$NULL_FLAG = ' + NullFlag + #10 +
+        Line:= Line + 'UPDATE RDB$RELATION_FIELDS SET RDB$NULL_FLAG = ' + NullFlag + LineEnding +
           'WHERE RDB$FIELD_NAME = ''' + UpperCase(Trim(edFieldName.Text)) + ''' AND RDB$RELATION_NAME = ''' +
-          fTableName + '''' + #10;
+          fTableName + '''' + LineEnding;
     end;
 
     // Description
@@ -134,7 +134,7 @@ begin
     begin
       Line:= Line + 'UPDATE RDB$RELATION_FIELDS set RDB$DESCRIPTION = ''' + edDescription.Text +
         '''  where RDB$FIELD_NAME = ''' + UpperCase(Trim(edFieldName.Text)) +
-        ''' and RDB$RELATION_NAME = ''' + fTableName + ''';' + #10;
+        ''' and RDB$RELATION_NAME = ''' + fTableName + ''';' + LineEnding;
     end;
 
     // Default value
@@ -142,7 +142,7 @@ begin
     begin
       Line:= Line + 'UPDATE RDB$RELATION_FIELDS set RDB$Default_Source = ''' + edDefault.Text +
         '''  where RDB$FIELD_NAME = ''' + UpperCase(Trim(edFieldName.Text)) +
-        ''' and RDB$RELATION_NAME = ''' + fTableName + ''';' + #10;
+        ''' and RDB$RELATION_NAME = ''' + fTableName + ''';' + LineEnding;
     end;
 
     if Line <> '' then

+ 4 - 4
newtable.pas

@@ -67,7 +67,7 @@ var
   FieldType: string;
   PKey: string;
 begin
-  Result:= 'create table ' + edNewTable.Text + ' (' + #10;
+  Result:= 'create table ' + edNewTable.Text + ' (' + LineEnding;
   for i:= 1 to StringGrid1.RowCount - 1 do
     if Trim(StringGrid1.Cells[0, i]) <> '' then
     begin
@@ -102,7 +102,7 @@ begin
       end;
 
       if (StringGrid1.RowCount > i + 1) and (Trim(stringGrid1.Cells[0, i + 1]) <> '') then
-        FieldLine:= FieldLine + ',' + #10;
+        FieldLine:= FieldLine + ',' + LineEnding;
       Result:= Result + FieldLine;
     end;
 
@@ -110,9 +110,9 @@ begin
   if PKey <> '' then
   begin
     Delete(PKey, Length(PKey), 1);
-    Result:= Result + ', ' + #10 + ' constraint ' + edNewTable.Text + '_pk_1 primary key (' + PKey + ') ' + #10;
+    Result:= Result + ', ' + LineEnding + ' constraint ' + edNewTable.Text + '_pk_1 primary key (' + PKey + ') ' + LineEnding;
   end;
-  Result:= Result + ');' + #10;
+  Result:= Result + ');' + LineEnding;
 
   // Permission
   if cxGrantPermission.Checked and (Trim(cbRolesUsers.Text) <> '') then

+ 5 - 5
permissionmanage.pas

@@ -293,19 +293,19 @@ begin
   if (Grant) and (not WithGrant) then
   begin
     if OldTableSelectGrant and not cxSelectGrant.Checked and (LowerCase(OptionName) = 'select') then
-      Line:= Line + #10 + 'REVOKE GRANT OPTION FOR SELECT ON ' + ATableName + ' FROM ' + cbUsers.Text + ';';
+      Line:= Line + LineEnding + 'REVOKE GRANT OPTION FOR SELECT ON ' + ATableName + ' FROM ' + cbUsers.Text + ';';
 
     if OldTableUpdateGrant and not cxUpdateGrant.Checked and (LowerCase(OptionName) = 'update') then
-      Line:= Line + #10 + 'REVOKE GRANT OPTION FOR Update ON ' + ATableName + ' FROM ' + cbUsers.Text + ';';
+      Line:= Line + LineEnding + 'REVOKE GRANT OPTION FOR Update ON ' + ATableName + ' FROM ' + cbUsers.Text + ';';
 
     if OldTableReferencesGrant and not cxReferencesGrant.Checked and (LowerCase(OptionName) = 'references') then
-      Line:= Line + #10 + 'REVOKE GRANT OPTION FOR References ON ' + ATableName + ' FROM ' + cbUsers.Text + ';';
+      Line:= Line + LineEnding + 'REVOKE GRANT OPTION FOR References ON ' + ATableName + ' FROM ' + cbUsers.Text + ';';
 
     if OldTableDeleteGrant and not cxDeleteGrant.Checked and (LowerCase(OptionName) = 'delete') then
-      Line:= Line +#10 +  'REVOKE GRANT OPTION FOR Delete ON ' + ATableName + ' FROM ' + cbUsers.Text + ';';
+      Line:= Line +LineEnding +  'REVOKE GRANT OPTION FOR Delete ON ' + ATableName + ' FROM ' + cbUsers.Text + ';';
 
     if OldTableInsertGrant and not cxInsertGrant.Checked and (LowerCase(OptionName) = 'insert') then
-      Line:= Line  +#10 +  'REVOKE GRANT OPTION FOR Insert ON ' + ATableName + ' FROM ' + cbUsers.Text + ';';
+      Line:= Line  +LineEnding +  'REVOKE GRANT OPTION FOR Insert ON ' + ATableName + ' FROM ' + cbUsers.Text + ';';
   end;
 
   List.Add(Line);

+ 1 - 6
querywindow.pas

@@ -1455,11 +1455,6 @@ begin
     try
       ATab.ImageIndex:= 2;
       SQLScript.Script.Text:= Script;
-      {todo: when generating SQL, instead of generating #10 for line endings,
-       use  ASCII 23, ETB/End of Transmit Block
-       when displaying/using, replace ASCII 23 with End Of Line. Gives
-       better error messages on Windows where otherwise we'd have huge lines
-      }
       SQLScript.ExecuteScript;
 
       // Auto commit
@@ -1622,7 +1617,7 @@ begin
     if Pos('begin', Trim(LowerCase(QueryList[i]))) > 0 then
       BeginExists:= True;
 
-    SQLSegment:= SQLSegment + QueryList[i] + #10;
+    SQLSegment:= SQLSegment + QueryList[i] + LineEnding;
 
     if (QueryType in [qtSelectable, qtExecute]) and
       (((Pos(';', QueryList[i]) > 0) and (Not BeginExists)) or

+ 3 - 0
scriptdb.pas

@@ -338,9 +338,12 @@ begin
     List.Clear;
     for i:= 0 to ProceduresList.Count - 1 do
     begin
+      // Insert procedure body...
       ProcedureScript.Text:= fmMain.GetStoredProcBody(dbIndex, ProceduresList[i], SPOwner);
+      // Then put CREATE part above it...
       ProcedureScript.Insert(0, 'SET TERM ^ ;');
       ProcedureScript.Insert(1, 'CREATE Procedure ' + ProceduresList[i]);
+      // ... and closing SET TERM part below it.
       ProcedureScript.Add('^');
       ProcedureScript.Add('SET TERM ; ^');
       ProcedureScript.Add('');

+ 14 - 14
systables.pas

@@ -579,12 +579,12 @@ begin
   begin
     Msg:= sqQuery.FieldByName('RDB$MESSAGE').AsString;
     Description:= sqQuery.FieldByName('RDB$DESCRIPTION').AsString;
-    SqlQuery:= 'CREATE EXCEPTION ' + ExceptionName + #10 +
+    SqlQuery:= 'CREATE EXCEPTION ' + ExceptionName + LineEnding +
       '''' + Msg + ''';';
     if Description<>'' then
-      SQLQuery:= SQLQuery + #10 +
-        'UPDATE RDB$EXCEPTIONS set ' + #10 +
-        'RDB$DESCRIPTION = ''' + Description + ''' ' + #10 +
+      SQLQuery:= SQLQuery + LineEnding +
+        'UPDATE RDB$EXCEPTIONS set ' + LineEnding +
+        'RDB$DESCRIPTION = ''' + Description + ''' ' + LineEnding +
         'where RDB$EXCEPTION_NAME = ''' + ExceptionName + ''';';
   end;
   sqQuery.Close;
@@ -1015,17 +1015,17 @@ function TdmSysTables.GetIndexInfo(dbIndex: Integer; ATableName, AIndexName: str
 begin
   Init(dbIndex);
   sqQuery.Close;
-  sqQuery.SQL.Text:= 'SELECT RDB$Indices.*, RDB$INDEX_SEGMENTS.RDB$FIELD_NAME AS field_name, ' + #10 +
-     'RDB$INDICES.RDB$DESCRIPTION AS description, ' + #10 +
-     '(RDB$INDEX_SEGMENTS.RDB$FIELD_POSITION + 1) AS field_position, ' + #10 +
-     'RDB$RELATION_CONSTRAINTS.RDB$CONSTRAINT_TYPE as IndexType, ' + #10 +
-     'RDB$RELATION_CONSTRAINTS.RDB$CONSTRAINT_Name as ConstraintName' + #10 +
-     'FROM RDB$INDEX_SEGMENTS ' + #10 +
-     'LEFT JOIN RDB$INDICES ON RDB$INDICES.RDB$INDEX_NAME = RDB$INDEX_SEGMENTS.RDB$INDEX_NAME ' + #10 +
+  sqQuery.SQL.Text:= 'SELECT RDB$Indices.*, RDB$INDEX_SEGMENTS.RDB$FIELD_NAME AS field_name, ' + LineEnding +
+     'RDB$INDICES.RDB$DESCRIPTION AS description, ' + LineEnding +
+     '(RDB$INDEX_SEGMENTS.RDB$FIELD_POSITION + 1) AS field_position, ' + LineEnding +
+     'RDB$RELATION_CONSTRAINTS.RDB$CONSTRAINT_TYPE as IndexType, ' + LineEnding +
+     'RDB$RELATION_CONSTRAINTS.RDB$CONSTRAINT_Name as ConstraintName' + LineEnding +
+     'FROM RDB$INDEX_SEGMENTS ' + LineEnding +
+     'LEFT JOIN RDB$INDICES ON RDB$INDICES.RDB$INDEX_NAME = RDB$INDEX_SEGMENTS.RDB$INDEX_NAME ' + LineEnding +
      'LEFT JOIN RDB$RELATION_CONSTRAINTS ON RDB$RELATION_CONSTRAINTS.RDB$INDEX_NAME = RDB$INDEX_SEGMENTS.RDB$INDEX_NAME '
-     + #10 +
-     ' WHERE UPPER(RDB$INDICES.RDB$RELATION_NAME)=''' + UpperCase(ATablename) + '''         -- table name ' + #10 +
-     '  AND UPPER(RDB$INDICES.RDB$INDEX_NAME)=''' + UpperCase(AIndexName) + ''' ' + #10 +
+     + LineEnding +
+     ' WHERE UPPER(RDB$INDICES.RDB$RELATION_NAME)=''' + UpperCase(ATablename) + '''         -- table name ' + LineEnding +
+     '  AND UPPER(RDB$INDICES.RDB$INDEX_NAME)=''' + UpperCase(AIndexName) + ''' ' + LineEnding +
      'ORDER BY RDB$INDEX_SEGMENTS.RDB$FIELD_POSITION;';
   sqQuery.Open;
   Result:= sqQuery.FieldCount > 0;

+ 3 - 3
tablemanage.pas

@@ -245,8 +245,8 @@ begin
 
     if cbIndexType.ItemIndex = 0 then // primary key
     begin
-      QWindow.meQuery.Lines.Text:= 'alter table ' + fTableName + #13#10 +
-      'add constraint ' + edIndexName.Text + #13#10 +
+      QWindow.meQuery.Lines.Text:= 'alter table ' + fTableName + LineEnding +
+      'add constraint ' + edIndexName.Text + LineEnding +
       'primary key (' + Fields + ')';
     end
     else    // Secondary index
@@ -257,7 +257,7 @@ begin
       FirstLine:= FirstLine + cbSortType.Text + ' index ' + edIndexName.Text;
 
 
-      QWindow.meQuery.Lines.Text:= FirstLine + #13+#10 + 'on ' + fTableName + #13#10 + Fields;
+      QWindow.meQuery.Lines.Text:= FirstLine + LineEnding + 'on ' + fTableName + LineEnding + Fields;
     end;
     QWindow.OnCommit:= bbRefreshIndices.OnClick;