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:
Ansgar Becker
2011-04-30 05:07:50 +00:00
parent 1e6c79372e
commit 52c57c84e3
2 changed files with 15 additions and 14 deletions

View File

@@ -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

View File

@@ -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;