Re: connecting()?

2010-04-16 Thread Tim Bunce
On Thu, Apr 15, 2010 at 10:07:14AM -0700, David E. Wheeler wrote:
 On Apr 15, 2010, at 5:17 AM, Tim Bunce wrote:
 
 $drh = DBI-install_driver($driver);
 $dbh = $drh-connect(...);
  
  Assuming we added a $dbh-connecting() method, how would it be called,
  and how would the callback have been enabled prior to calling it?
 
 In connect(), before $connect_meth, just as connected() is called in that 
 method after $connect_meth.
 
   $dbh-connected(@orig_args);
   unless ($dbh = $drh-$connect_meth($dsn, $user, $pass, $attr)) {

$dbh is undef before the $drh-$connect_meth call.

 It's not my needs. Someone is creating a CPAN module I think. His
 needs were met by connected(), but I think that connecting() would be
 useful as well.

Perhaps but it sure seems like a low priority.

  If we did that (and handled backwards compatibility somewhow)
  then presumably new_child() could apply the Callbacks attribute
  which would then fire on the subsequent $dbh-connect call.
 
 That would be cool. I, alas, have a very short supply of tuits these days.

Ditto.

Tim.


Re: connecting()?

2010-04-16 Thread David E. Wheeler
On Apr 16, 2010, at 3:13 AM, Tim Bunce wrote:

 In connect(), before $connect_meth, just as connected() is called in that 
 method after $connect_meth.
 
  $dbh-connected(@orig_args);
  unless ($dbh = $drh-$connect_meth($dsn, $user, $pass, $attr)) {
 
 $dbh is undef before the $drh-$connect_meth call.

Oh. Well that'd have to change.

 It's not my needs. Someone is creating a CPAN module I think. His
 needs were met by connected(), but I think that connecting() would be
 useful as well.
 
 Perhaps but it sure seems like a low priority.

I don't the tuits to do it, I admit.

 That would be cool. I, alas, have a very short supply of tuits these days.
 
 Ditto.

Is that what's holding back 1.610?

Best,

David




Re: connecting()?

2010-04-16 Thread H.Merijn Brand
On Fri, 16 Apr 2010 12:41:32 -0700, David E. Wheeler
da...@kineticode.com wrote:

 On Apr 16, 2010, at 3:13 AM, Tim Bunce wrote:
 
  In connect(), before $connect_meth, just as connected() is called in that 
  method after $connect_meth.
  
 $dbh-connected(@orig_args);
 unless ($dbh = $drh-$connect_meth($dsn, $user, $pass, $attr)) {
  
  $dbh is undef before the $drh-$connect_meth call.
 
 Oh. Well that'd have to change.
 
  It's not my needs. Someone is creating a CPAN module I think. His
  needs were met by connected(), but I think that connecting() would be
  useful as well.
  
  Perhaps but it sure seems like a low priority.
 
 I don't the tuits to do it, I admit.
 
  That would be cool. I, alas, have a very short supply of tuits these days.
  
  Ditto.
 
 Is that what's holding back 1.610?

There will be no 1.610

$ perl -MV=DBI
DBI
/pro/lib/perl5/site_perl/5.12.0/i686-linux-64int-ld/DBI.pm: 1.611


-- 
H.Merijn Brand  http://tux.nl  Perl Monger  http://amsterdam.pm.org/
using  porting perl 5.6.2, 5.8.x, 5.10.x, 5.11.x on HP-UX 10.20, 11.00,
11.11, 11.23, and 11.31, OpenSuSE 10.3, 11.0, and 11.1, AIX 5.2 and 5.3.
http://mirrors.develooper.com/hpux/   http://www.test-smoke.org/
http://qa.perl.org  http://www.goldmark.org/jeff/stupid-disclaimers/


Re: connecting()?

2010-04-15 Thread Tim Bunce
On Wed, Mar 31, 2010 at 10:14:04AM -0700, David E. Wheeler wrote:
 Fellow DBIers,
 
 I was just discussing writing a callback on connect() to change
 authentication (my correspondent wants to use realm files). But then I
 discovered to my disappointment that there is no support for callbacks
 on connect(). This makes sense, frankly, since the method is called
 before the callbacks are applied, and callbacks execute before the
 method, not afterward (at least for now).

Yeap.

 But I've found great use by adding callbacks on connected(), so that
 they execute just after a connection. So I was wondering how folks
 felt about the idea of adding a connecting() method that executes just
 before the DBI tries to connect to the database? I think this would be
 a nice complement to connecting(), and instantly make a simple
 interface for adding a pre-connection callback, too.

DBI-connect effectively does:

$drh = DBI-install_driver($driver);
$dbh = $drh-connect(...);

Assuming we added a $dbh-connecting() method, how would it be called,
and how would the callback have been enabled prior to calling it?

Why not register the callback on the driver:

DBI-install_driver('Pg')-{Callbacks}{connect} = ...;

That'll affect all subsequent connects using that driver and won't work
with proxy drivers like Gofer, which is why DBI docs discourage messing
with driver handles, but it may fit your needs.

Tim.

p.s. On a slight tangent: most drivers implement $dbh-connect with code like:

my $this = DBI::_new_dbh($drh, ...);

It's long bugged me that this isn't a method call.
In http://cpansearch.perl.org/src/TIMB/DBI-1.609/TODO_2005.txt
(which is old but still has useful information) I suggested:

Rework handle creation to use methods:
Maybe $h-new_child(\%handle_attr)
dr::connect =
$dbh = $drh-new_child(\%attr);
$dbh-connect(...)  - calls $dbh-reset()
   db::prepare =
sub ...::db::prepare {
my ($dbh, $sql, $attr) = @_;
$sth = $dbh-new_child($attr)
my @statements = $dbh-preparse($sql);
$sth-{PendingStatements} = \...@statements if @statements  1;
$sth-prepare( shift @statements ) or return;
return $sth;
}

If we did that (and handled backwards compatibility somewhow)
then presumably new_child() could apply the Callbacks attribute
which would then fire on the subsequent $dbh-connect call.


Re: connecting()?

2010-04-15 Thread David E. Wheeler
On Apr 15, 2010, at 5:17 AM, Tim Bunce wrote:

$drh = DBI-install_driver($driver);
$dbh = $drh-connect(...);
 
 Assuming we added a $dbh-connecting() method, how would it be called,
 and how would the callback have been enabled prior to calling it?

In connect(), before $connect_meth, just as connected() is called in that 
method after $connect_meth.

$dbh-connected(@orig_args);
unless ($dbh = $drh-$connect_meth($dsn, $user, $pass, $attr)) {

 Why not register the callback on the driver:
 
DBI-install_driver('Pg')-{Callbacks}{connect} = ...;
 
 That'll affect all subsequent connects using that driver and won't work
 with proxy drivers like Gofer, which is why DBI docs discourage messing
 with driver handles, but it may fit your needs.

It's not my needs. Someone is creating a CPAN module I think. His needs were 
met by connected(), but I think that connecting() would be useful as well.

 If we did that (and handled backwards compatibility somewhow)
 then presumably new_child() could apply the Callbacks attribute
 which would then fire on the subsequent $dbh-connect call.

That would be cool. I, alas, have a very short supply of tuits these days.

Best,

David



Re: connecting()?

2010-03-31 Thread H.Merijn Brand
On Wed, 31 Mar 2010 10:14:04 -0700, David E. Wheeler
da...@kineticode.com wrote:

 Fellow DBIers,
 
 I was just discussing writing a callback on connect () to change
 authentication (my correspondent wants to use realm files). But then I
 discovered to my disappointment that there is no support for callbacks
 on connect (). This makes sense, frankly, since the method is called
 before the callbacks are applied, and callbacks execute before the
 method, not afterward (at least for now).
 
 But I've found great use by adding callbacks on connected (), so that
 they execute just after a connection. So I was wondering how folks
 felt about the idea of adding a connecting () method that executes just
 before the DBI tries to connect to the database? I think this would be
 a nice complement to connecting (), and instantly make a simple
 interface for adding a pre-connection callback, too.
 
 Thoughts?

All in favour, if not only to be able to use $ENV{DBD_VERBOSE} and
$ENV{DBI_VERBOSE} to set verbosity on connection before it even starts!

-- 
H.Merijn Brand  http://tux.nl  Perl Monger  http://amsterdam.pm.org/
using  porting perl 5.6.2, 5.8.x, 5.10.x, 5.11.x on HP-UX 10.20, 11.00,
11.11, 11.23, and 11.31, OpenSuSE 10.3, 11.0, and 11.1, AIX 5.2 and 5.3.
http://mirrors.develooper.com/hpux/   http://www.test-smoke.org/
http://qa.perl.org  http://www.goldmark.org/jeff/stupid-disclaimers/