[DB-SIG] ping method for connection objects
Tue, 8 Oct 2002 13:57:40 -0700
On Tuesday, Oct 8, 2002, at 13:45 US/Pacific, M.-A. Lemburg wrote:
> 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
> 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 ?
> connection.cursor().execute('select x from nonexistingtable')
> except OperationalError:
> # reconnect
> except ProgrammingError:
> # alive
>> Otherwise, I find the spec very complete!
> Same here :-)
Well, isn't the the entire purpose of the DBI?
Ie, should we not create a method that either uses the database's
particular 'are you there', method, or emulates it using something like
the above construct. ??
in the specification:
connection.ping() will test the database connection and return an
exception if the connection is broken
in an implementation who's backend database has a ping method:
def ping ( self ):
if not self._db.ping ()
in an implementation who's backend database does not have a ping method:
def ping ( self ):
connection.cursor().execute('select x from nonexistingtable')
Or something like this.
ie, the whole idea of a DBABI is to remove the reliance on the
particular implementation for the DB. If a particular method starts to
become widely available over a set of databases, this method should be
added to the next rev of the API, and API writers instructed to call
the method, or emulate it. To help the API writers, it would be easy
enough to write a 'base class' that the API can inherit from to supply
common emulations for these special methods, so all the API writer
needs to do is replace the method if a more-efficient method is
available for that particular DB, or if the particular emulation
doesn't work for that DB.
This is the same argument for ensuring that python operators work the
same way over all implementations, rather than saying "the XYZ
operator's behavior is dependant on the underlying C module".
("`-/")_.-'"``-._ Ch'marr, a.k.a.
. . `; -._ )-;-,_`) Chris Cogdon <email@example.com>
(v_,)' _ )`-.\ ``-'
_.- _..-_/ / ((.' FC1.3:
((,.-' ((,/ fL RLCT acl+++d++e+f+++h++i++++jp-sm++