On Nov 1, 2005, at 12:11 PM, David Wheeler wrote:

So, what's the status on Callbacks? Are they ready to go into a release?

Ah, I see from this post:

  http://www.mail-archive.com/dbi-dev@perl.org/msg03793.html

That Steven Schubiger was going to pen some docs for Callbacks. Since that didn't happen, perhaps I should have a crack at it.

Also, the reason I'm following up on this is that I've found a perfect use for callbacks. DBD::SQLite lets you declare database functions and aggregates _in Perl_! This is a slick feature of which I plan to take full advantage. I have a quick example here:

http://www.justatheory.com/computers/databases/sqlite/ custom_perl_aggregates.html

But the downside is that any functions or aggregates exist only for the duration of the database connection. So what I need is some way to create them every time a new dbh gets created. The ideal place is inside a callback:

  my $dbh = DBI->connect_cached(
      "dbi:SQLite:dbname=$dbfile", '', '', {
          Callbacks => {
              'connect_cached.new' => sub {
                  my $dbh = shift;
                  # use $dbh->func() to add functions.
              }
          }
      }
  );


However, according to what Tim says in this message:

  http://www.mail-archive.com/dbi-dev@perl.org/msg03797.html

the callback will be called _before_ the database connection is actually made. In his original "Callback support is oin [sic]" message, he mentions this as a to-do item:

2. No support for post-call callbacks via
        $dbh->{Callbacks}->{prepare} => [ \&pre, \&post ]

So, unless there's some other way I can get a hook into things after connect() is called but before connect_cached() returns the dbh, I think I'd like to take a stab at this. Tim, if you're around (new baby arrived yet???), can you give me a pointer as to where I might start?

Thanks,

David

Reply via email to