benutzername
Programmer
I have a table containing three columns: "ID", "url" and "status". The table contains a list of URLs,
all with status = 0 in the beginning.
With each query I want to read one URL from the database and mark the read URLs by setting their status
to 1.
In the moment, I'm doing this with two queries:
1.) "SELECT ID, url FROM myTable WHERE status = 0 LIMIT 1"
This way I get an URL and the ID of this URL. Now I can set the status of this URL to 1 to mark it as
read:
2.) "UPDATE myTable SET status = 1 WHERE ID = " + urlID
This works fine...
The problem: I'm working with multiple threads, so it could happen, that another thread gets the same
URL, before the status is set to 1.
The solution: I want to perform both actions in a single query - this shouldn't be so hard, but I'm
not very into SQL so I don't know, how to do it.
best regards,
Ben Utzer
all with status = 0 in the beginning.
With each query I want to read one URL from the database and mark the read URLs by setting their status
to 1.
In the moment, I'm doing this with two queries:
1.) "SELECT ID, url FROM myTable WHERE status = 0 LIMIT 1"
This way I get an URL and the ID of this URL. Now I can set the status of this URL to 1 to mark it as
read:
2.) "UPDATE myTable SET status = 1 WHERE ID = " + urlID
This works fine...
The problem: I'm working with multiple threads, so it could happen, that another thread gets the same
URL, before the status is set to 1.
The solution: I want to perform both actions in a single query - this shouldn't be so hard, but I'm
not very into SQL so I don't know, how to do it.
best regards,
Ben Utzer