Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2006

    Question 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.


  2. #2
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts