FAQ
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

Search Discussions

  • John Bokma at Sep 2, 2010 at 10:35 pm

    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/
  • Lawrence D'Oliveiro at Sep 3, 2010 at 6:39 am

    In message <4c801218$0$1622$742ec2ed at news.sonic.net>, John Nagle wrote:

    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.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedSep 2, '10 at 9:07p
activeSep 3, '10 at 6:39a
posts3
users3
websitepython.org

People

Translate

site design / logo © 2023 Grokbase