Thread: DB2 + C; embedded SQL
07-03-06, 09:29 #1Registered User
- Join Date
- Jul 2006
Unanswered: DB2 + C; embedded SQL
I have a rather simple question I need answered...I hope.
When declaring and using a cursor in embedded SQL in C code, being used against DB2:
The proper sequence of events for Cursor...Select...For Update:
Should these be:
1) Declare the cursor with the select for update.
2) Open the cursor
3) Fetch cursor into variable
4) Update the record...Where Current Of cursor
5) DB Commit
6) Close the cursor
The concern I have are the last 2. If a close cuirsor happens before the commit, or vice versa:
1) will either way work?
2) will one or the other result in record locks being left hanging on the table?
We are running into a problem where 2 separate applications are accessing the same table, the same record, on occasion, creating -911 reponse.
Thanking you for your input in advance.
07-03-06, 10:43 #2Registered User
- Join Date
- May 2003
When a commit is issued, the cursor is automatically closed, unless you declare the cursor the cursor using the WITH HOLD option.
Locks are not released until a commit (or rollback) is issued.
In your situtation where you are getting 911's, I would declare the cursor using the WITH HOLD option, and commit after each update, and then close the cursor at the very end.M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390