MySQLdb is a Python Database API Specification 2.0 database module, so you should be familiar with the spec. Deviations from the spec are documented in the MySQLdb documentation.
Get a clue. Clues have been provided in the examples
directory
of the MySQLdb distribution.
Okay, it goes something like this:
import MySQLdb db = MySQLdb.connect(db='mydb',user='myuser',passwd='mypasswd') c = db.cursor() c.execute(myquery) results = c.fetchall()
True enough. MySQLdb fakes it, though, because the spec requires it.
MySQL now supports transactions using BDB tables. If your server doesn't support them, rollbacks will always fail, as they should, because it can't do what you asked. Even if your server does support them, rollbacks will fail if you modified any non-BDB tables.
OTOH, cursor.commit()
, which attempts to commit the transaction
to the database, does exist and always succeeds, because MySQL
essentially is always in auto-commit mode.
Short answer: Don't, if you can avoid it. Your program will not be portable to other databases.
Long answer: MySQLdb exports all symbols from _mysql. There are only
a couple MySQL functions available this way, though. The Connection object
does wrap nearly all of the various MySQL calls that use a MYSQL
argument (the connection handle in the C API). So let's say you want to
use mysql_select_db(newdb)
. In MySQLdb, that's
db.select_db(newdb)
where db
is your Connection object.
Well, it may
be appropriate in some cirumstances.
ZMySQLDA does this, because MySQLdb does a lot of type conversion that
isn't necessary for Zope's purposes.