Don –
"
UPDATE jobs SET jobs.running = 1 WHERE (id in (10,11,12))
…
UPDATE jobs
SET jobs.running = 1
WHERE (id in (10,11,12)
AND lock_version in (1340, 1333, 807));
"
I think you want
update jobs set jobs.running = 1, jobs.lock_version = jobs.lock_version
- 1
where (id = 10 and lock_version = 1340)
or (id = 11 and lock_version = 1333)
or (id = 12 and lock_version = 807)
With a begin transaction somewhere and a rollback if this doesn’t update
3 rows.
Others and Don –
So, I have a record with a lock_version field and Rails did not
increment the lock_version field prior to saving the record on disk.
The ‘save’ method does not maintain lock_version.
I don’t understand what the point is in having magic fields if they are
going to work magically.
Chuck
Chuck Simmons wrote:
I think you want
update jobs set jobs.running = 1, jobs.lock_version = jobs.lock_version
- 1
where (id = 10 and lock_version = 1340)
or (id = 11 and lock_version = 1333)
or (id = 12 and lock_version = 807)
With a begin transaction somewhere and a rollback if this doesn’t update
3 rows.
Chuck,
Yes. Thank you. You are exactly right. I was so focused on setting
the running field I completely missed the part of the update that was
part and parcel to post!
Thank you for the correction!
Wouldn’t this also work?
UPDATE jobs
SET jobs.running = 1, jobs.lock_version = jobs.lock_version + 1
WHERE (id in (10,11,12)
AND lock_version in (1340, 1333, 807));
If so I guess it’s a matter of which is more efficient. Like I
mentioned. I’m certainly not a SQL guy! If any SQL gurus out there can
provide a litte guidence here and the Rails community can verify that
update_all should increment lock_version, then we can work on a patch.