Ja, es scheint
dieser Bug zu sein. Mit MySQLdb 1.2.2 klappts.
Ein Beispiel um das Problem zu illustrieren:
Code: Alles auswählen
>>> import MySQLdb
>>> conn = MySQLdb.connect(host=dbhost,user=dbuser,passwd=dbpass,db=dbname)
>>> cursor = conn.cursor()
>>> query = "CREATE TABLE `table_1` (`id` int(16) NOT NULL DEFAULT '0',`set_field` set('x','y','z') COLLATE utf8_unicode_ci NOT NULL DEFAULT '')"
>>> cursor.execute(query)
0L
>>> query = "INSERT INTO table_1 (set_field) VALUES('x')"
>>> cursor.execute(query)
1L
>>> query = "SELECT * FROM table_1"
>>> cursor.execute(query)
1L
>>> row = cursor.fetchall()
>>> print row
((0L, 'x'),)
>>> query="INSERT INTO table_1 (set_field) VALUES('x,y')"
>>> cursor.execute(query)
1L
>>> query = "SELECT * FROM table_1"
>>> cursor.execute(query)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/lib/python2.4/site-packages/MySQLdb/cursors.py", line 158, in execute
self.errorhandler(self, TypeError, m)
File "/usr/lib/python2.4/site-packages/MySQLdb/connections.py", line 35, in defaulterrorhandler
raise errorclass, errorvalue
TypeError: str() takes at most 1 argument (2 given)
Mit MySQLdb 1.2.2 siehts so aus:
Code: Alles auswählen
>>> import MySQLdb
>>> conn = MySQLdb.connect(host=dbhost,user=dbuser,passwd=dbpass,db=dbname)
>>> cursor = conn.cursor()
>>> query = "CREATE TABLE `table_1` (`id` int(16) NOT NULL DEFAULT '0',`set_field` set('x','y','z') COLLATE utf8_unicode_ci NOT NULL DEFAULT '')"
>>> cursor.execute(query)
0L
>>> query = "INSERT INTO table_1 (set_field) VALUES('x')"
>>> cursor.execute(query)
1L
>>> query = "SELECT * FROM table_1"
>>> cursor.execute(query)
1L
>>> row = cursor.fetchall()
>>> print row
((0L, 'x'),)
>>> query="INSERT INTO table_1 (set_field) VALUES('x,y')"
>>> cursor.execute(query)
1L
>>> query = "SELECT * FROM table_1"
>>> cursor.execute(query)
2L
>>> row = cursor.fetchall()
>>> print row
((0L, 'x,y'), (0L, 'x'))