Set focus on connection root after dropping tables so there is a focused node when firing later queries. Fixes issue #2224.

This commit is contained in:
Ansgar Becker
2010-11-14 23:16:08 +00:00
parent 23da40e86e
commit e01b7035fc

View File

@ -2598,7 +2598,7 @@ end;
// Drop Table(s) // Drop Table(s)
procedure TMainForm.actDropObjectsExecute(Sender: TObject); procedure TMainForm.actDropObjectsExecute(Sender: TObject);
var var
msg, activeDB : String; msg, db: String;
InDBTree: Boolean; InDBTree: Boolean;
Act: TAction; Act: TAction;
Node: PVirtualNode; Node: PVirtualNode;
@ -2606,10 +2606,9 @@ var
DBObject: TDBObject; DBObject: TDBObject;
ObjectList: TDBObjectList; ObjectList: TDBObjectList;
Editor: TDBObjectEditor; Editor: TDBObjectEditor;
Conn: TMySQLConnection;
begin begin
// Set default database name to to ActiveDatabase. Conn := ActiveConnection;
// Can be overwritten when someone selects a table in dbtree from different database
activeDB := ActiveDatabase;
ObjectList := TDBobjectList.Create(TDBObjectDropComparer.Create, False); ObjectList := TDBobjectList.Create(TDBObjectDropComparer.Create, False);
@ -2620,13 +2619,15 @@ begin
// drop table selected in tree view. // drop table selected in tree view.
case ActiveDBObj.NodeType of case ActiveDBObj.NodeType of
lntDb: begin lntDb: begin
if MessageDlg('Drop Database "'+activeDB+'"?' + crlf + crlf + 'WARNING: You will lose all objects in database '+activeDB+'!', mtConfirmation, [mbok,mbcancel], 0) <> mrok then if MessageDlg('Drop Database "'+Conn.Database+'"?' + crlf + crlf + 'WARNING: You will lose all objects in database '+Conn.Database+'!', mtConfirmation, [mbok,mbcancel], 0) <> mrok then
Abort; Abort;
try try
SetActiveDatabase('', ActiveConnection); db := Conn.Database;
ActiveConnection.Query('DROP DATABASE ' + mask(activeDB)); Node := FindDBNode(DBtree, db);
ActiveConnection.ClearDbObjects(activeDB); SetActiveDatabase('', Conn);
RefreshTree; Conn.Query('DROP DATABASE ' + mask(db));
DBtree.DeleteNode(Node);
Conn.ClearDbObjects(db);
except except
on E:EDatabaseError do on E:EDatabaseError do
MessageDlg(E.Message, mtError, [mbOK], 0); MessageDlg(E.Message, mtError, [mbOK], 0);
@ -2654,24 +2655,27 @@ begin
// Ask user for confirmation to drop selected objects // Ask user for confirmation to drop selected objects
ObjectList.Sort; ObjectList.Sort;
msg := 'Drop ' + IntToStr(ObjectList.Count) + ' object(s) in database "'+activeDB+'"?' + CRLF + CRLF; msg := 'Drop ' + IntToStr(ObjectList.Count) + ' object(s) in database "'+Conn.Database+'"?' + CRLF + CRLF;
for DBObject in ObjectList do for DBObject in ObjectList do
msg := msg + DBObject.Name + ', '; msg := msg + DBObject.Name + ', ';
Delete(msg, Length(msg)-1, 2); Delete(msg, Length(msg)-1, 2);
if MessageDlg(msg, mtConfirmation, [mbok,mbcancel], 0) = mrOk then begin if MessageDlg(msg, mtConfirmation, [mbok,mbcancel], 0) = mrOk then begin
try try
// Disable foreign key checks to avoid SQL errors // Disable foreign key checks to avoid SQL errors
ActiveConnection.Query('/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */'); if Conn.ServerVersionInt >= 40014 then
Conn.Query('SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0');
// Compose and run DROP [TABLE|VIEW|...] queries // Compose and run DROP [TABLE|VIEW|...] queries
Editor := ActiveObjectEditor; Editor := ActiveObjectEditor;
for DBObject in ObjectList do begin for DBObject in ObjectList do begin
ActiveConnection.Query('DROP '+UpperCase(DBObject.ObjType)+' '+Mask(DBObject.Name)); Conn.Query('DROP '+UpperCase(DBObject.ObjType)+' '+Mask(DBObject.Name));
if Assigned(Editor) and Editor.Modified and Editor.DBObject.IsSameAs(DBObject) then if Assigned(Editor) and Editor.Modified and Editor.DBObject.IsSameAs(DBObject) then
Editor.Modified := False; Editor.Modified := False;
end; end;
if Conn.ServerVersionInt >= 40014 then
Conn.Query('SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS');
// Refresh ListTables + dbtree so the dropped tables are gone: // Refresh ListTables + dbtree so the dropped tables are gone:
ActiveConnection.ClearDbObjects(ActiveDatabase); Conn.ClearDbObjects(ActiveDatabase);
ActiveConnection.Query('/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */'); SetActiveDatabase(Conn.Database, Conn);
except except
on E:EDatabaseError do on E:EDatabaseError do
MessageDlg(E.Message, mtError, [mbOK], 0); MessageDlg(E.Message, mtError, [mbOK], 0);
@ -6741,7 +6745,8 @@ begin
InvalidateVT(ListCommandstats, VTREE_NOTLOADED, False); InvalidateVT(ListCommandstats, VTREE_NOTLOADED, False);
InvalidateVT(ListTables, VTREE_NOTLOADED, False); InvalidateVT(ListTables, VTREE_NOTLOADED, False);
end; end;
if (PrevDBObj.Connection <> DBObj.Connection) or (PrevDBObj.Database <> DBObj.Database) then if (DBObj.NodeType <> lntNone)
and ((PrevDBObj.Connection <> DBObj.Connection) or (PrevDBObj.Database <> DBObj.Database)) then
InvalidateVT(ListTables, VTREE_NOTLOADED, True); InvalidateVT(ListTables, VTREE_NOTLOADED, True);
// Store click history item // Store click history item