Delphi - Business Processors - Where can we see the final resulting sql?

Where in the DA Business Processors that are auto created can we see the final result of the created Sql insert and update statements?

Or can we see this sql statement somewhere on an event?

Would like to log this result prior to the execution of the statement. Also, will this show the exact sql to be executed or is it without the parameters being processed with the passed data?

Thanks.
Bill Brittain

Hi,

you can use the TDABusinessProcessor.OnBeforeExecuteCommand event.

in case of auto created BP, you can assign this event in the DataService.OnBusinessProcessorAutoCreated event, something like

procedure TDataService.DataAbstractServiceBusinessProcessorAutoCreated(aSender: TRORemoteDataModule;
  BusinessProcessor: TDABusinessProcessor);
begin
  if BusinessProcessor.ReferencedDataset = 'MyTable' then
    BusinessProcessor.OnBeforeExecuteCommand := My_OnBeforeExecuteCommand;
end;

We assign values via parameters so you should log param values too.

Interesting, I can get the ReferenceDataSet name for my custom Liodden Sql Anywhere driver but not the FireDac driver.

But how do I get the Sql statement from the auto created process?

Hi,

use Sender.SQL in the TDABusinessProcessor.OnBeforeExecuteCommand event.

Note: Insert/Update/Delete commands are created dynamically during processing of each delta unless you assigned existing commands to BP manually or set them in Schema Modeler:

I can get it to work if I setup with a manually place Business Processor but I cannot figure out how to do it with an auto created one. Trying to get the Sql statement that was created.

Can you show me a full example of doing that?

Thanks.

Hi,

procedure TDataService.DataAbstractServiceBusinessProcessorAutoCreated(aSender: TRORemoteDataModule;
  BusinessProcessor: TDABusinessProcessor);
begin
  BusinessProcessor.OnBeforeExecuteCommand := MyBeforeExecuteCommand;
end;
  • Add MyBeforeExecuteCommand method:
    procedure DataAbstractServiceBusinessProcessorAutoCreated(aSender: TRORemoteDataModule;
      BusinessProcessor: TDABusinessProcessor);
  private
    procedure MyBeforeExecuteCommand(const Sender: IDASQLCommand); //<<<<<<<<
...

procedure TDataService.MyBeforeExecuteCommand(const Sender: IDASQLCommand);
var
  i: Integer;
  s: string;
begin
  s := Sender.SQL;
  for i := 0 to Sender.Params.Count - 1 do
    s := s + sLineBreak +
           'Param[' + i.ToString+'], ' +
           'Name = '+ Sender.Params[i].Name+ ','+
           'Value = '+ Sender.Params[i].AsString;
  ShowMessage(s);
end;
  • Build and launch server. Start server on 7099 port
  • launch SimpleDataOperations.exe. it was created at beginning
  • see


Thank you Evgeny. Worked.

So this tells me now that the Business Processor is working correctly to create the Insert and Update statements. Somewhere down the line in the custom driver is a problem where the created statement is not being used when the statement is actually run.