Skip to content

Commit e7e5e11

Browse files
committed
feat: recreate previous state of trigger after realizing the user edited code has errors
Refs #2348
1 parent 3028076 commit e7e5e11

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

source/trigger_editor.pas

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,8 @@ procedure TfrmTriggerEditor.comboDefinerDropDown(Sender: TObject);
228228

229229

230230
function TfrmTriggerEditor.ApplyModifications: TModalResult;
231+
var
232+
OldCreateCode: String;
231233
begin
232234
// Edit mode means we drop the trigger and recreate it, as there is no ALTER TRIGGER.
233235
Result := mrOk;
@@ -237,7 +239,9 @@ function TfrmTriggerEditor.ApplyModifications: TModalResult;
237239
// So, we take the risk of loosing the trigger for cases in which the user has SQL errors in
238240
// his statement. The user must fix such errors and re-press "Save" while we have them in memory,
239241
// otherwise the trigger attributes are lost forever.
242+
OldCreateCode := '';
240243
if ObjectExists then try
244+
OldCreateCode := DBObject.CreateCode;
241245
DBObject.Connection.Query('DROP TRIGGER '+DBObject.Connection.QuoteIdent(DBObject.Name));
242246
except
243247
end;
@@ -253,6 +257,8 @@ function TfrmTriggerEditor.ApplyModifications: TModalResult;
253257
on E:EDbError do begin
254258
ErrorDialog(E.Message);
255259
Result := mrAbort;
260+
if not OldCreateCode.IsEmpty then
261+
DBObject.Connection.Query(OldCreateCode);
256262
end;
257263
end;
258264
end;

0 commit comments

Comments
 (0)