RE: Select for update

[prev] [thread] [next] [Date index for 2004/07/19]

From: Ian McDonald-ONLINE
Subject: RE: Select for update
Date: 16:08 on 19 Jul 2004
Will it guarantee that no other process will start a transaction
affecting the same rows at the same time? This is what 'select for
update' does. Rather than making the whole transaction atomic,
committing at the end only makes the changes to the database atomic.

That wasn't a very transparent explanation, so I shall give an example
of the kind of situation I am trying to guard against:
t1: A reads the data.
t2: B reads the data.
t3: A makes some changes to the data on the basis of what it was like at
t1. It uses transactions, so they are atomic. Fortunately, the data
hasn't changed.
t4: B makes some changes to the data on the basis of what it was like at
t2. But it has changed, and so B gets its changes wrong.

If A had used "select for update", it would stop B from reading the data
until A had rolled back or committed.

This is what I'm wanting to guard against.

-----Original Message-----
From: Edward J. Sabol [mailto:sabol@xxxxxxxx.xxxx.xxxx.xxx]=20
Sent: 19 July 2004 15:16
To: Ian McDonald-ONLINE
Cc: cdbi-talk@xxxxxx.xxxxx.xxx
Subject: Re: Select for update


Ian McDonald wrote:
> Hi, I'd like to make some of my units of work (collections of updates=20=

> across multiple tables) atomic, and plan to do this by issuing "select

> ... for update" commands instead of simple selects.

Read <http://www.class-dbi.com/cgi-bin/wiki/index.cgi?AtomicUpdates>;
for the best practice in implementing atomic anything.

> Am I right to think I need to overload private methods or use add_sql=20=

> for this?

You mean set_sql(), right? Anyway, that or add_constructor() as Jason
Scott Gessner suggested in the other response. And wrap it all inside of
a
do_transaction() (see the above Wiki page).

http://www.bbc.co.uk/ - World Wide Wonderland

This e-mail (and any attachments) is confidential and may contain
personal views which are not the views of the BBC unless specifically
stated.
If you have received it in error, please delete it from your system.=20
Do not use, copy or disclose the information in any way nor act in
reliance on it and notify the sender immediately. Please note that the
BBC monitors e-mails sent or received.=20
Further communication will signify your consent to this.

Select for update
Ian McDonald-ONLINE 13:15 on 19 Jul 2004

Re: Select for update
jason scott gessner 13:27 on 19 Jul 2004

Re: Select for update
Edward J. Sabol 14:16 on 19 Jul 2004

Re: Select for update
Perrin Harkins 14:22 on 19 Jul 2004

Re: Select for update
Edward J. Sabol 15:11 on 19 Jul 2004

RE: Select for update
Ian McDonald-ONLINE 16:08 on 19 Jul 2004

RE: Select for update
Perrin Harkins 16:55 on 19 Jul 2004

Generated at 11:35 on 01 Dec 2004 by mariachi v0.52