February 28th, 2005, 12:04 AM
mysql auto_increase, nextNumber
I need a way to find the next number that is going to be asinged to an auto_increasing value, using MySQLdb module.
February 28th, 2005, 02:42 PM
Well here is something that works for me:
I should warn you that I'm no programmer as of yet. I just started learning this stuff about 2 weeks ago but it works for me.
db = MySQLdb.connect(host="hostname", user="webuser", passwd="pword", db="database")
cursor = db.cursor()
cursor.execute("SELECT id FROM some_table ORDER BY id DESC")
tuple = cursor.fetchall()
next_number = int(tuple) + 1
I'll learn this stuff someday.
February 28th, 2005, 11:18 PM
ya, that is basicly what I am currently doing. I have done some things into mysql to see if i could find a better method. It doesn't seem tho that there really is. If anyone knows of a faster method, please share.
February 28th, 2005, 11:50 PM
you could do your way and limit 1,1 so it will only give you one result or you can use the following sql
"SELECT MAX(id) FROM some_table"
March 1st, 2005, 04:10 AM
You may be able to use:
SELECT LAST_INSERT_ID() FROM tablename;
Then, just increment it.
btw: crossposting is bad.
March 1st, 2005, 06:21 AM
ya i know, i was looking for a way to do it in python, then i releaised it may be better done with mysql itself. I thought this thread was dead, so i posted in mysql to see if i could get better results.