Yearly Archives: 2006

MySQLdb 1.2.0 with Mysql 5.0.18 and Python 2.4

I was trying to get Python 2.4 working with MySQL 5.0 and thought it would be pretty simple….Oh No. I thought I’d run a quick test last night while I checked my mail before bed….2 1/2 hours later still no joy. I downloaded the MySQLdb win32 exe from MySQLdb’s SourceForge page and ran it. I then tried to import MySQLdb which resulted in an import error stating that _mysql and MySQLdb were different versions. The funny thing was that when I imported _mysql which is also in the package it worked fine

[code lang=”python”]
import _mysql
db=_mysql.connect(host=”localhost”,user=”root”,passwd=”****”,db=”test”)
db.query(“””SELECT VERSION()”””)
r=db.store_result()
r.fetch_row()
[/code]

I then downloaded the most recent source release and tried to build it (with some help) but to no avail… I kept getting link errors. I then had a look at the MySQLdb __init__.py file whilch gets called on all MySQLdb imports. I commented out the following
[code lang=”python”]
v = getattr(_mysql, ‘version_info’, None)
if version_info != v:
raise ImportError, “this is MySQLdb version %s, but _mysql is version %s” %\
(version_info, v)
del v
[/code]

to read

[code lang=”python”]
#v = getattr(_mysql, ‘version_info’, None)
#if version_info != v:
# raise ImportError, “this is MySQLdb version %s, but _mysql is version %s” %\
# (version_info, v)
#del v
[/code]

This stops the version check and importing MySQLdb works fine. I’m sure it’s not the right thing to do but it works and I haven’t had any problems yet.. Hope it helps somebody out there 🙂

[code lang=”python”]
import MySQLdb
conn = MySQLdb.connect (host=”localhost”,user=”root”,passwd=”****”,db=”test”)
cursor = conn.cursor ()
cursor.execute (“SELECT VERSION()”)
row = cursor.fetchone ()
print “server version:”, row[0]
cursor.close ()
conn.close ()
[/code]

Multiline you regex bastard

“I said multiline you F*^k” I shouted repeatedly as my c# kept failing to match my regex. I did have
[code lang=”cpp”]
(<span>)(.*?)(</span>)
[/code]

in multiline mode but I also needed ^$

[code lang=”cpp”]
(<span>)([^$.]*?)(</span>)
[/code]

At last

Update… no it wasnt.

What I needed was singleLine option instead of multiline. Where is the logic???

[code lang=”cpp”]
(<span>)(.*?)(</span>)
[/code]

with the /s or System.Text.RegularExpressions.RegexOptions.Singleline incase you have the same problem as me 🙂