Thursday, April 1, 2010

[Level 2] MySQLdb Python API -- Module Attributes

If you want to get some information about MySQLdb API,
you can use the following script to get the info.

  import MySQLdb
  db = MySQLdb
  if db:
    print "db.apilevel=" + db.apilevel
    print "db.threadsafety=" + str(db.threadsafety)
    print "db.paramstyle=" + db.paramstyle
except ImportError:
  print "import MySQLdb fail"

The attributes description:
a. apilevel => Version of API.
b. threadsafety => Level of thread safety
    0: Not threadsafe. Should not share the module at all.
    1: Minimally threadsafe. Could share module but not connection. (Default)
    2: Moderately threadsafe. Could share both module and connection but not cursors.
    3: Fully threadsafe. Could share module, connection and cursor.
c. paramstyle => Parameter style of the module
    numeric: WHERE addr=:1
    named: WHERE addr=:addr
    pyformat: WHERE addr=%(addr)s
    qmark: WHERE addr=?
    format: WHERE addr=%s (Default)
Run it:
# ./

Wish this helps.

Stanley Huang