473,536 Members | 2,901 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

CURSOR Keeps Closing

I wrote a stored procedure that contains some COMMIT logic, but keep
runnign into an odd problem. As soon as the procedure gets to the
COMMIT statement, the CURSOR closes. Here's the procedure:

CREATE PROCEDURE AIM.UPDATEARCHIVERETRIEVALSTATUS ( )
SPECIFIC AIM.UPDATEARCRETSTS
LANGUAGE SQL

P1: BEGIN
DECLARE RECORDCOUNT INTEGER;
DECLARE intLOOPS INTEGER;
DECLARE intImageCount INTEGER;
DECLARE decArchiveRetrievalID DECIMAL (13,0);
DECLARE AT_END int DEFAULT 0;
DECLARE NOT_FOUND CONDITION FOR SQLSTATE '02000';
DECLARE UPDATE_CURSOR CURSOR FOR
SELECT ARCHIVERETRIEVALID FROM AIM.ARCHIVERETRIEVAL WHERE
ESTIMATEDRESPONSETIME < CURRENT TIMESTAMP --AND EXPIRATIONDATE <
DATE(CURRENT TIMESTAMP)
AND STATUSID = 2
--OR SELECT ARCHIVERETRIEVALID FROM AIM.ARCHIVERETRIEVAL WHERE
OR
ESTIMATEDRESPONSETIME < CURRENT TIMESTAMP AND EXPIRATIONDATE IS NULL
AND STATUSID = 2;

DECLARE CONTINUE HANDLER for NOT_FOUND
SET AT_END = 1;

SET intLOOPS = 0;
SET RECORDCOUNT = 0;

OPEN UPDATE_CURSOR;
FETCH_LOOP:
LOOP
FETCH UPDATE_CURSOR INTO decArchiveRetrievalID;
SET intImageCount = (SELECT COUNT(IMAGEFRONT) FROM AIM.AIMRETRIEVEDITEM
WHERE ARCHIVERETRIEVALID = decArchiveRetrievalID
AND LENGTH(IMAGEFRONT) > 0);
IF AT_END = 1 THEN
LEAVE FETCH_LOOP;
ELSEIF intImageCount = (SELECT ITEMCOUNT FROM AIM.ARCHIVERETRIEVAL
WHERE ARCHIVERETRIEVALID = decArchiveRetrievalID) THEN
ITERATE FETCH_LOOP;
END IF;
UPDATE AIM.ArchiveRetrieval SET STATUSID = 3 WHERE ARCHIVERETRIEVALID =
decArchiveRetrievalID;
SET RECORDCOUNT = RECORDCOUNT + 1;
IF RECORDCOUNT = 10 THEN
COMMIT;
SET intLOOPS = intLOOPS + 1;
SET RECORDCOUNT = 0;
END IF;
END LOOP FETCH_LOOP;
CLOSE UPDATE_CURSOR;

CALL AIM.UPDATEAIMRETRIEVALSTATUS_CRON();

END P1

For instance, I know there should be 45 rows updated. The procedure
gets through the first set of 10 updates and then it bombs and gives me
the following error:

A database manager error occurred.[IBM][CLI Driver][DB2/6000] SQL0501N
The cursor specified in a FETCH or CLOSE statement is not open.
SQLSTATE=24501

Can I assume the COMMIT is what's causing it to close the cursor? Is
there any way to address this?

THanks for any help!

Nov 12 '05 #1
2 9473
"ansonee" <an*****@yahoo.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
I wrote a stored procedure that contains some COMMIT logic, but keep
runnign into an odd problem. As soon as the procedure gets to the
COMMIT statement, the CURSOR closes. Here's the procedure:

CREATE PROCEDURE AIM.UPDATEARCHIVERETRIEVALSTATUS ( )
SPECIFIC AIM.UPDATEARCRETSTS
LANGUAGE SQL

P1: BEGIN
DECLARE RECORDCOUNT INTEGER;
DECLARE intLOOPS INTEGER;
DECLARE intImageCount INTEGER;
DECLARE decArchiveRetrievalID DECIMAL (13,0);
DECLARE AT_END int DEFAULT 0;
DECLARE NOT_FOUND CONDITION FOR SQLSTATE '02000';
DECLARE UPDATE_CURSOR CURSOR FOR
SELECT ARCHIVERETRIEVALID FROM AIM.ARCHIVERETRIEVAL WHERE
ESTIMATEDRESPONSETIME < CURRENT TIMESTAMP --AND EXPIRATIONDATE <
DATE(CURRENT TIMESTAMP)
AND STATUSID = 2
--OR SELECT ARCHIVERETRIEVALID FROM AIM.ARCHIVERETRIEVAL WHERE
OR
ESTIMATEDRESPONSETIME < CURRENT TIMESTAMP AND EXPIRATIONDATE IS NULL
AND STATUSID = 2;

DECLARE CONTINUE HANDLER for NOT_FOUND
SET AT_END = 1;

SET intLOOPS = 0;
SET RECORDCOUNT = 0;

