mirror of
https://github.com/HeidiSQL/HeidiSQL.git
synced 2025-08-26 11:17:57 +08:00
Fix wrong ALTER code when changing a column name more than one time. Fixes issue #1792.
This commit is contained in:
@ -2845,6 +2845,7 @@ begin
|
|||||||
Col := TTableColumn.Create;
|
Col := TTableColumn.Create;
|
||||||
Columns.Add(Col);
|
Columns.Add(Col);
|
||||||
Col.Name := rx.Match[1];
|
Col.Name := rx.Match[1];
|
||||||
|
Col.OldName := Col.Name;
|
||||||
Col.Status := esUntouched;
|
Col.Status := esUntouched;
|
||||||
|
|
||||||
// Datatype
|
// Datatype
|
||||||
|
@ -426,10 +426,8 @@ begin
|
|||||||
for i:=FColumns.Count-1 downto 0 do begin
|
for i:=FColumns.Count-1 downto 0 do begin
|
||||||
if FColumns[i].Status = esDeleted then
|
if FColumns[i].Status = esDeleted then
|
||||||
FColumns.Delete(i)
|
FColumns.Delete(i)
|
||||||
else begin
|
else
|
||||||
FColumns[i].Status := esUntouched;
|
FColumns[i].Status := esUntouched;
|
||||||
FColumns[i].OldName := '';
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
DeletedKeys.Clear;
|
DeletedKeys.Clear;
|
||||||
for i:=0 to FKeys.Count-1 do begin
|
for i:=0 to FKeys.Count-1 do begin
|
||||||
@ -450,7 +448,7 @@ end;
|
|||||||
function TfrmTableEditor.ComposeAlterStatement: String;
|
function TfrmTableEditor.ComposeAlterStatement: String;
|
||||||
var
|
var
|
||||||
Specs: TStringList;
|
Specs: TStringList;
|
||||||
ColSpec, OldColName, IndexSQL: String;
|
ColSpec, IndexSQL: String;
|
||||||
i: Integer;
|
i: Integer;
|
||||||
Results: TMySQLQuery;
|
Results: TMySQLQuery;
|
||||||
Col, PreviousCol: PTableColumn;
|
Col, PreviousCol: PTableColumn;
|
||||||
@ -534,12 +532,9 @@ begin
|
|||||||
else
|
else
|
||||||
ColSpec := ColSpec + ' AFTER '+Mainform.mask(PreviousCol.Name);
|
ColSpec := ColSpec + ' AFTER '+Mainform.mask(PreviousCol.Name);
|
||||||
end;
|
end;
|
||||||
if Col.Status = esModified then begin
|
if Col.Status = esModified then
|
||||||
OldColName := Col.OldName;
|
Specs.Add('CHANGE COLUMN '+Mainform.mask(Col.OldName) + ' ' + ColSpec)
|
||||||
if OldColName = '' then
|
else if Col.Status in [esAddedUntouched, esAddedModified] then
|
||||||
OldColName := Col.Name;
|
|
||||||
Specs.Add('CHANGE COLUMN '+Mainform.mask(OldColName) + ' ' + ColSpec);
|
|
||||||
end else if Col.Status in [esAddedUntouched, esAddedModified] then
|
|
||||||
Specs.Add('ADD COLUMN ' + ColSpec);
|
Specs.Add('ADD COLUMN ' + ColSpec);
|
||||||
end;
|
end;
|
||||||
PreviousCol := Col;
|
PreviousCol := Col;
|
||||||
@ -548,12 +543,8 @@ begin
|
|||||||
|
|
||||||
// Deleted columns, not available as Node in above loop
|
// Deleted columns, not available as Node in above loop
|
||||||
for i:=0 to FColumns.Count-1 do begin
|
for i:=0 to FColumns.Count-1 do begin
|
||||||
if FColumns[i].Status = esDeleted then begin
|
if FColumns[i].Status = esDeleted then
|
||||||
OldColName := FColumns[i].OldName;
|
Specs.Add('DROP COLUMN '+Mainform.mask(FColumns[i].OldName));
|
||||||
if OldColName = '' then
|
|
||||||
OldColName := FColumns[i].Name;
|
|
||||||
Specs.Add('DROP COLUMN '+Mainform.mask(OldColName));
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// Drop indexes, also changed indexes, which will be readded below
|
// Drop indexes, also changed indexes, which will be readded below
|
||||||
@ -819,10 +810,7 @@ begin
|
|||||||
Node := listColumns.GetFirstSelected;
|
Node := listColumns.GetFirstSelected;
|
||||||
while Assigned(Node) do begin
|
while Assigned(Node) do begin
|
||||||
Col := listColumns.GetNodeData(Node);
|
Col := listColumns.GetNodeData(Node);
|
||||||
if Col.OldName <> '' then begin
|
|
||||||
Col.Name := Col.OldName;
|
Col.Name := Col.OldName;
|
||||||
Col.OldName := '';
|
|
||||||
end;
|
|
||||||
Col.Status := esDeleted;
|
Col.Status := esDeleted;
|
||||||
Node := listColumns.GetNextSelected(Node);
|
Node := listColumns.GetNextSelected(Node);
|
||||||
end;
|
end;
|
||||||
@ -1124,7 +1112,6 @@ begin
|
|||||||
Exit;
|
Exit;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
Col.OldName := Col.Name;
|
|
||||||
Col.Name := NewText;
|
Col.Name := NewText;
|
||||||
end;
|
end;
|
||||||
2: begin // Data type
|
2: begin // Data type
|
||||||
|
Reference in New Issue
Block a user