On Fri, May 08, 2009 at 09:48:42AM +0100, Tim Bunce wrote:
> 
> The callbacks can not only see the params, they can change them.
> There are examples in the 70callbacks.t file.

I suspect I'm missing something obvious.

Do you mean the section?

    my $attr;
    eval { $dbh->quote_identifier('foo','bar', $attr) };
    is $called{quote_identifier}, 1;
    ok $@, 'quote_identifier callback caused fatal error';
    is ref $attr, 'HASH', 'param modified by callback - not recommended!';


I'm calling prepare and execute in the script below.  What I'm after
is printing out both the statement AND the bind parameters passed to
execute.

When running the script below I see:

callback [FETCH]
callback [STORE]
callback [FETCH]
callback [connected]
callback [STORE]
callback [prepare]
Fetched 1


I initially didn't think I'd see methods called on statement handles,
but if I can see what's passed to execute that would be great.




#!/usr/bin/perl
use warnings;
use strict;
use DBI;
use Data::Dumper;


my %callbacks = map {
    $_ => sub {
        warn "callback [$_]\n";
        # warn Dumper \...@_;

        return;
    },
} qw/ prepare prepare_cached execute quote_identifier * /;



my $dbh = DBI->connect( 'dbi:Pg:', '', '',
    {
        RaiseError => 1,
        AutoCommit => 1,
        Callbacks => \%callbacks,
    },
);

my $sth = $dbh->prepare( 'SELECT * from foo where id = ?' );
$sth->execute( 1 );
my $rows = $sth->rows;
print "Fetched $rows\n";




-- 
Bill Moseley.
[email protected]
Sent from my iMutt

Reply via email to