On Tue, Feb 09, 2010 at 01:57:40PM -0500, Chris Nehren wrote:
> Hey, all.
> 
> We've got a situation where we need to get the placeholders used for
> statements when doing profiling. I've RTFM'd and RTFS'd and not found
> any leads. What do I need to poke to get this information?

"get the placeholders"? Do you mean _include_ the current placeholder
_values_ in the profile 'Path'?

As Greg said, the placeholder values are in $h->{ParamValues}
(if your driver supports that attribute).

The magic ingredient you need for DBI::Profile is the knowledge that the
Path can contain code refs:
http://search.cpan.org/~timb/DBI-1.609/lib/DBI/Profile.pm#Code_Reference

So you might, for example, use a Path like this (untested):

    $h->{Profile}{Path} = [
        '!Statement',
        sub { my $p = shift->{ParamValues}||{}; return %$p }
    ];

Other variations on that sub might include:

    sub { my $p = shift->{ParamValues}||{}; return join ",", %$p }
    sub { my $p = shift->{ParamValues}||{}; return values %$p }
    sub { my $p = shift->{ParamValues}||{}; my @n=keys %$p; return @{$p}{sort 
@n} }
    sub { my $p = shift->{ParamValues}||{}; sort map { "$_=$p->{$_}"} keys %p }

Experiment. Let us know how it works out.

Remember that the code ref gets called for _every_ DBI method call, so
keep it fast.

Tim.

p.s. The slides for DBI::Profile in the Advanced DBI Tutorial (2004) on CPAN
are out of date 
http://cpansearch.perl.org/src/TIMB/DBI_AdvancedTalk_2004/sld022.htm
I gave a talk at the Italian Perl Workshop on DBI::Profile.
I've uploaded the screencast to http://blip.tv/file/3199117

Reply via email to