On Sat, Jul 06, 2002 at 03:24:47PM +0700, Edwin Pratomo wrote:
> Tim Bunce wrote:
> >
> > Thanks.
> >
> > I'm thinking in terms of
> >
> > $h->{HandleEvent} = sub { ... }
> >
> > which would be called when the driver code calls something like
> > DBIh_EVENT(...)
>
> Will this also apply to async callback for event alerter?
Probably.
> InterBase and Firebird supports event alerter: an event can be posted
> from inside a stored proc or a trigger, and an application may choose to
> sync wait for the event, or alternatively register/install a callback.
I think some other databases support similar things.
> Current DBD::InterBase in its cvs already has had support for this
> feature, which is implemented by the means of private methods and
> separate event objects (handles).
>
> my $cb = sub {
> ++$cnt;
> print "Event caught! Count: $cnt.\n";
> };
>
> # initialize an event handle, announcing interests of the occurences of
> foo_inserted and foo_updated events
> my $evh = $dbh->func('foo_inserted', 'foo_updated', 'init_event');
That "init_event" method (and all your private methods) should be
renamed to begin with your driver private prefix ('ib_').
> # register callbacks for $evh
> $dbh->func($evh, $cb, 'register_callback');
ib_register_callback.
> init_event() only accepts max 15 event names, so if an application wants
> to watch for more than 15 events, it must initialize another event
> handle. And register_callback() should then be called again to the
> subsequent eveht handles.
>
> So the installed callback also depends on $evh, not only $dbh. In this
> case, $h->{HandleEvent} seems insufficient. Maybe I'm wrong, so I'm open
> to any suggestion.
Designing the DBI API is always a compromise - every driver specific
feature can't be accomodated directly. The goal is to let simple
things be possible (and portable) and complex things be possible
(via driver private extensions). I suspect the concept of event
handles will fall outside the DBI and that DBD::InterBase would treat
$h->{HandleEvent} as relating to a default event handle.
Tim.