Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

DBI 1.39

by gmax (Abbot)
on Nov 30, 2003 at 20:20 UTC ( #311088=perlnews: print w/replies, xml ) Need Help??

DBI 1.39 was released a few days ago.

Although it is mostly a bug fix version, there are three things that I would like to point out:

  1. The documentation for "InactiveDestroy" was updated, making clear what this method does.
    InactiveDestroy is a handler attribute that instructs the DBI not to call the database engine methods related to DESTROY. It is especially useful in a forked process.
    The example below shows what the docs mean. A child process inherits a database handler from its parent. The handler goes out of scope in the child process, and if we don't set InactiveDestroy (line 23), we get an error, because the database handler's DESTROY method will implicitly call disconnect().
    Notice that with some database engines, such as Oracle, this example won't work, because they don't allow passing of handlers across processes.

  2. Starting from version 1.38, as promised since February 2003, the minimum requirement for DBI is Perl 5.6.0.
    If you still are using an older version of Perl, it may be time to upgrade.

  3. <plug> Both the changelog and the docs point to an article, which is nothing more than a bit polished DBI Recipes.
    In a private message, Tim Bunce promised that the next version of Programming the Perl DBI will be very much cookbook oriented. </plug>
#!/usr/bin/perl -w use DBI; use strict; my $dbh = DBI->connect("DBI:mysql:test", "user", "pwd", { RaiseError => 1 }) or die "can't connect\n"; my $query = qq{select user(), NOW()}; my $sth = $dbh->prepare($query); my $pid ; FORK: { if ($pid = fork) { print "I am the parent (PID: $$) and $pid is my child \n"; print_result($sth); } elsif (defined $pid) { print "I am the child ($$)\n"; $dbh->{InactiveDestroy} = 1; # line 23 print_result($sth); } else { die "Can't fork: $!\n"; } } sub print_result { my $st = shift; return unless $st; print "process id: $$\n"; $st->execute() or die "can't execute (PID $$), ($DBI::errstr)\n"; while (my $row = $st->fetchrow_arrayref()) { print ">> @$row\n"; } } __END__ I am the parent (PID: 2812) and 2813 is my child I am the child (2813) process id: 2813 >> gmax@localhost 2003-11-30 18:06:20 process id: 2812 >> gmax@localhost 2003-11-30 18:06:20
 _  _ _  _  
(_|| | |(_|><

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlnews [id://311088]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (2)
As of 2022-12-03 22:28 GMT
Find Nodes?
    Voting Booth?

    No recent polls found