When a row is added to my table, I need a certain column's value to be max+1. This is not an auto increment situation because it's only within a set of rows within the table. In other words, when selecting certain rows, the max of THOSE rows is what needs to determine the next row I add, not the max of the entire table. So there can be more than 1 row with the same values, just not more than 1 row within my x rows I select.
This is when they are added. The values can also be changed later on, manually, via a form, and would still need to remain unique within that set (which is easy, of course).
The problem, here, is since there is a tiny delay between checking for the max value and updating it, technically, even though this has not happened in years of me using this, a second user "could" come along and get that same max value, in between the original user's select and update.
I'd rather not have to do locking the table, and the framework I am working within doesn't have transactions built in. Just curious if anyone has other ideas.
One idea I had was locking the method itself... when someone is using it, add a temporary row to the db, then check for it and if one is there, have the second user basically redirect to the same page until that row is removed. But a lot of extra db work involved there, so I don't know...
This same issue comes into play when there is a limit. Say only 50 people can add a row, 49 have added them, 2 members could both get that same 49 in between a select and update, and be allowed in.