#199 problems with MySQL SETs

MySQLdb-1.2
closed
MySQLdb (285)
7
2012-09-19
2006-08-01
No

mysql-python 1.2.1p2 has a bug with MySQL sets. as long
as a SET has only one value, everything works as
expected, but when you define more values, the bug occurs:

import MySQLdb
db = MySQLdb.connect(user="user",passwd="*",db=
"db")
cursor = db.cursor()
cursor.execute("SELECT * FROM tbl_set WHERE 1")
2L
cursor.execute("UPDATE tbl_set SET test_sets =
'0,1'")
2L
cursor.execute("SELECT * FROM tbl_set WHERE 1")
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)

this bug occurs with mysql-python 1.2.1p2, but not with
mysql-python 1.2.1c1. in other words, it has been
introduced with the new upstream release 1.2.1p2.

i attached a patch which fixes half of the bug. i doubt
that it really fixes the whole mess with MySQL SETs.

The patch was prepared by Simeon Anastasov
simeon@know-it.net. Maybe you can mention him in the
changelog.

greetings
jonas

Discussion

  • Jonas Meurer

    Jonas Meurer - 2006-08-01

    patch to fix a bug with MySQL SETs

     
  • Andy Dustman

    Andy Dustman - 2006-08-01

    Logged In: YES
    user_id=71372

    But the patched code doesn't return a Set.

     
  • Andy Dustman

    Andy Dustman - 2006-08-26

    Logged In: YES
    user_id=71372

    I can't duplicate this problem.

     
  • Jonas Meurer

    Jonas Meurer - 2006-09-04

    Logged In: YES
    user_id=266781

    see the attachment for an example script to reproduce the
    bug. for me it still breaks.

     
  • Jonas Meurer

    Jonas Meurer - 2006-09-04

    python script to reproduce bug

     
  • Anonymous - 2006-09-04

    Logged In: YES
    user_id=1583135

    I have the same problem.
    It come from the apply(str, tuple(values)) lines, because
    the number of arguments is the length of the tuple. If you
    have more than one value in the set field, you're done.

    I changed it like this :

    def Str2Set(s):
    values = s.split(',')
    return Set(values)

    However I'm wondering if it would not be better to return an
    ImmutableSet.

     
  • Boris Dušek

    Boris Dušek - 2007-08-14

    Logged In: YES
    user_id=1241214
    Originator: NO

    I am hitting the same bug with 1.2.1-p2-4-ubuntu4. I have table with a column of type set and multiple elements allowed to be member of the set.

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks