Perrin Harkins wrote:
> 
> On Thu, 9 Nov 2000, Tim Sweetman wrote:
> > Apache::DBI is, as far as I know, dangerous, and people rarely seem to
> > warn of this.
> 
> It's no more dangerous than any other scheme for persistent connections,
> like JDBC pooling, etc.
> 
> > It's dangerous because:
> > (a) Although it rolls back any transactions automatically, it may not
> > deal with other persistant
> >     state on the handle. (Does it clear MySQL table locks, for
> > instance?). Other settings, such
> >     as the lock timeout (SQL: "SET LOCK MODE TO WAIT nnn") or isolation
> > levels, will also persist.
 
> Would you be interested in adding support for resetting some of these to
> Apache::DBI?  It's pretty easy to do, using PerlCleanupHandler like the
> auto-rollback does.  It would be database-specific though, so you'd have
> to find a way for people to explicitly request cleanups.

I suspect automating via DBI would be a major pain, because you'd have
to be able to identify the "dangerous" changes in state. Probably
requiring SQL to be parsed. :(

In principle, you could probably have a ->do_not_reuse method which
could be called before someone does something dangerous. As long as they
remember.

> I used to do something like this to call finish() on all of my cached
> statement handles, back when prepare_cached() used to die on unfinished
> handles.  (Now it just warns.)
> 
> > (b) Presumably, what were previously separate transactions on the same
> > database on different handles
> >     can become entangled:
> >
> >     TX1: BEGIN WORK
> >     TX2: BEGIN WORK
> >     TX1: INSERT A
> >     TX2: COMMIT
> >     TX1: INSERT B
> >
> > ... this would probably cause either fatal errors, or very strange
> > things to happen.
> 
> Wouldn't this be the same with Apache::DBI or without it?  Or are you
> saying that this would have been done with two separate database
> connections before Apache::DBI came into the mix?  You can still get
> multiple connections through Apache::DBI if you really want to.  Just vary
> anything at all in the connect string ({MyBogusParam => 1}) and you'll get
> a different handle.

I believe without Apache::DBI there'd be two handles. This could be
useful for some purposes... though is, in itself, dangerous if TX1 and
TX2 touch the same tables because you can get into a deadlock that your
database won't know about.

> So you would check handles in and out?  I suppose that would work, but it
> sounds like a lot of trouble to handle a very unusual case to me.

Could be. I _have_ seen such cases. I don't know how rare they are.
Checking handles in & out is a mixed blessing (since it slows you down
if you have lots of processes grabbing handles in autocommit mode &
performing single statements, in which case sharing handles is
harmless).

Cheers

--
Tim Sweetman
A L Digital
"Any technology distinguishable from magic is insufficiently advanced"

Reply via email to