Obscure MySQLdb question - duplicating a database handle

J

John Nagle

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?

John Nagle
 
J

John Bokma

John Nagle said:
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.
 
L

Lawrence D'Oliveiro

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.

Any particular reason you’re using a database table for logging? It’s
usually easier to write to text files for this purpose.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,000
Messages
2,570,248
Members
46,844
Latest member
JudyGvh32

Latest Threads

Top