MySQLdb Win32 binary?
Michal Wallace
sabren at manifestation.com
Fri Oct 6 18:49:59 EDT 2000
On Fri, 6 Oct 2000, Philipp von Klitzing wrote:
> Hi there,
>
> the subject pretty much says it: I am looking for a Win32 build of
> MySQLdb, preferably for Python 1.52 - is there anyone out there
> that could help me with this? Unfortunately I don't have access to
> a Windows C compiler.
http://www.faqts.com/knowledge-base/view.phtml/aid/4188/fid/395
This is a slightly dated version, and has a small bug regarding
.fetchall() with the latest mysql... It works great, given a wrapper
(below)..
Maybe we ought to ask Activestate to consider maintaining mysqldb
with their win32 tools..
Cheers,
- Michal
------------------------------------------------------------------------
www.manifestation.com www.sabren.com www.linkwatcher.com www.zike.net
------------------------------------------------------------------------
"""
this is a wrapper to bring mysqldb up to dbapi 2.0 compliance
a better idea would be to upgrade to the 0.22 of mysqldb, but I only
have 0.21 as a windows binary, and 0.22 has resisted all my attempts
to compile it. (perhaps because I'm using a new version of mysql???)
anyway, without further ado...
"""
from MySQLdb import *
import MySQLdb
def connect(*args, **kwargs):
return Connection(apply(MySQLdb.connect, args, kwargs))
class Wrapper:
def __init__(self, realDeal):
self._realDeal = realDeal
def __getattr__(self, attr):
if attr == "_realDeal":
return self.__dict__["_realDeal"]
else:
return getattr(self._realDeal, attr)
def __setattr__(self, attr, value):
if attr != "_realDeal":
setattr(self._realDeal, attr)
else:
self.__dict__["_realDeal"] = value
class Connection(Wrapper):
def cursor(self):
return DBAPI2Cursor(
MySQLdb.Connection.cursor(self._realDeal))
class DBAPI2Cursor(Wrapper):
def fetchone(self):
try:
return self._realDeal.fetchone()
except IndexError:
return None
if __name__=="__main__":
dbc = connect(host="jubie",
user="sabren",
passwd="chacha",
db="zike_test")
cur = dbc.cursor()
cur.execute("DELETE FROM test_fish")
cur.execute("SELECT * FROM test_fish")
assert cur.fetchone() == None, \
"ooops!"
More information about the Python-list
mailing list