Re: Record Locking
Posted in 1994
bathini@netcom.com (Suresh Kumar Bathini) writes: >Hi There: >I have two clients in their transactions as below. >Client1----> > begin work > fetch a record R1 > > ..... > update R1 > commit work >Client2-----> > begin work > fetch a record R1 > update R1 > commit Work >Both the clients fetched the same record but client2 updated R1 before >client1 did, so this resulted in client1's R1 to be an old copy. Is >there a way I could lock a record to read in a transaction? Or is this >kind of problem accepatable in Relational world as R1 is a copy and >doesn't guarentee its state in d/b? You need to declare your cursor to select R1 "FOR UPDATE". Then: UPDATE R1 WHERE CURRENT OF cursorname. Now, when Client1 fetches R1, an Update Lock will be placed on the record. When Client2 attempts to fetch the same recor with an Update Lock, it will be unable to acquire it. If LOCK MODE is not set to WAIT, then the engine will immediately return -246 to Client2. ___ ___ Senior Consultant / ) __ . __/ /_ ) _ _ __ Informix Software Inc. (303) 850-0210 _/__/ (_(_ (/ / (_(_ _/__) (-' ~/ '(_- 5299 DTC Blvd #740 Englewood CO 80111