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

前端 未结 8 852
梦毁少年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:53

    For perl neophytes, my solution, copied from not2qubit and simplified/hopefully made a bit more generic/reuseable:

    sub dump_query {
      my $tquery = shift;
      my @args = shift;
      my $j;
        foreach my $j (@args) { $tquery =~ s/\?/\'$j\'/; }
        print STDERR "$tquery\n\n";
    }
    

提交回复
热议问题