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

前端 未结 8 658
梦毁少年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 09:41

    See Tracing in DBI. The following works using DBD::SQLite but produces a lot of output:

    $dbh->trace($dbh->parse_trace_flags('SQL|1|test'));
    

    Output:

    <- prepare('SELECT ... FROM ... WHERE ... = ?')= DBI::st=HASH(0x21ee924) at booklet-excel.pl line 213

    <- execute('Inhaler')= '0E0' at booklet-excel.pl line 215

    etc etc.

    You could plug your own filter in to the trace stream to only keep prepares.

提交回复
热议问题