3

I have a nasty error when executing a Firedac TFDScript error trying to drop a non-existent table:

  • Delphi Berlin 10.1 Upd 2
  • Database Firebird 2.5

It give an error when calling FDScript.ExecuteAll (it passes the FDScript.ValidateAll without any problem)

The code I am executing is as follows:

FDScript: TFDScript;

{...}

begin
  FDScript.ScriptOptions.Reset;
  FDScript.SQLScripts.Clear;
  FDScript.SQLScriptFileName := '';
  FDScript.ScriptOptions.CommandSeparator := ';';
  FDScript.ScriptOptions.CommitEachNCommands := 1;
  FDScript.ScriptOptions.DropNonexistObj := True;  // seems to ignore this directive

  FDConnection.StartTransaction;
  try
    FDScript.SQLScripts.Add.SQL.Add('drop table countries;');     

    FDScript.ValidateAll; // no errors here

    ScriptStatus := GetEnumName(TypeInfo(TFDScriptStatus), Ord(FDScript.Status));
    if FDScript.Status = ssFinishSuccess then begin

      FDScript.ExecuteAll; // ERROR HERE! TABLE COUNTRIES DOES NOT EXIXTS

      if FDScript.TotalErrors = 0 then begin
        FDConnection.Commit;
      end
      else begin
        FDConnection.Rollback;
      end;
    end
    else begin
      FDConnection.Rollback;
    end;
  except
    FDConnection.Rollback;
    raise;
  end;
end;
RRUZ
  • 134,889
  • 20
  • 356
  • 483
Fabio Vitale
  • 2,257
  • 5
  • 28
  • 38
  • What exception is being raised? It looks like FireDac lets an internal exception be raised for ObjNotExists and then checks to see if it should be ignored or re-raised. Look at this code in FireDac.Comp.ScriptCommands on E: EFDDBEngineException do begin if (E.Kind = ekObjNotExists) and Engine.ScriptOptions.DropNonexistObj and ((eCmdKind = skUnknown) and (oCmd.CommandKind in [skDrop, skAlter]) or (eCmdKind in [skDrop, skAlter])) then begin – Mark Elder Feb 28 '17 at 22:39

1 Answers1

0

Implementation seems to be correct. The engine checks if a raised exception is of ekObjNotExists kind, and if so and the DropNonexistObj property is enabled and command kind is DROP or ALTER, it logs to its console. Otherwise re-raises the caught exception.

The only explanation is then, that you are seeing an exception message dialog shown by debugger. These dialogs are displayed even for handled exceptions (so long you won't add them to an ignore list or turn this feature off, which you should not do).

Victoria
  • 7,822
  • 2
  • 21
  • 44