On Mar 29, 2005, at 2:39 AM, Tim Bunce wrote:

  $dbh->prepare($sql, { Callbacks => { prepare => sub { ... } });

...well, I guess it'd be pretty dumb to do that.

Not if you remember that the (or at least _a_ plan) plan is to rework $dbh->prepare so it looks like this:

        sub prepare {
            my ($dbh, $sql, $attr) = @_;
             my $sth = $dbh->new_child($attr);
             $sth->prepare($sql);
             return $sth;
        }

But I suspect that's not going to happen for perl 5.

Fair enough.

Callbacks should only apply to the database handle, I think.

I don't see any reason to limit them in that way. They already work for all methods on all handles. Note that sth callbacks, for example, give you a relatively clean way to set the UTF8 flag on fetched data.

Oh, so you remember my winging about that last year, eh? I'll definitely be taking advantage of that functionality. Is there a way to set it on an entire row at once, or would it have to be done for each column in each row?


But I mispoke above. What I meant to say is that I can't see that they should ever be applied to the driver handle. One doesn't really use the driver handle or call methods on it.

Wouldn't it just be undef?

As an rvalue yes, but something like $_[2]=... wouldn't work.

Oh, right, becuase there's no container (lvalue?) in which to store a value (rvalue?). Got it.



3. The method name isn't available via a localized $_

Yeah, that'd be neat.

Done.

Cool!

I gotcha. Seems like you're talking about syntactic sugar for the most
part, though, eh?

Strong sugar I guess, plus the benefits of encapsulation. But unless someone contributes it I'm unlikely to anytime soon.

Understood.

That seems reasonable to me. Since the drh isn't really available in
user space, it doesn't matter so much to me.

$drh = DBI->install_driver('Pg'); $drh->{Callbacks} = ...

but that's discouraged :)

Huh. What other attributes are settable on the drh (but discouraged)? It doesn't make a lot of sense to me to do that...


True. I can definitely see a place for global callbacks drh, dbh,
and sth callbacks though. It's up to the callbacks to be 'well behaved'.
Umm, perhaps:


    DBI->callback_add('dr', connect => sub { ... });
    DBI->callback_add('db', prepare => sub { ... });

Would only apply to future handles though.

Or perhaps

  $dbh->add_callback(sub { ... });
  $sth->add_callback(sub { ... });

?

I've left in the "connect_cached.reused" special case but removed the
"connect" one as it wasn't 'special' enough and there's no clear need.
That'll do for now.

Well, and since that's the one I really need, it makes me happy. :-)

Regards,

David



Reply via email to