Disable foreign key checks while truncating tables. See http://www.heidisql.com/forum.php?t=17587

This commit is contained in:
Ansgar Becker
2015-01-29 19:41:53 +00:00
parent 9d3c19af49
commit daae16e583

View File

@ -3680,6 +3680,8 @@ var
TableOrView: TDBObject;
Objects: TDBObjectList;
Names: String;
DisableForeignKeys: Boolean;
Conn: TDBConnection;
begin
// Delete rows from selected tables and views
@ -3700,11 +3702,17 @@ begin
mtConfirmation, [mbOk, mbCancel]) = mrOk then begin
Screen.Cursor := crHourglass;
EnableProgress(Objects.Count);
Conn := ActiveConnection;
try
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');
for TableOrView in Objects do begin
TableOrView.Connection.Query(TableOrView.Connection.GetSQLSpecifity(spEmptyTable) + TableOrView.QuotedName);
ProgressStep;
end;
if DisableForeignKeys then
Conn.Query('SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS');
actRefresh.Execute;
except
on E:EDatabaseError do begin