Toad World® Forums

CodeXpert - why reports CURSOR violations?

Hello,

I am wondering why I get following CURSOR violations on the simple code example below:

  • three times “Cursor - Ensure that any local cursors you are referencing have actually been opened”
    ** (18,16)
    ** (20,13)
    ** (22,19)
  • once “Cursor - Confirm that the cursor you are referencing has been opened”
    ** (12,14)

{code}
CREATE OR REPLACE PACKAGE BODY PKG_TEST
AS
CURSOR cursor1
IS
SELECT 1 FROM DUAL;

PROCEDURE PROC_TEST
IS
val_i NUMBER (10);
BEGIN
IF NOT cursor1%ISOPEN
THEN
OPEN cursor1;
END IF;

  LOOP
     FETCH cursor1 INTO   val_i;

     IF cursor1%NOTFOUND
     THEN
        CLOSE cursor1;

        EXIT;
     END IF;
  /* ... some further code ... */
  END LOOP;

END PROC_TEST;
END PKG_TEST;
/
{code}

Can anybody help me figuring out this?

IMHO it is necessary to ask here if the cursor is already opened due to its declarations in package scope and the possible exception for opening an already open cursor.
For sure one can fix this situation if the cursor is moved to procedure scope but that is not possible because it is reused at another place (this short example just does not contain this).

I am using Toad 9.7.2.5 …

I very much appreciate your help, thank you.

Can anyone tell me if the above described problem still occurs the newest version (11.0) by using the provided code example?

Thank you very much …

Hello Andreas,

A few code analysis rules use older legacy code which often has flaws. We are in the process of replacing old code over time. We already did such for the majority of the rules by introducing XPath expressions. It will sure take several months to finish all kinds of analysis, including cursor analysis. Thanks for understanding, we do the best we can.

Andre

Hi Andre,

thanks for your feedback. It is, though, not clear for me if the above false positive is fixed in 11.5 or not?

Cheers,
Andreas