Well, I'm not sure it was stated that a return value was needed. The way I read the original post was basically (to paraphrase): "I need to update a counter field, and the way I intend to do it is to retrieve the current value, modify it, and then write it out again as two separate queries". If that's the scenario, I don't see any reason the SQL statement I gave (assuming I got the syntax right) wouldn't work just fine.

If your saying that you need to do the update and then retrieve the value for some reason, then I agree, it's not as straight-forward. One thing that MIGHT work, although I'd frankly have to go try it myself to be sure, is a subquery, something along the lines of:

select (update table set counter=counter+1) as counter from table

Even if the theory is correct, I'm not sure about how database-independant it may or may not be.

--
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com

Mike Curwen wrote:
Ok, since it's been brought forward...

how do you update and retrieve all in one query? This is for: "I need a new
primary key, and I need it to be thread safe."
something that would run on mysql?
unless you can get this magic query, it's not quite as simple as "let the
databse handle it", is it?




-----Original Message-----
From: Peter Lin [mailto:[EMAIL PROTECTED] Sent: Thursday, September 30, 2004 7:42 PM
To: Tomcat Users List; [EMAIL PROTECTED]
Subject: Re: method level synchronization doesn't work



that would be the easiest way.

but you made it too easy, I thought people are suppose to suffer and stumble :)

peter


On Thu, 30 Sep 2004 17:46:51 -0400, Frank W. Zammetti <[EMAIL PROTECTED]> wrote:


Why not just let SQL do the update?  Do the following:

update my_table set counter_field = counter_field + 1 (where clause here if needed)

(off the top of my head, my syntax might be off)

In other words, why not let the database handle the

concurrency issue?


That's kind of what they're there for (partly anyway).


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]




--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]









---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to