Re: Record Locking
Posted in 2000
Topics: SQL Development & Query Writing, Connectivity: ESQL/C, 4GL & Embedded SQL
rajiv wrote: > is it possible to lock a row in informix if yes can u suggest me the > precise step In a programming language (eg ESQL/C), declare a cursor for a SELECT statement with the FOR UPDATE clause appended. When you fetch that row, it will be locked (unless the table has page locking, in which case the page will be locked, possibly locking more than the one row). If it's a MODE ANSI database, all SELECT statements which can be used for UPDATE are implicitly treated as having the FOR UPDATE clause, of course... -- Jonathan Leffler (jleffler@informix.com, jleffler@earthlink.net) Guardian of DBD::Informix v1.00.PC1 -- see http://www.perl.com/CPAN #include <disclaimer.h>
Jonathan Leffler wrote: > rajiv wrote: > > > is it possible to lock a row in informix if yes can u suggest me the > > precise step > > In a programming language (eg ESQL/C), declare a cursor for > a SELECT statement with the FOR UPDATE clause appended. When > you fetch that row, it will be locked (unless the table has > page locking, in which case the page will be locked, possibly > locking more than the one row). However, the (promotable) lock will only be maintained while the cursor is on that row. The moment the next row is fetched, the lock on the previous row is released...unless the row was modified by an UPDATE statement. If UPDATEd, the lock will be maintained for the duration of the transaction. Rudy
Rudy Fernandes wrote: > Jonathan Leffler wrote: > > rajiv wrote: > > > is it possible to lock a row in informix if yes can u suggest me the > > > precise step > > > > In a programming language (eg ESQL/C), declare a cursor for > > a SELECT statement with the FOR UPDATE clause appended. When > > you fetch that row, it will be locked (unless the table has > > page locking, in which case the page will be locked, possibly > > locking more than the one row). > > However, the (promotable) lock will only be maintained while the cursor > is on that row. The moment the next row is fetched, the lock on the > previous row is released...unless the row was modified by an UPDATE > statement. If UPDATEd, the lock will be maintained for the duration of > the transaction. That depends on your isolation level. At repeatable read, a shared lock is held for the duration of the transaction to ensure that you can reread the same data. At lower levels of isolation, what Rudy says is accurate. -- Jonathan Leffler (jleffler@informix.com, jleffler@earthlink.net) Guardian of DBD::Informix v1.00.PC1 -- see http://www.perl.com/CPAN #include <disclaimer.h>