Search code examples
delphifiredac

In Delphi, on TFDQuery is there a way to get the SQL with the parameters merged?


I want to log SQL statements in TFDQuery components, but the qry.SQL.Text property doesn't have the parameters merged. Is there a way I can get the SQL that is being sent to the server?


Solution

  • AFAIK, there is no way to get the SQL with parameters merged, because that is not how it works. The SQL content is preprocessed by FireDAC and then sent to the SQL server with parameter markers, while the parameters are sent separately. That allows to execute the same (already prepared) query with different parameters to increase performance.

    If you follow the TFDMonitor advice in the comments, you will see that: The SQL sent to the server has parameter markers and the actual parameters are sent separately.

    As the SQL in the TFDQuery may be preprocessed, the result can be retrieved with TFDQuery.Command.SQLText as long as the query is already prepared (see: FireDAC.Comp.Client.TFDCustomCommand.SQLText).