From c568e1ccffd019add87338c1fc67cf1e604f4886 Mon Sep 17 00:00:00 2001 From: Ansgar Becker Date: Fri, 6 Feb 2026 14:10:26 +0100 Subject: [PATCH] fix: keep column default value in table editor, when user changes its datatype to one in the same category as before (int => bigint) Refs #1374 --- source/table_editor.pas | 60 ++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/source/table_editor.pas b/source/table_editor.pas index 3c714a72..94d845eb 100644 --- a/source/table_editor.pas +++ b/source/table_editor.pas @@ -1580,6 +1580,7 @@ var Col: PTableColumn; Key: TTableKey; WasModified: Boolean; + OldDatatype: TDBDatatype; begin // Column property edited Col := Sender.GetNodeData(Node); @@ -1603,6 +1604,7 @@ begin end; ColNumDatatype: begin + OldDatatype := Col.DataType; Col.DataType := DBObject.Connection.GetDatatypeByName(NewText, False, Col.Name); // Reset length/set for column types which don't support that if not Col.DataType.HasLength then @@ -1621,34 +1623,36 @@ begin if (not Col.LengthCustomized) or (Col.DataType.RequiresLength and (Col.LengthSet = '')) then Col.LengthSet := Col.DataType.DefLengthSet; // Auto-change default type and text - if not Col.DataType.HasDefault then begin - Col.DefaultType := cdtNothing; - Col.DefaultText := ''; - end else begin - // Auto-fix user selected default type which can be invalid now - case Col.DataType.Category of - dtcInteger: begin - Col.DefaultType := cdtExpression; - if Col.AllowNull then - Col.DefaultType := cdtNull - else - Col.DefaultText := IntToStr(MakeInt(Col.DefaultText)); - end; - dtcReal: begin - Col.DefaultType := cdtExpression; - if Col.AllowNull then - Col.DefaultType := cdtNull - else - Col.DefaultText := FloatToStr(MakeFloat(Col.DefaultText)); - end; - dtcText, dtcBinary, dtcSpatial, dtcOther: begin - Col.DefaultType := cdtText; - if Col.AllowNull then - Col.DefaultType := cdtNull; - end; - dtcTemporal: begin - if Col.DefaultType = cdtAutoinc then - Col.DefaultType := cdtNothing; + if Col.DataType.Category <> OldDatatype.Category then begin + if not Col.DataType.HasDefault then begin + Col.DefaultType := cdtNothing; + Col.DefaultText := ''; + end else begin + // Auto-fix user selected default type which can be invalid now + case Col.DataType.Category of + dtcInteger: begin + Col.DefaultType := cdtExpression; + if Col.AllowNull then + Col.DefaultType := cdtNull + else + Col.DefaultText := IntToStr(MakeInt(Col.DefaultText)); + end; + dtcReal: begin + Col.DefaultType := cdtExpression; + if Col.AllowNull then + Col.DefaultType := cdtNull + else + Col.DefaultText := FloatToStr(MakeFloat(Col.DefaultText)); + end; + dtcText, dtcBinary, dtcSpatial, dtcOther: begin + Col.DefaultType := cdtText; + if Col.AllowNull then + Col.DefaultType := cdtNull; + end; + dtcTemporal: begin + if Col.DefaultType = cdtAutoinc then + Col.DefaultType := cdtNothing; + end; end; end; end;