mirror of
https://github.com/HeidiSQL/HeidiSQL.git
synced 2025-08-16 11:42:12 +08:00
Restrict disabling foreign keys to MySQL when dropping objects. See http://www.heidisql.com/forum.php?t=7025#p16142
This commit is contained in:
@ -3004,6 +3004,7 @@ var
|
|||||||
ObjectList: TDBObjectList;
|
ObjectList: TDBObjectList;
|
||||||
Editor: TDBObjectEditor;
|
Editor: TDBObjectEditor;
|
||||||
Conn: TDBConnection;
|
Conn: TDBConnection;
|
||||||
|
DisableForeignKeys: Boolean;
|
||||||
begin
|
begin
|
||||||
Conn := ActiveConnection;
|
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
|
if MessageDialog(f_('Drop %d object(s) in database "%s"?', [ObjectList.Count, Conn.Database]), msg, mtCriticalConfirmation, [mbok,mbcancel]) = mrOk then begin
|
||||||
try
|
try
|
||||||
// Disable foreign key checks to avoid SQL errors
|
// 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');
|
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;
|
||||||
@ -3067,7 +3069,7 @@ begin
|
|||||||
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
|
if DisableForeignKeys then
|
||||||
Conn.Query('SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS');
|
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:
|
||||||
Conn.ClearDbObjects(ActiveDatabase);
|
Conn.ClearDbObjects(ActiveDatabase);
|
||||||
|
Reference in New Issue
Block a user