472,370 Members | 2,561 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,370 software developers and data experts.

ibm db2 lock (row/table) status/indication

as wat ive mentioned in the title.. im would like to know whether the a
particular record/table is being locked in my program. some of the
methods which i would like to develop are as below:

Lock(KEY, SQLCODE)
- to create a lock. Returns 0 on success, 1 if a lock already exists
and -1 on failure with SQLCODE. There is no necessity to use IsLock()
for checking if a lock exists or not, just insert the record and check
for

Unlock(KEY, SQLCODE)
- to remove a lock. Returns 0 on success, -1 on error with the
appropriate SQLCODE. Returns 1 if no lock record is found.

IsLock(Key, SQLCODE)
- to check if a lock for the Keyvalue exists or not. Returns 1 if a
lock exists, 0 otherwise and -1 on error with the appropriate SQLCODE.

is there any dbms status return that will return a status code if the
table/row is lock? however i still couldnt manage to dig any
information from the internet which can help me .any help would be
appreciated. thnks in advance

Feb 9 '06 #1
2 15511
ad****@gmail.com wrote:
as wat ive mentioned in the title.. im would like to know whether the a
particular record/table is being locked in my program. some of the
methods which i would like to develop are as below:

Lock(KEY, SQLCODE)
- to create a lock. Returns 0 on success, 1 if a lock already exists
and -1 on failure with SQLCODE. There is no necessity to use IsLock()
for checking if a lock exists or not, just insert the record and check
for

Unlock(KEY, SQLCODE)
- to remove a lock. Returns 0 on success, -1 on error with the
appropriate SQLCODE. Returns 1 if no lock record is found.

IsLock(Key, SQLCODE)
- to check if a lock for the Keyvalue exists or not. Returns 1 if a
lock exists, 0 otherwise and -1 on error with the appropriate SQLCODE.

is there any dbms status return that will return a status code if the
table/row is lock? however i still couldnt manage to dig any
information from the internet which can help me .any help would be
appreciated. thnks in advance


I really doubt that there is an external interface to get such information
from the DB2 lock manager because:

(1) DB2 locks tuples/rows and you do not get the internal row-id out. This
has to do with encapsulation (basic OO stuff) and data independence.
(2) DB2 supports hierarchical locks, i.e. it locks databases, tables and
rows. Somehow your interface would have to accommodate for that.
(3) There are about a gazillion different locking modes in DB2. I really
doubt that you want to dig into all of them.
(4) Whoever needs to access the locking mechanisms explicitly should rethink
his/her application. The idea is that you use the DBMS to manage your
data. Handling the concurrent access is the job of the DBMS.
What do you need that for?

What you could do, however, is to implement a bunch of UDFs that employ
shared memory techniques to maintain their own locks. Implementing that is
very straight forward.

--
Knut Stolze
DB2 Information Integration Development
IBM Germany
Feb 9 '06 #2
<ad****@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
as wat ive mentioned in the title.. im would like to know whether the a
particular record/table is being locked in my program. some of the
methods which i would like to develop are as below:

Lock(KEY, SQLCODE)
- to create a lock. Returns 0 on success, 1 if a lock already exists
and -1 on failure with SQLCODE. There is no necessity to use IsLock()
for checking if a lock exists or not, just insert the record and check
for

Unlock(KEY, SQLCODE)
- to remove a lock. Returns 0 on success, -1 on error with the
appropriate SQLCODE. Returns 1 if no lock record is found.

IsLock(Key, SQLCODE)
- to check if a lock for the Keyvalue exists or not. Returns 1 if a
lock exists, 0 otherwise and -1 on error with the appropriate SQLCODE.

is there any dbms status return that will return a status code if the
table/row is lock? however i still couldnt manage to dig any
information from the internet which can help me .any help would be
appreciated. thnks in advance


DB2 is known as a locking or pessimistic locking database. It locks
automatically based on the SQL statement submitted in a manner that is
appropriate for most all situation without the need for a programmer to
perform locking tasks. For that reason, it has only limited capabilities to
manually lock rows.

In DB2 you cannot directly lock a row, however by executing the appropriate
SQL statement on the row such as select for update, update, or select on the
row, DB2 will automatically take appropriate locks on the row(s). These
locks may be share locks, update locks, exclusive locks, etc. There is an
explicit lock table statement, but not for rows.

To unlock rows, it depends on what SQL statement was used to lock them. The
isolation level determines how long share locks are held. CS holds share
locks the until the row is finished processing for the select, RS hold the
share locks on all rows processed by the select until the SQL statement is
completely finished, and RR holds share locks on all rows processed until a
commit is issued. Isolation level UR holds no locks and ignores any existing
locks for select statements. All other non-share locks (update, exclusive,
etc) are released at commit time.

If you SET CURRENT LOCK TIMEOUT WAIT, then DB2 will return a -911 reason
code 68 immediately for any SQL that is waiting on a lock. This only works
in a different application than is holding the lock, since an application
cannot lock itself out even with multiple SQL statements. But it will be an
indication that the row is locked. This feature is in the 8.2 release.
Feb 9 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: Robert | last post by:
Hi! I was wondering if the was any way to determine the state of the caps lock key, on or off. Of course I can capture the key events and see whether the caps lock is pressed, but that does not...
2
by: xixi | last post by:
i am using type 4 driver with fp3 on windows 64bit server, auto commit is true, cursor is CS type. i have a sensitive , updatable cursor open and bring back a one row resultset, i get this...
5
by: xixi | last post by:
hi, i am using db2 udb v8.1 on windows, i create a index on a unique value column on a table to try to create row lock, here is what i do , sql = select value from table where id=1 for update,...
9
by: Jane | last post by:
Our db2diag.log is full of messages like this: 2004-05-31-17.15.10.383766 Instance:tminst1 Node:000 PID:394948(db2agent (TMDB1) 0) TID:1 Appid:GA140956.EF26.03A4B1202647 data management ...
0
by: Bruce Pullen | last post by:
DB2 v7.2 (FP7 - DB2 v7.1.0.68) on AIX 5.2.0.0. We're seeing unexpected single row (then commit) insert locking behaviour. We're seeing Applications that already hold row-level W locks in...
2
by: Trent | last post by:
Hello, all. I have the following production DB2 environment. DB2 8.1.4 (fp4) WG edition with 2 production databases on Windows 2003 standard edition. My first question is regard with...
4
by: Ed L. | last post by:
I think I'm seeing table-level lock contention in the following function when I have many different concurrent callers, each with mutually distinct values for $1. Is there a way to reimplement...
2
by: shenanwei | last post by:
DB2 V8.2 on AIX, type II index is created. I see this from deadlock event monitor. 5) Deadlocked Connection ... Participant no.: 2 Lock wait start time: 09/18/2006 23:04:09.911774 .........
9
by: kavallin | last post by:
I receives the following in the db2diag.log file many times / day : 2007-03-05-14.55.24.836553+060 E12415C457 LEVEL: Warning PID : 2785 TID : 1 PROC :...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.