in reply to Debugging DBI placeholders

A crude approach:
sub _debug_query { my ($sql, @values) = @_; # Format query $sql =~ s/(FROM|(LEFT )?JOIN|WHERE|AND|GROUP|ORDER|LIMIT)/\n$1/g; $sql =~ s/(SELECT|ROWS)/$1\n/g; $sql =~ s/(\w{4,},)/$1\n/g; # Replace values @values = map { $_ =~ m/^\d+$/ ? $_ : "'$_'" } @values; $sql =~ s/\?/shift @values/e while (@values); warn "$sql\n"; }

Replies are listed 'Best First'.
Re^2: Debugging DBI placeholders
by davies (Monsignor) on Feb 06, 2011 at 10:38 UTC

    Thanks for the suggestion, but I don't see it helping me. Trace revealed my problem because it included output from the connection command, revealing where my immediate problem was. While your code would be better for some things (trace gives the prepare and execute information on two lines while I would really prefer a single combined exposition), I can't see how it would handle the insert query I included in my OP. I'm not good enough at Perl or SQL to build a full SQL parser that would cover all queries without being another possible point of failure that would have to be investigated when next I foul up.

    Regards,

    John Davies

    Update, in case anyone reads this while in search of a similar solution. Increasing the trace level DOES produce the full query, but it also makes the trace information more verbose.