diff --git a/source/apphelpers.pas b/source/apphelpers.pas index 5bf28d7f..651b2419 100644 --- a/source/apphelpers.pas +++ b/source/apphelpers.pas @@ -422,6 +422,7 @@ type procedure FindComponentInstances(BaseForm: TComponent; ClassType: TClass; var List: TObjectList); function WebColorStrToColorDef(WebColor: string; Default: TColor): TColor; function UserAgent(OwnerComponent: TComponent): String; + function CodeIndent(Steps: Integer=1): String; var AppSettings: TAppSettings; @@ -2999,6 +3000,16 @@ begin end; +function CodeIndent(Steps: Integer=1): String; +begin + // Provide tab or spaces for indentation, uniquely used for all SQL statements + if AppSettings.ReadBool(asTabsToSpaces) then + Result := StringOfChar(' ', AppSettings.ReadInt(asTabWidth) * Steps) + else + Result := StringOfChar(#9, Steps); +end; + + { Get SID of current Windows user, probably useful in the future function GetCurrentUserSID: string; type diff --git a/source/copytable.pas b/source/copytable.pas index 39f1022b..c19ab0b7 100644 --- a/source/copytable.pas +++ b/source/copytable.pas @@ -357,12 +357,12 @@ var Column: TTableColumn; Key: TTableKey; ForeignKey: TForeignKey; -const - ClausePattern: String = #9 + '%s,' + CRLF; + ClausePattern: String; begin // Compose and run CREATE query TargetTable := FConnection.QuotedDbAndTableName(comboDatabase.Text, editNewTablename.Text); + ClausePattern := CodeIndent + '%s,' + sLineBreak; // Watch out if target table exists try diff --git a/source/csv_detector.pas b/source/csv_detector.pas index 9eb424c7..61d611b3 100644 --- a/source/csv_detector.pas +++ b/source/csv_detector.pas @@ -359,7 +359,7 @@ begin TableName := FConnection.CleanIdent(TableName); Result := 'CREATE TABLE '+FConnection.QuoteIdent(FLoadDataFrm.comboDatabase.Text)+'.'+FConnection.QuoteIdent(TableName)+' (' + sLineBreak; for Col in Columns do begin - Result := Result + #9 + Col.SQLCode; + Result := Result + CodeIndent + Col.SQLCode; if Col <> Columns.Last then Result := Result + ','; Result := Result + sLineBreak; diff --git a/source/dbconnection.pas b/source/dbconnection.pas index 4f69ea2d..280a7f2f 100644 --- a/source/dbconnection.pas +++ b/source/dbconnection.pas @@ -4077,25 +4077,25 @@ begin Result := 'CREATE TABLE '+QuoteIdent(Obj.Name)+' ('; TableCols := Obj.GetTableColumns; for TableCol in TableCols do begin - Result := Result + CRLF + #9 + TableCol.SQLCode + ','; + Result := Result + sLineBreak + CodeIndent + TableCol.SQLCode + ','; end; TableCols.Free; TableKeys := Obj.GetTableKeys; for TableKey in TableKeys do begin - Result := Result + CRLF + #9 + TableKey.SQLCode + ','; + Result := Result + sLineBreak + CodeIndent + TableKey.SQLCode + ','; end; TableKeys.Free; TableForeignKeys := Obj.GetTableForeignKeys; for TableForeignKey in TableForeignKeys do begin - Result := Result + CRLF + #9 + TableForeignKey.SQLCode(True) + ','; + Result := Result + sLineBreak + CodeIndent + TableForeignKey.SQLCode(True) + ','; end; TableForeignKeys.Free; TableCheckConstraints := Obj.GetTableCheckConstraints; for TableCheckConstraint in TableCheckConstraints do begin - Result := Result + CRLF + #9 + TableCheckConstraint.SQLCode + ','; + Result := Result + sLineBreak + CodeIndent + TableCheckConstraint.SQLCode + ','; end; TableCheckConstraints.Free; diff --git a/source/event_editor.pas b/source/event_editor.pas index c8940d75..82d7d12b 100644 --- a/source/event_editor.pas +++ b/source/event_editor.pas @@ -272,7 +272,7 @@ begin Result := CreateOrAlter + ' '; if comboDefiner.Text <> '' then Result := Result + 'DEFINER='+DBObject.Connection.QuoteIdent(comboDefiner.Text, True, '@')+' '; - Result := Result + 'EVENT ' + DBObject.Connection.QuoteIdent(ObjName) + CRLF + #9 + 'ON SCHEDULE' + CRLF + #9#9; + Result := Result + 'EVENT ' + DBObject.Connection.QuoteIdent(ObjName) + sLineBreak + CodeIndent + 'ON SCHEDULE' + sLineBreak + CodeIndent(2); if radioOnce.Checked then begin d := dateOnce.DateTime; ReplaceTime(d, timeOnce.DateTime); @@ -297,14 +297,14 @@ begin end; if chkDropAfterExpiration.Checked then - Result := Result + #9 + 'ON COMPLETION NOT PRESERVE' + Result := Result + CodeIndent + 'ON COMPLETION NOT PRESERVE' else - Result := Result + #9 + 'ON COMPLETION PRESERVE'; + Result := Result + CodeIndent + 'ON COMPLETION PRESERVE'; if ObjectExists and (DBObject.Name <> editName.Text) then - Result := Result + CRLF + #9 + 'RENAME TO ' + DBObject.Connection.QuoteIdent(editName.Text); - Result := Result + CRLF + #9 + UpperCase(grpState.Items[grpState.ItemIndex]); - Result := Result + CRLF + #9 + 'COMMENT ' + DBObject.Connection.EscapeString(editComment.Text); - Result := Result + CRLF + #9 + 'DO ' + SynMemoBody.Text; + Result := Result + sLineBreak + CodeIndent + 'RENAME TO ' + DBObject.Connection.QuoteIdent(editName.Text); + Result := Result + sLineBreak + CodeIndent + UpperCase(grpState.Items[grpState.ItemIndex]); + Result := Result + sLineBreak + CodeIndent + 'COMMENT ' + DBObject.Connection.EscapeString(editComment.Text); + Result := Result + sLineBreak + CodeIndent + 'DO ' + SynMemoBody.Text; end; diff --git a/source/exportgrid.pas b/source/exportgrid.pas index 5043f8b2..2e12aa4c 100644 --- a/source/exportgrid.pas +++ b/source/exportgrid.pas @@ -681,47 +681,46 @@ begin case ExportFormat of efHTML: begin Header := - '' + CRLF + CRLF + - '' + CRLF + - '
' + CRLF + - '' + GridData.SQL + '
' + CRLF + CRLF; - Header := Header + '' + Grid.Header.Columns[Col].Text + ' | ' + CRLF; + Header := Header + CodeIndent(5) + '' + Grid.Header.Columns[Col].Text + ' | ' + sLineBreak; Col := Grid.Header.Columns.GetNextVisibleColumn(Col); end; Header := Header + - '
---|---|
' + Data + ' | ' + CRLF; + tmp := tmp + CodeIndent(5) + '' + Data + ' | ' + sLineBreak; end; efExcel, efCSV: begin @@ -994,7 +993,7 @@ begin efXML: begin // Print cell start tag. - tmp := tmp + #9#9'
' + CRLF + - ' generated ' + DateToStr(now) + ' ' + TimeToStr(now) + - ' by ' + APPNAME + ' ' + Mainform.AppVersion + '' + CRLF + - '
' + CRLF + CRLF + - ' ' + CRLF + - '' + CRLF; + CodeIndent(3) + '' + sLineBreak + + CodeIndent(2) + '' + sLineBreak + + CodeIndent(3) + 'generated ' + DateToStr(now) + ' ' + TimeToStr(now) + + CodeIndent(3) + 'by ' + APPNAME + ' ' + Mainform.AppVersion + '' + sLineBreak + + CodeIndent(2) + '
' + sLineBreak + sLineBreak + + CodeIndent + '