SUMMARY: [MySQLdb] Problems with unsigned int's...

Mike Andersen mike at src.no
Fri Aug 25 10:42:22 EDT 2000


Using the MySQLdb, I had problems reading the values stored as unsigned
int's in MySQL.  The solution came from Andy Dustman (the author of the
MySQLdb):

| It's arguably a bug in the module. Python integers are based on C int,
| and this is an unsigned int that's bigger than maxint. So INT UNSIGNED
| can overflow Python integers, in which case they need to be returned
| as long integers.
| 
| To get around this:
| 
| def int_or_long:(s):
|    try: return int(s)
|    except ValueError: return long(s)
| 
| type_conv[FIELD_TYPE.LONG] = int_or_long
| 
| See line 50 of MySQLdb.py. If this works acceptably, I'll put it in
| 0.3.0.


mike
-- 
To err is human, to forgive, beyond the scope of the Operating System.



More information about the Python-list mailing list