RE: Re: Code Analysis false positives for dead code with case statement

"Simoneau, Roger" <[email protected]>
Newsgroups gmane.comp.db.oracle.toad.free
Message-ID <85214F3A9C2FE94F9FF1D7C6456E33F9109EA1BBC7@EX-CLUS-MBX-01.abcp.ab.bluecross.ca>
Well... the cursor wouldn't be closed if you fail on other issues.

Add a "when others then close cursor" and then I'd agree that you've covered every possibility so the rule shouldn't trigger.

Roger S.

From: [email protected] [mailto:[email protected]] On Behalf Of Jonathan
Sent: Friday, June 22, 2012 6:33 AM
To: [email protected]
Subject: [toad] Re: Code Analysis false positives for dead code with case statement



I think I've found another issue this time with rule 2601: Ensure locally opened cursors will be closed.

I believe that in this code snippet it is incorrect in saying the rule fails (I've built this example using the structure of some production code we have) because as far as I can tell the cursor will be closed either at the end of the loop or if the exception is raised.

CREATE OR REPLACE PROCEDURE testproc (x IN PLS_INTEGER)
AS
CURSOR testcur
IS
SELECT * FROM DUAL;

testrec testcur%ROWTYPE;

testexception EXCEPTION;
BEGIN
OPEN testcur;

LOOP
FETCH app_cur INTO app_rec;

EXIT WHEN app_cur%NOTFOUND;

IF x = 1
THEN
BEGIN
--Some code
NULL;
EXCEPTION
WHEN OTHERS
THEN
RAISE testexception;
END;
ELSE
BEGIN
--Some code
NULL;
EXCEPTION
WHEN OTHERS
THEN
RAISE testexception;
END;
END IF;
END LOOP;

CLOSE testcur;
EXCEPTION
WHEN testexception
THEN
CLOSE testcur;
END;

Am I correct that this code is okay and shouldn't be failing this rule?

Regards,

Jonathan


________________________________
This communication, including any attached documentation, is intended only for the person or entity to which it is addressed, and may contain confidential, personal and/or privileged information. Any unauthorized disclosure, copying, or taking action on the contents is strictly prohibited. If you have received this message in error, please contact us immediately so we may correct our records. Please then delete or destroy the original transmission and any subsequent reply.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.