Click to See Complete Forum and Search --> : The equivalent C# Interlocked.Increment() in MySQL ?


mikoil
October 26th, 2006, 02:48 PM
Hi!
I have this task:
I have a MySQL table (database) with this records:
ID File
~~ ~~~
1 f1.dat
2 f2.dat
3 f3.dat
4 f4.dat

And this table that holds only 1 record which is the current id, eg:
CurrentID
~~~~~~
{x}


I need my cgi to increase the CurrentID value and have the result. Also, reset to 1 if the CurrentID is 4 (end of the table).
Simple algo to make it clear:

if(CurrentID==4)
CurrentID=0;
CurrentID++;


The problem is that this cgi might be executed dozens of times per second, so I might get problems like my cgi would save an invalid value or something, I'm not really sure even :)

Is there a MySQL function to do this? Simply get CurrentID's value PLUS increase it by one, no matter how many "threads" are doing it in the same time?

mikoil
October 28th, 2006, 02:17 AM
Noone knows? :(