mirror of
https://github.com/HeidiSQL/HeidiSQL.git
synced 2026-03-13 09:24:25 +08:00
feat: recreate previous state of trigger after realizing the user edited code has errors
Refs #2348 and #1788
This commit is contained in:
@@ -226,6 +226,8 @@ end;
|
||||
|
||||
|
||||
function TfrmTriggerEditor.ApplyModifications: TModalResult;
|
||||
var
|
||||
OldCreateCode: String;
|
||||
begin
|
||||
// Edit mode means we drop the trigger and recreate it, as there is no ALTER TRIGGER.
|
||||
Result := mrOk;
|
||||
@@ -235,7 +237,9 @@ begin
|
||||
// So, we take the risk of loosing the trigger for cases in which the user has SQL errors in
|
||||
// his statement. The user must fix such errors and re-press "Save" while we have them in memory,
|
||||
// otherwise the trigger attributes are lost forever.
|
||||
OldCreateCode := '';
|
||||
if ObjectExists then try
|
||||
OldCreateCode := DBObject.CreateCode;
|
||||
DBObject.Connection.Query('DROP TRIGGER '+DBObject.Connection.QuoteIdent(DBObject.Name));
|
||||
except
|
||||
end;
|
||||
@@ -251,6 +255,8 @@ begin
|
||||
on E:EDbError do begin
|
||||
ErrorDialog(E.Message);
|
||||
Result := mrAbort;
|
||||
if not OldCreateCode.IsEmpty then
|
||||
DBObject.Connection.Query(OldCreateCode);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
Reference in New Issue
Block a user