How can I print the SQL query executed after Perl's DBI fills in the placeholders?

前端 未结 8 674
梦毁少年i
梦毁少年i 2021-02-05 09:36

I\'m using Perl\'s DBI module. I prepare a statement using placeholders, then execute the query.

Is it possible to print out the final query that was executed without ma

8条回答
  •  情深已故
    2021-02-05 10:00

    This works for DBD::mysql with server-side prepare disabled (the default):

    $ DBI_TRACE=2 perl your-script-here
    

    It will print each statement twice, once before binding parameters and once after. The latter will be well-formed SQL that you can run yourself.

    There is also a module, DBI::Log, which only prints SQL statements (no other debug noise), and optional timing information and caller stacktraces. It's really useful.

提交回复
热议问题