OPEN UPDATE_CURSOR;
FETCH_LOOP:
LOOP
FETCH UPDATE_CURSOR INTO decArchiveRetrievalID;
SET intImageCount = (SELECT COUNT(IMAGEFRONT) FROM AIM.AIMRETRIEVEDITEM
WHERE ARCHIVERETRIEVALID = decArchiveRetrievalID
AND LENGTH(IMAGEFRONT) > 0);
IF AT_END = 1 THEN
LEAVE FETCH_LOOP;
ELSEIF intImageCount = (SELECT ITEMCOUNT FROM AIM.ARCHIVERETRIEVAL
WHERE ARCHIVERETRIEVALID = decArchiveRetrievalID) THEN
ITERATE FETCH_LOOP;
END IF;
UPDATE AIM.ArchiveRetrieval SET STATUSID = 3 WHERE ARCHIVERETRIEVALID =
decArchiveRetrievalID;
SET RECORDCOUNT = RECORDCOUNT + 1;
IF RECORDCOUNT = 10 THEN
COMMIT;
SET intLOOPS = intLOOPS + 1;
SET RECORDCOUNT = 0;
END IF;
END LOOP FETCH_LOOP;
CLOSE UPDATE_CURSOR;

CALL AIM.UPDATEAIMRETRIEVALSTATUS_CRON();

END P1

For instance, I know there should be 45 rows updated. The procedure
gets through the first set of 10 updates and then it bombs and gives me
the following error:

A database manager error occurred.[IBM][CLI Driver][DB2/6000] SQL0501N
The cursor specified in a FETCH or CLOSE statement is not open.
SQLSTATE=24501

Can I assume the COMMIT is what's causing it to close the cursor? Is
there any way to address this?

THanks for any help!

Cursor closes at COMMIT unless you use the WITH HOLD option on cursor.
Nov 12 '05 #2
have you tried accomplishing the same task using only SQL, i.e.

UPDATE AIM.ArchiveRetrieval SET STATUSID = 3
WHERE
((ESTIMATEDRESPONSETIME < CURRENT TIMESTAMP --AND EXPIRATIONDATE <
DATE(CURRENT TIMESTAMP)
AND STATUSID = 2)
OR
(ESTIMATEDRESPONSETIME < CURRENT TIMESTAMP AND EXPIRATIONDATE IS NULL
AND STATUSID = 2))
AND
(
(SELECT COUNT(IMAGEFRONT) FROM AIM.AIMRETRIEVEDITEM
WHERE ARCHIVERETRIEVALID = AIM.ArchiveRetrieval.ARCHIVERETRIEVALID
AND LENGTH(IMAGEFRONT) > 0)
<>
(SELECT ITEMCOUNT FROM AIM.ARCHIVERETRIEVAL
WHERE ARCHIVERETRIEVALID = AIM.ArchiveRetrieval.ARCHIVERETRIEVALID )
)

Nov 12 '05 #3

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

Similar topics

1
1891
by: dinesh prasad | last post by:
I'm simply trying to divide each close1 column by 20, then insert that value into the twentydayMA field. The query keeps on running without finishing, even if I'm only using a single page of data. What could be making this hang? To execute, I'm using exec tad778. I thought about using another cursor to to handle the return values, instead of...
1
2243
by: ilPostino | last post by:
I'm using this function to load a custom cursor from a .cur file; public static extern IntPtr LoadCursorFromFile(String str); It works great but if I popup a ContextMenu or Control like a ListView, the cursor resets to the system arrow. Even if I set the cursor property of each control to the one loaded it just ignores it. The...
2
1928
by: Nathan Sokalski | last post by:
I have a section in my ASP.NET code where I have an HTML unordered list. Visual Studio keeps removing the closing list item tags, except for the last list item. In other words, Visual Studio makes my code look like the following: <ul> <li>adasf <li>asdfsa <li>asdfd <li>adfsdf</li>
3
7195
by: Rud | last post by:
I'm still searching for an easy way to implement customized mouse pointers. I've searched in the help text but couldn't get the answer. Do I have to dig into the creation of resource files or is there a better alternative? Can I use an imagelist like: panel.cursor = imagelist.listimages(1) or something like this??? Kind regards, Rud
5
34209
by: Paul M | last post by:
Hi All, I've been tasked with writing a z/OS C program to read and update a table (DB/2 v8). This Table contains a single row with a single column of data. This program (which will run as a Stored Proc) needs to implement a strategy for concurrency as the Stored Proc can be called concurrently by several different users. The code...
10
2087
by: Franky | last post by:
I think I misread a post and understood that if I do: System.Windows.Forms.Cursor.Current = Cursors.WaitCursor there is no need to reset the cursor to Default. So I made all the reset statements into comments (placed an ' in front)
2
2275
by: Florian Lindner | last post by:
Hello, I have a function that executes a SQL statement with MySQLdb: def executeSQL(sql, *args): print sql % args cursor = conn.cursor() cursor.execute(sql, args) cursor.close() it's called like that:
1
1782
by: love2livedislife | last post by:
I have a requirement as follows: while executing the procedure for first time i'll open a cursor and read the first row from it and return the value through OUT parameter of procedure without closing the cursor... during the second time execution of the same procedure i need the cursor to be opened so that i can read the second row during...
1
2518
by: luigidavinci | last post by:
I am using Scriptaculous to achieve a pretty simple and straightforward effect. I need a couple of images and text to fade in and fade out periodically, which I already managed to do it using SetInterval, Effect.Appear and Effect.Fade. The only problem is that while the effects are taking place(fading in/out) the cursor keeps flickering in IE(not...
0
7359
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7289
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7530
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7273
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5821
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4841
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
918
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
570
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.