Obscure MySQLdb question - duplicating a database handle

John Bokma john at castleamber.com
Fri Sep 3 00:35:07 CEST 2010

John Nagle <nagle at animats.com> writes:

>   I have a system which does error logging to its database:
> 	db = MySQLdb.connect(...) # get database connection
> 	...
> 	errorlog(db, "Message")
> The problem is that I want errorlog to commit its message to
> the table used for error logging, but don't want to commit
> whatever the caller was doing - that may well revert.
> MySQL doesn't support nested transactions, so that won't help.
> At the many points errorlog is called, only the database
> handle is available, not the params used for "connect".
> Is there something like UNIX "dup" for database connections
> in MySQLdb, or can I get the connection parameters (username,
> password, database, etc.) from the "db" object?

Maybe I am not clear anymore (long day), but why not make 2 db
connections? It might even be better since you can give each one its own
user and hence, privileges.

John Bokma                                                               j3b

Blog: http://johnbokma.com/    Facebook: http://www.facebook.com/j.j.j.bokma
    Freelance Perl & Python Development: http://castleamber.com/

More information about the Python-list mailing list