diff --git a/source/dbconnection.pas b/source/dbconnection.pas index 51da75b0..6d9c8b60 100644 --- a/source/dbconnection.pas +++ b/source/dbconnection.pas @@ -230,7 +230,7 @@ type procedure SetStatus(Value: TEditingStatus); public Name, OldName: String; - DataType: TDBDatatype; + DataType, OldDataType: TDBDatatype; LengthSet: String; Unsigned, AllowNull, ZeroFill, LengthCustomized: Boolean; DefaultType: TColumnDefaultType; @@ -2698,6 +2698,7 @@ begin // Datatype Col.DataType := GetDatatypeByName(UpperCase(rx.Match[2])); + Col.OldDataType := GetDatatypeByName(UpperCase(rx.Match[2])); // Length / Set // Various datatypes, e.g. BLOBs, don't have any length property diff --git a/source/table_editor.pas b/source/table_editor.pas index e0d09922..823a60cb 100644 --- a/source/table_editor.pas +++ b/source/table_editor.pas @@ -484,6 +484,19 @@ begin end; AddQuery; + // Special case for removed default values on columns, which can neither be done in + // ALTER TABLE ... CHANGE COLUMN query, as there is no "no default" clause, nor by + // appending an ALTER COLUMN ... DROP DEFAULT, without getting an "unknown column" error. + // Also, do this after the data type was altered, if from TEXT > VARCHAR e.g. + for i:=0 to FColumns.Count-1 do begin + if (FColumns[i].FStatus = esModified) + and (FColumns[i].DefaultType = cdtNothing) + and (FColumns[i].OldDataType.HasDefault) + then + Specs.Add('ALTER '+DBObject.Connection.QuoteIdent(FColumns[i].OldName)+' DROP DEFAULT'); + end; + AddQuery; + if editName.Text <> DBObject.Name then Specs.Add('RENAME TO ' + DBObject.Connection.QuoteIdent(editName.Text)); if memoComment.Tag = ModifiedFlag then @@ -607,19 +620,6 @@ begin AddQuery; - // Special case for removed default values on columns, which can neither be done in - // ALTER TABLE ... CHANGE COLUMN query, as there is no "no default" clause, nor by - // appending an ALTER COLUMN ... DROP DEFAULT, without getting an "unknown column" error. - // Also, do this after the data type was altered, if from TEXT > VARCHAR e.g. - for i:=0 to FColumns.Count-1 do begin - if (FColumns[i].FStatus = esModified) - and (FColumns[i].DefaultType = cdtNothing) - and (FColumns[i].DataType.HasDefault) - then - Specs.Add('ALTER '+DBObject.Connection.QuoteIdent(FColumns[i].OldName)+' DROP DEFAULT'); - end; - AddQuery; - FreeAndNil(Specs); Mainform.ShowStatusMsg; Mainform.ProgressBarStatus.Hide;