mirror of
https://github.com/HeidiSQL/HeidiSQL.git
synced 2026-03-13 09:24:25 +08:00
Fix follow up problems introduced in r3795: DROP DEFAULT on renamed column took the old column name, and the old table name is used also when it was renamed. Revert r3795, move DROP DEFAULT clauses before the main ALTER query, and introduce a .OldDataType property on TTableColumn to check if that can have a default value.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user