You're using the result of curs.execute() to get the row count; this is not portable. Use curs.rowcount instead. This will still return a long because MySQL returns a 64-bit unsigned value for the row count and this won't fit in Python's 32-bit signed int (typically). Also read PEP-249.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks will look at it. I've figure out other ways to accomplish what I wanted. I think I had sunstroke and lacked sleep when I posted the other day as I'd recalc'd in my head and my problem wasn't correct.
I'd like to understand why the conve=my_conv isn't working though. Is that as you stated due to MySQL being 64bit unsigned and Python 32bit signed?
Thanks.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi, I am running Python 2.6 and MySQL 5.0.67 and MySQL-Python 1.2.2.
My problem is this:
I have a db with a Primary Key type INTEGER that is AUTO-INCREMENTING.
When I connect to the DB via Python it is like so:
I usually load the connection in via the program I'm writing and then use the IDLE Shell hence the >>> below denoting where I use the shell:
conn = MySQLdb.connect(db="dbase", user="root")
curs = conn.cursor()
>>>test_pt = curs.execute('SELECT * FROM tablename')
3L
>>> type(test_pt)
<type 'long'>
I have also changed my connection which is listed above to something like this:
from MySQLdb.constants import FIELD_TYPE
my_conv = { FIELD_TYPE.LONG : int }
conn = MySQLdb.connect(db='dbase', user='root', conv=my_conv)
curs = conn.cursor()........
....and get the same thing with a long integer.
Any ideas on how I can get the database or MySQLdb to give me an Integer directly rather than having to always convert from LONG integers to Integers?
Hope I provided enough info and was clear enough.
You're using the result of curs.execute() to get the row count; this is not portable. Use curs.rowcount instead. This will still return a long because MySQL returns a 64-bit unsigned value for the row count and this won't fit in Python's 32-bit signed int (typically). Also read PEP-249.
Thanks will look at it. I've figure out other ways to accomplish what I wanted. I think I had sunstroke and lacked sleep when I posted the other day as I'd recalc'd in my head and my problem wasn't correct.
I'd like to understand why the conve=my_conv isn't working though. Is that as you stated due to MySQL being 64bit unsigned and Python 32bit signed?
Thanks.
conv is only used on the result set itseld; no amount of tinkering on it will change the type in .rowcount