I have several worker threads that need to pull rows from a database and work on them. Trying to make a single call that shows the row has/is being checked. I had hoped cursor.lastrowid would work but it always returns zero. The docs say "This read-only property returns the value generated for an AUTO_INCREMENT column by the previous INSERT or UPDATE statement". The table has two columns, id (unique, auto increment) checked (int).
cursor.execute('UPDATE the_table SET checked = 1 WHERE checked = 0 LIMIT 1')
mysql.commit()
id = cursor.lastrowid
print(id) #returns 0 not last id
This does update the row but the cursor.lastrowid is always 0. cursor.rowcount returns 1. Checking the database shows a single row affected. Are there any known issues or perhaps I have something out of order?
EDIT: This may not be possible. I have not seen any working example where an UPDATE can return the auto_increment value. Perhaps the docs need to be updated?