Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CF9: What is this evaluate statement evaluating?

I'm stuck and need a fresh set of eyes on this, please.

I'm working with someone else's spaghetti code who is no longer around and having a heck of a time figuring out what they were evaluating.

<cfset surveyCount = 0>
<cfloop query="surveys">
    <cfif evaluate("defaultReport" & ID)>
        <cfset surveyCount = surveyCount + 1>
    </cfif>
</cfloop>  

In the query dump, I see 9 records which is what I am expecting but because because the evaluate is failing, the surveyCount isn't being incremented. I do not see any columns for defaultReport. In my 15 years of working with CF, I've always avoided evaluate() and now when I need to analyze it, I'm at a complete loss. Can someone offer any guidance?

Added CFDump image (some columns names have been removed for privacy and security): enter image description here

UPDATE I: This file has numerous cfinclude statements and very little code formatting. As a result, I overlooked some cfinclude statements. I found the following. I'm still looking but wanted to document this as I dig.

<cfloop query="surveys"> <cfscript> variables["defaultReport" & ID] = evaluate(thisAssociation & "Price"); </cfscript> </cfloop>

UPDATE II: Dumping the variable scope, I did confirm the variable I am looking for (finding the query I posted in UPDATE I helped, too). :)
enter image description here

like image 700
HPWD Avatar asked Feb 09 '18 03:02

HPWD


People also ask

How does the EVALUATE statement work?

The execution of the EVALUATE statement operates as if each selection subject and selection object were evaluated and assigned a numeric, alphanumeric, DBCS, or national character value; a range of numeric, alphanumeric, DBCS, or national character values; or a truth value.

When does the scope of execution of the evaluative statement end?

The scope of execution of the EVALUATE statement is terminated when execution reaches the end of the scope of the selected WHEN phrase or WHEN OTHER phrase, or when no WHEN phrase is selected and no WHEN OTHER phrase is specified. Rate this page [ Index| Table of contents]

What is the use of EVALUATE statement in COBOL?

EVALUATE statement is used for conditional processing in COBOL. If multiple conditions need to be checked then EVALUATE is a better than IF-ELSE. Using a single EVALUATE condition, we can check multiple conditions.

What is the difference between IF-ELSE and evaluate?

Nesting of ‘IF-ELSE’ statements can be messy hence instead of using IF-ELSE, we can code a single EVALUATE which is much more powerful than IF-ELSE EVALUATE {cond-for-evaluate} [ALSO] {cond-for-evaluate} [ALSO] …


1 Answers

What they wanted to do is to increase surveyCount but only if this thing: evaluate("defaultReport" & ID) evaluates to true.

From your query dump picture it looks like the IDs are numbers like 144, 145, etc...

In this context, you can think at evaluate("defaultReport" & ID) as something like defaultReport144, defaultReport145, etc... (these are variables set somewhere in the code).

So the code:

<cfif evaluate("defaultReport" & ID)>
    <cfset surveyCount = surveyCount + 1>
</cfif>

becomes (for an ID of 144, the first one on your query loop)

<cfif defaultReport144>
    <cfset surveyCount = surveyCount + 1>
</cfif>

and so on... for the other IDs

So, search your code for where variables like defaultReport144, defaultReport145, etc... are set to either true or false (0 or 1).

Something like:

<cfset defaultReport144 = true />

or maybe they use some expression that evaluates to true or false, like:

<cfset defaultReport144 = [some expression] />

If you can't find, then maybe the code was changed or removed in the place where these defaultReport... variables were set.

ColdFusion evaluate() documentation:
https://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7f4e.html

like image 139
Alex Baban Avatar answered Sep 30 '22 05:09

Alex Baban