From 2a4a23a19b21228038ec6aba1897df73b4a618ac Mon Sep 17 00:00:00 2001 From: Ansgar Becker Date: Sun, 17 Aug 2014 10:00:46 +0000 Subject: [PATCH] Restrict disabling foreign keys to MySQL when dropping objects. See http://www.heidisql.com/forum.php?t=7025#p16142 --- source/main.pas | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/source/main.pas b/source/main.pas index 42bbd732..4081d515 100644 --- a/source/main.pas +++ b/source/main.pas @@ -3004,6 +3004,7 @@ var ObjectList: TDBObjectList; Editor: TDBObjectEditor; Conn: TDBConnection; + DisableForeignKeys: Boolean; begin Conn := ActiveConnection; @@ -3058,7 +3059,8 @@ begin if MessageDialog(f_('Drop %d object(s) in database "%s"?', [ObjectList.Count, Conn.Database]), msg, mtCriticalConfirmation, [mbok,mbcancel]) = mrOk then begin try // Disable foreign key checks to avoid SQL errors - if Conn.ServerVersionInt >= 40014 then + DisableForeignKeys := (Conn.Parameters.NetTypeGroup = ngMySQL) and (Conn.ServerVersionInt >= 40014); + if DisableForeignKeys then Conn.Query('SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0'); // Compose and run DROP [TABLE|VIEW|...] queries Editor := ActiveObjectEditor; @@ -3067,7 +3069,7 @@ begin if Assigned(Editor) and Editor.Modified and Editor.DBObject.IsSameAs(DBObject) then Editor.Modified := False; end; - if Conn.ServerVersionInt >= 40014 then + if DisableForeignKeys then Conn.Query('SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS'); // Refresh ListTables + dbtree so the dropped tables are gone: Conn.ClearDbObjects(ActiveDatabase);