From 1ef9ebf07bc33b0ed0ad96d3d41dc0cade8bb84b Mon Sep 17 00:00:00 2001 From: Ansgar Becker Date: Wed, 24 Mar 2010 17:18:48 +0000 Subject: [PATCH] Fix wrong ALTER code when changing a column name more than one time. Fixes issue #1792. --- source/helpers.pas | 1 + source/table_editor.pas | 29 ++++++++--------------------- 2 files changed, 9 insertions(+), 21 deletions(-) diff --git a/source/helpers.pas b/source/helpers.pas index 5d892ada..618723a8 100644 --- a/source/helpers.pas +++ b/source/helpers.pas @@ -2845,6 +2845,7 @@ begin Col := TTableColumn.Create; Columns.Add(Col); Col.Name := rx.Match[1]; + Col.OldName := Col.Name; Col.Status := esUntouched; // Datatype diff --git a/source/table_editor.pas b/source/table_editor.pas index 01b9ad94..15b4a8dc 100644 --- a/source/table_editor.pas +++ b/source/table_editor.pas @@ -426,10 +426,8 @@ begin for i:=FColumns.Count-1 downto 0 do begin if FColumns[i].Status = esDeleted then FColumns.Delete(i) - else begin + else FColumns[i].Status := esUntouched; - FColumns[i].OldName := ''; - end; end; DeletedKeys.Clear; for i:=0 to FKeys.Count-1 do begin @@ -450,7 +448,7 @@ end; function TfrmTableEditor.ComposeAlterStatement: String; var Specs: TStringList; - ColSpec, OldColName, IndexSQL: String; + ColSpec, IndexSQL: String; i: Integer; Results: TMySQLQuery; Col, PreviousCol: PTableColumn; @@ -534,12 +532,9 @@ begin else ColSpec := ColSpec + ' AFTER '+Mainform.mask(PreviousCol.Name); end; - if Col.Status = esModified then begin - OldColName := Col.OldName; - if OldColName = '' then - OldColName := Col.Name; - Specs.Add('CHANGE COLUMN '+Mainform.mask(OldColName) + ' ' + ColSpec); - end else if Col.Status in [esAddedUntouched, esAddedModified] then + if Col.Status = esModified then + Specs.Add('CHANGE COLUMN '+Mainform.mask(Col.OldName) + ' ' + ColSpec) + else if Col.Status in [esAddedUntouched, esAddedModified] then Specs.Add('ADD COLUMN ' + ColSpec); end; PreviousCol := Col; @@ -548,12 +543,8 @@ begin // Deleted columns, not available as Node in above loop for i:=0 to FColumns.Count-1 do begin - if FColumns[i].Status = esDeleted then begin - OldColName := FColumns[i].OldName; - if OldColName = '' then - OldColName := FColumns[i].Name; - Specs.Add('DROP COLUMN '+Mainform.mask(OldColName)); - end; + if FColumns[i].Status = esDeleted then + Specs.Add('DROP COLUMN '+Mainform.mask(FColumns[i].OldName)); end; // Drop indexes, also changed indexes, which will be readded below @@ -819,10 +810,7 @@ begin Node := listColumns.GetFirstSelected; while Assigned(Node) do begin Col := listColumns.GetNodeData(Node); - if Col.OldName <> '' then begin - Col.Name := Col.OldName; - Col.OldName := ''; - end; + Col.Name := Col.OldName; Col.Status := esDeleted; Node := listColumns.GetNextSelected(Node); end; @@ -1124,7 +1112,6 @@ begin Exit; end; end; - Col.OldName := Col.Name; Col.Name := NewText; end; 2: begin // Data type