BEGIN; SELECT COUNT(*) INTO @n FROM Duties WHERE Shift=@s AND Status='on duty' FOR UPDATE; if @n > 1 then UPDATE Duties SET Status='reserve' WHERE DoctorId=@d AND Shift=@s; COMMIT; else ROLLBACK;
If you're not familiar with InnoDB, the SELECT establishes a critical section covering the on duty doctors. This same sequence executing concurrently will block until the connection with the lock has checked the count. The COMMIT (or ROLLBACK) will unblock the other connection waiting for the lock. In case the first connection committed an UPDATE which reduced the count to 1, the second connection, when unblocked, will see the new count of 1 and not make any update.
@ marnanel: Sounds like you are best finding another country.
Come to Canada, at least we respect and are knowledgeable about other countries and cultures. The condescension of your child's teacher and your bank is not worth tolerating.
For I wrote a book, you see, .... It was about how, if you sack too many people, or you underpay and impoverish too many people, there aren't enough customers left to sell things to, and the economy goes to hell. I wrote it in 1998 and nobody attacked any one of the arguments. They tiptoed away from the argument. They were above such things.
And lo, it has come to pass. Americans too impoverished to buy houses had stopped making their payments, and cash their creditors owed to lending entities further up the money chain could not be paid either, and like bird flu the illness swept across the planet, and here we are. And I was right; and Michael Costa and Peter Costello and all the neocons and Friedmanites and Tim Blair were wrong. And we are now in big trouble.
Decide how long Alan Greenspan should spend in gaol. For he nearly wrecked the world, in my view, with his one percent interest rates and house loans to fools as dumb as Barney in The Simpsons, ... Decide how long George Bush should spend in gaol for squandering a trillion dollars (thus far) on two needless unending wars and another trillion thus far bailing out his upperclass coke-sniffing accomplices who like him couldn't add.
And, boy, they really couldn't add. They thought the dollar could be floated for instance, and China's command economy with its fixed undervalued currency and low house prices was doomed to fail. They thought they'd won the Cold War against such barbarities, and socialist command economies didn't work. And they borrowed money from China, trillions of dollars from China, to prove their system worked better. China, which quietly won the Cold War by lending it to them, if you care to add up the figures.
New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.
Keep up with the latest Advogato features by reading the Advogato status blog.
If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!