[DB-SIG] ping method for connection objects

M.-A. Lemburg mal@lemburg.com
Wed, 09 Oct 2002 10:33:18 +0200


Michael C. Neel wrote:
> 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.

"select 1" is not portable. It is also not clear that the driver
will actually check the network connection that way.

> The reconnect would just save a bit of work, and re-use the same object
> that might have been passed around a bit.  
> 
> 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.

Same here. The typical setup to implement reconnects and keep-alives
is a database connection pooling mechanism which is usually built
on top of the low-level drivers as abstraction layer.

If you'd like a .ping() method on connections, I could add it
as standard extension to the spec, but I doubt that it will get
implemented by many interface authors.

A .reconnect() method would not be in line with the spec (once
you close a connection it becomes useless). But that's easy to
handle by a connect wrapper function, if you need it.

Please remember that the DB API focuses on the low-level
aspects of talking to databases, not the more involved issues
like connection pooling, automatic reconnect, schema analysis
or even object-relational mappings. That's left for layers on top
of the DB API to implement.

Thanks,
-- 
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/