Automatically refresh children of active database node after creating a new table or renaming one. Fixes issue #1248 and part 1 of issue #1352

This commit is contained in:
Ansgar Becker
2009-09-12 06:47:17 +00:00
parent 77ec7315e8
commit 2146332be6
2 changed files with 16 additions and 10 deletions

View File

@ -556,32 +556,31 @@ var
Specs: TWideStringlist;
Key: TForeignKey;
Col: TColumn;
FocusChangeEvent: procedure(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex) of object;
begin
// Create or alter table
if FAlterTableName = '' then
sql := ComposeCreateStatement
else begin
sql := ComposeAlterStatement;
// Special case for altered foreign keys: These have to be dropped in a seperate query
// otherwise the server would return error 121 "Duplicate key on write or update"
// See also http://dev.mysql.com/doc/refman/5.1/en/innodb-foreign-key-constraints.html :
// "You cannot add a foreign key and drop a foreign key in separate clauses of a single
// ALTER TABLE statement. Separate statements are required."
// Special case for altered foreign keys: These have to be dropped in a seperate query
// otherwise the server would return error 121 "Duplicate key on write or update"
// See also http://dev.mysql.com/doc/refman/5.1/en/innodb-foreign-key-constraints.html :
// "You cannot add a foreign key and drop a foreign key in separate clauses of a single
// ALTER TABLE statement. Separate statements are required."
Specs := TWideStringList.Create;
for i:=0 to ForeignKeys.Count-1 do begin
Key := ForeignKeys[i] as TForeignKey;
if Key.Modified and (not Key.Added) then
Specs.Add('DROP FOREIGN KEY '+Mainform.mask(Key.KeyName));
end;
if Specs.Count > 0 then
if Specs.Count > 0 then
Mainform.ExecUpdateQuery('ALTER TABLE '+Mainform.mask(FAlterTableName)+' '+ImplodeStr(', ', Specs));
end;
Mainform.ExecUpdateQuery(sql);
// Set table name for altering if Apply was clicked
FAlterTableName := editName.Text;
tabALTERcode.TabVisible := FAlterTableName <> '';
Mainform.SetEditorTabCaption(Self, FAlterTableName);
Mainform.tabData.TabVisible := True;
if chkCharsetConvert.Checked then begin
// Autoadjust column collations
for i:=0 to FColumns.Count-1 do begin
@ -591,7 +590,14 @@ begin
end;
end;
ResetModificationFlags;
Mainform.ResetSelectedTableStuff;
// Refresh db tree and reselect edited table node.
// Supress tab jumping, implicitely invoked by RefreshTreeDB.
FocusChangeEvent := Mainform.DBtree.OnFocusChanged;
Mainform.DBtree.OnFocusChanged := nil;
Mainform.RefreshTreeDB(Mainform.ActiveDatabase);
Mainform.DBtree.OnFocusChanged := FocusChangeEvent;
Mainform.SelectDBObject(FAlterTableName, lntTable);
end;