MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

SELECT FOR UPDATE and locks

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
Luc Orient
Beginner


Joined: 30 Apr 2006
Posts: 15
Topics: 4
Location: Paris - France

PostPosted: Sat Aug 25, 2007 9:14 am    Post subject: SELECT FOR UPDATE and locks Reply with quote

Hello :
A question about duration of a lock in a specific case :

When I have a "SELECT FOR UPDATE" cursor and a package bound with ISOLATION(CS) "a row or page lock is held only long enough to allow the cursor to move to another row or page" (source = DB2 Administration Guide).

My question :
If the package CLOSE the cursor, is the lock released after this statement ?

Thank's in advance ...
Fran
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Sat Aug 25, 2007 12:15 pm    Post subject: Reply with quote

Luc Orient,

When you close a cursor with the CLOSE CURSOR statement that includes the WITH RELEASE clause, the database manager attempts to release all read locks that have been held for the cursor. Table read locks are IS, S, and U table locks. Row-read locks are S, NS, and U row locks. Block-read locks are IS, S, and U block locks.

The WITH RELEASE clause has no effect on cursors that are operating under the CS or UR isolation levels. When specified for cursors that are operating under the RS or RR isolation levels, the WITH RELEASE clause ends some of the guarantees of those isolation levels. Specifically, a RS cursor may experience the nonrepeatable read phenomenon, and a RR cursor may experience either the nonrepeatable read or phantom read phenomenon.

Hope this helps...

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
dbzTHEdinosauer
Supermod


Joined: 20 Oct 2006
Posts: 1411
Topics: 26
Location: germany

PostPosted: Sat Aug 25, 2007 12:54 pm    Post subject: Reply with quote

Kolusu,

If there has been an 'UPDATE CURRENT CURSOR', will not a COMMIT or ROLLBACK be required to release any locks on updated rows/pages???
_________________
Dick Brenholtz
American living in Varel, Germany
Back to top
View user's profile Send private message
Luc Orient
Beginner


Joined: 30 Apr 2006
Posts: 15
Topics: 4
Location: Paris - France

PostPosted: Sat Aug 25, 2007 1:43 pm    Post subject: Reply with quote

kolusu wrote:
Luc Orient,

When you close a cursor with the CLOSE CURSOR statement that includes the WITH RELEASE clause, the database manager ...

I am sorry but I don't see the WITH RELEASE clause in DB2 for z/OS ....

For instance in DB2 V8 SQL Reference :
http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/DSNSQJ13/5.17?PICTORIAL=Y&DT=20060113155812&PICTORIAL=N

Whatever thank's for your response and " Bonjour de Paris " ...
Back to top
View user's profile Send private message
Luc Orient
Beginner


Joined: 30 Apr 2006
Posts: 15
Topics: 4
Location: Paris - France

PostPosted: Sat Aug 25, 2007 1:51 pm    Post subject: Reply with quote

dbzTHEdinosauer wrote:
Kolusu,

If there has been an 'UPDATE CURRENT CURSOR', will not a COMMIT or ROLLBACK be required to release any locks on updated rows/pages???

In my question there is no UPDATE ... WHERE CURRENT OF ...

Only :

- OPEN my_cursor_for_update_of

- FETCH my_cursor_for_update_of - > U lock on the page ...

- CLOSE my_cursor_fot_update_of

So the point is :

The U lock ... released or not released ?

That is the question ...
Back to top
View user's profile Send private message
dbzTHEdinosauer
Supermod


Joined: 20 Oct 2006
Posts: 1411
Topics: 26
Location: germany

PostPosted: Sat Aug 25, 2007 2:38 pm    Post subject: Reply with quote

Luc,

If you are not going to UPDATE or DELETE anything why are you using the FOR UPDATE OF clause?
Are you using the FOR UPDATE OF clause just to lock pages?
What is the goal of your SQL?
_________________
Dick Brenholtz
American living in Varel, Germany
Back to top
View user's profile Send private message
Luc Orient
Beginner


Joined: 30 Apr 2006
Posts: 15
Topics: 4
Location: Paris - France

PostPosted: Sat Aug 25, 2007 3:34 pm    Post subject: Reply with quote

dbzTHEdinosauer wrote:
Luc,

If you are not going to UPDATE or DELETE anything why are you using the FOR UPDATE OF clause?
Are you using the FOR UPDATE OF clause just to lock pages?
What is the goal of your SQL?

You are rigth ...
I want juste to lock the page ...

Another case may be to have the UPDATE far from the FETCH and after the CLOSE ...

I am not saying this way is the right way to program, it's just the way it is done in one of our package ...

I want to understand how it's working and I know we have to modify and to fix these things ...
Back to top
View user's profile Send private message
dbzTHEdinosauer
Supermod


Joined: 20 Oct 2006
Posts: 1411
Topics: 26
Location: germany

PostPosted: Sat Aug 25, 2007 4:42 pm    Post subject: Reply with quote

you should look at the BIND parms, especially the RELEASE(COMMIT) & RELEASE(DEALLOCATE) parms.

What I am getting at is there is more to it than just the SQL. The Bind parms as well as the locks setting - page, row, etc (Database setup)... have a lot to do with what is going on. In addition, a lot has to do with which version of DB2 you are using.
_________________
Dick Brenholtz
American living in Varel, Germany
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group