Rubbish in Code Analysis

Hello from Germany,

in one of my package bodies, when executing code analysis, there pop up two strange and not comprehensible messages (see uploaded screen shot fragment).

I'm absolutely sure that I have no line # 0 in my code :joy: And there is not a single appearance of the words "COMPRESS" or "NOCOMPRESS" in my package. And as far as I see, there is also no duplicate CASE WHEN entry.

Of course I can't post my source code here in the public forum, but maybe one of the Quest guys want to have a glimpse on it? For sure I could send you my package.

Let me say, these messages are no matter for me, but maybe something could be fixed in the code analysis, whenever there is a bit time for :slightly_smiling_face:

Best regards,
-Rainer

Just curious... had you initiated Code Analysis in batch (multiple packages/procs) or only for this one package?

I initiated Code Analysis only for this one package

Hello Rainer,

The code analysis engine is part of my shop, so if you like you can safely send your package to me, I'll be glad to examine what could have happened.

Thanks,
Andre

andre.vergison@q.....com

Hello Andre,

first I want to wish you a happy 2024! And second I'd like to ask if there are any news about that topic... :slight_smile:

Best regards
-Rainer

Hello Rainer,

Of course a reciprocal formidable 2024 for you, and all inspired Toadies!

Yes it took me a bit to sort it out. The culprit is the XPath expression of rule 6714 which did not like a mix of WHEN clauses with simple variables (or literals) and WHEN clauses with expressions. This causes an XPath expression error which in Toad was unfortunately converted into a bogus result on line 0, column 0. So Rainer I do fully agree that you have no hidden line 0 in your code!

The same error on rule 6715 (the next rule in the list of rules to be checked) was caused by the above, a minor bug.

The ultimate fix is to have the XPath expression for rule 6714 replaced by the following corrected version:

//EXPR[@cat = "case"]/(
    for $cw in ./CASE_WHEN
      return
      (: compare with all following siblings :)
      for $fcw in $cw/following-sibling::CASE_WHEN
        return $fcw[qp5:equal-tokens(child::*[1], $cw/child::*[1])]/child::*[1]
)

For now you could tweak the Rule Universe file yourself. A next Toad beta (or release) will include the fixed expression as well. Your choice.

(QP-4140)


The rest of this post details what was happening - for those who are interested only, no need to read it, or to understand things whatsoever. :slight_smile:

Here's some minimal code producing the bug:

    BEGIN
       r := CASE
                WHEN x IS NOT NULL THEN y
                WHEN x             THEN z
                ELSE NULL
            END;
    END;

... and matching Parse Info:

      <BLOCK>
        <STMT>
          <ASSIGN>
            <LHS>
              <QNAME value="r">
                <IDENTIFIER value="r" dbvalue="R" />
              </QNAME>
            </LHS>
            <RHS>
              <EXPR cat="case">
                <CASE_WHEN>
                  <EXPR cat="is_not_null">
                    <QNAME value="x">
                      <IDENTIFIER value="x" dbvalue="X" />
                    </QNAME>
                  </EXPR>
                  <QNAME value="y">
                    <IDENTIFIER value="y" dbvalue="Y" />
                  </QNAME>
                </CASE_WHEN>
                <CASE_WHEN>
                  <QNAME value="x">
                    <IDENTIFIER value="x" dbvalue="X" />
                  </QNAME>
                  <QNAME value="z">
                    <IDENTIFIER value="z" dbvalue="Z" />
                  </QNAME>
                </CASE_WHEN>
                <CASE_ELSE>
                  <LITERAL type="boolean" value="null" dbvalue="null" />
                </CASE_ELSE>
              </EXPR>
            </RHS>
          </ASSIGN>
        </STMT>
      </BLOCK>

The old XPath expression ...

//EXPR[@cat = "case"]/(
    for $c in ./CASE_WHEN
    return
      for $ci in $c/following-sibling::CASE_WHEN
        return $ci[qp5:equal-tokens(EXPR, $c/EXPR)]/EXPR
)

... compares each WHEN clause with its following siblings.
In our case it uses an XPath function qp5:equal-tokens() to compare the WHEN variable x with the WHEN expression x IS NOT NULL.

As you can see, in the above case the function will want to compare EXPR children of the CASE_WHEN elements (there's at most one EXPR child though). The first CASE_WHEN has EXPR children indeed, all right, but the second one has QNAME (qualified name) children just because there's no expression! So that caused the error.

The fix is just to compare the children regardless of what they are.

Thanks,
Andre

Thanks very much Andre! I will see if I take the next beta or release.

Best regards,
Rainer

Hmm, in the new TOAD 17.1 it is still working wrong...

Best regards,
-Rainer

Hello Rainer,

Our parser production (and input to Toad team) is currently delayed quite a bit due to external reasons, but it should resume soon (days). So the fixed QP-4140 issue is still in the pipeline so to speak. We talk about a one-time delay before getting back to normal. Sorry for that, and I wanted you to understand what's happening.

In the meantime you could always create a new rule - numbered from 7000 up - with the expression I posted here. It should not be difficult or time consuming to do. Let me know if I can help you here.

Otherwise you may expect the fix to appear in Toad let's say by the end of the month.

Thanks!
Andre

No Problem with the delay Andre! So I decided now to create a new rule with the XPath expression you posted and disable the old rule - and what can I say- it works fine!!! :slight_smile:

So let's look when the fix is in a TOAD release, there is no need to hurry :wink:

Thanks for your support Andre!

Best regards from Germany
-Rainer