Since you are requesting some kind of database engine, I believe that the only reliable approach is the application for your application to register SQL before executing it. There are several ways to do this, from creating child objects from existing TAdoxxxx to creating simple functions that you need to remember every time you want to check something. Regarding logging, one of the preferred methods is to use outputdebugstring to send it to the debug console. When Delphi is running, it will be displayed in the message box. There is a standalone executable DebugView that can be used on remote systems.
If you just want to access SQL during debugging (so you can test and configure an external application), and using the tAdoQuery component, you can use a debugging evaluator to save this to a file. Just set a breakpoint right before opening, then at the breakpoint, start the debug analyzer and enter the name of your query component, and then: .sql.savetofile('c:\sqlfilename.sql') and then press return, it will save all existing SQL in the specified file, It can be a lifesaver if your SQL is generated or is too large to view using the debug inspector.
source share