How would you correctly iterate all the rows of a database query when doing multiple passes of a long operation without missing any row? In my case i have alphanumeric IDs, so id column is not reliable...
The main problem is that the query results may change between each cron task execution.
A first idea could be to store the offset / "number of rows processed". But if one of the already processed rows is deleted the others would shift and the first one would be skipped.
If I store the id of the last processed row and skip to the one after it I have a worse problem: if that exact row is deleted the next cron job will skip every remaining row.
Is there any more "standard" way of iterating a table like this ?
I'm doing this in php with a third party orm engine using sql as data store, but i think it's more a general question so anyone feel free to retag this more appropriately.