Below is my RUN_SQL function:
def RUN_SQL_SAFE(sql, input_tuple=(), get_update_id=False, debug = False):
conn = GET_MYSQL_CONNECTION()
cursor = conn.cursor(cursorclass=MySQLdb.cursors.DictCursor)
cursor.execute(sql, input_tuple)
conn.commit()
if get_update_id:
res = cursor.lastrowid
cursor.close()
conn.close()
if get_update_id:
return res
I run my code using “RUN_SQL_SAFE(sql, tuple, True)”, here sql is a insert sql and the table is empty but return res with 3. I wonder to know why it doesn’t return 1??
Thanks
Maybe the table has been in use before an therefore has an
AUTO_INCREMENTvalue> 1…BTW: I don’t think that this repeated
if get_update_id:is very elegant. Instead, you could doIf you could tell your connection to have
MySQLdb.cursors.DictCursoras its “basic cursor class”, you could even dowhich does this commit automatically.