[DB-SIG] ping method for connection objects

Michael C. Neel neel@mediapulse.com
Tue, 8 Oct 2002 17:20:01 -0400


I think the driver could handle what you outline, if the db did not have
a real ping method.  So a ping could be a "select 1" if no true ping was
available.  I even think the perl DBI docs state they work similar.

The reconnect would just save a bit of work, and re-use the same object
that might have been passed around a bit. =20

To be honest, I've only ever needed this in a webserver setup; and then
I just sub class the db myself and add these in.  I guess if I was
really into it, I'd setup the db object to reconnect if needed by
itself, hehe.

Mike

-----Original Message-----
From: M.-A. Lemburg [mailto:mal@lemburg.com]=20
Sent: Tuesday, October 08, 2002 4:46 PM
To: Michael C. Neel
Cc: db-sig@python.org
Subject: Re: [DB-SIG] ping method for connection objects


Michael C. Neel wrote:
> Just a request for the spec, is that a ping method be added to the
> connection object to test if the db handle is still valid, not unlike
> perl's DBI interface.  Ideally a reconnect method would be handy as
> well.

I'm not sure whether such a feature is available on a broad
enough basis, e.g. ODBC only recently added such a feature
to the spec and it's not available in all drivers.

Maybe we just need a portable way to test the connection,
e.g. a dummy SQL statement ?

try:
      connection.cursor().execute('select x from nonexistingtable')
except OperationalError:
      # reconnect
      pass
except ProgrammingError:
      # alive
      pass

> Otherwise, I find the spec very complete!

Same here :-)

--=20
Marc-Andre Lemburg
CEO eGenix.com Software GmbH
_______________________________________________________________________
eGenix.com -- Makers of the Python mx Extensions: mxDateTime,mxODBC,...
Python Consulting:                               http://www.egenix.com/
Python Software:                    http://www.egenix.com/files/python/