From 686ef30fb4ebc0abbffbefae6810c5e666a3dab6 Mon Sep 17 00:00:00 2001 From: Ansgar Becker Date: Fri, 16 May 2025 14:44:38 +0200 Subject: [PATCH] Issue #1853: try to fix column definition changes on MS SQL wrt collation quoting and default value --- source/dbconnection.pas | 8 +++++--- source/table_editor.pas | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/source/dbconnection.pas b/source/dbconnection.pas index 2ad8a150..112e6652 100644 --- a/source/dbconnection.pas +++ b/source/dbconnection.pas @@ -10904,6 +10904,7 @@ end; function TTableColumn.SQLCode(OverrideCollation: String=''; Parts: TColumnParts=[cpAll]): String; var IsVirtual: Boolean; + QuoteCollation: Boolean; function InParts(Part: TColumnPart): Boolean; begin @@ -10941,7 +10942,7 @@ begin Result := Result + 'INVISIBLE '; end; - if InParts(cpAllowNull) and (not IsVirtual) then begin + if InParts(cpAllowNull) and (not IsVirtual) and (not FConnection.Parameters.IsAnyMSSQL) then begin if not AllowNull then Result := Result + 'NOT NULL ' else if not FConnection.Parameters.IsAnyInterbase then @@ -10998,10 +10999,11 @@ begin if InParts(cpCollation) and (not IsVirtual) and (DataType.Index <> dbdtJson) then begin if Collation <> '' then begin Result := Result + 'COLLATE '; + QuoteCollation := not FConnection.Parameters.IsAnyMSSQL; if OverrideCollation <> '' then - Result := Result + FConnection.EscapeString(OverrideCollation) + ' ' + Result := Result + IfThen(QuoteCollation, FConnection.EscapeString(OverrideCollation), OverrideCollation) + ' ' else - Result := Result + FConnection.EscapeString(Collation) + ' '; + Result := Result + IfThen(QuoteCollation, FConnection.EscapeString(Collation), Collation) + ' '; end; end; diff --git a/source/table_editor.pas b/source/table_editor.pas index e33dc62c..348d852b 100644 --- a/source/table_editor.pas +++ b/source/table_editor.pas @@ -725,7 +725,7 @@ begin ColSpec := Col.SQLCode(OverrideCollation); case Col.Status of esModified: begin - Specs.Add(Format(AlterColBase, [Conn.QuoteIdent(Col.OldName), ColSpec])); + Specs.Add(Format(AlterColBase, ['', ColSpec])); end; esAddedUntouched, esAddedModified: begin Specs.Add(Format(AddColBase, [ColSpec]));