[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.

#!/usr/bin/python
try:
  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"
  exit

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:
# ./testMySQLdb_Module_Attrs.py
db.apilevel=2.0
db.threadsafety=1
db.paramstyle=format
#




Wish this helps.

regards,
Stanley Huang

Comments

Popular posts from this blog

[Level 2] Shell Interactive With Zenity Episode 5 -- list

[Level 2] iif in Python