February 28th, 2005, 01: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, 03: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.
March 1st, 2005, 12:18 AM
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.
March 1st, 2005, 12:50 AM
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, 05: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, 07: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.