CFML conversion of query string () query () to structure syntax

I have code inside the loop since the loop repeats. I set a dynamic variable tempto a value getAdvisor_Advisors.advisor_IDfor the current iteration of the loop.

<cfset temp = "getAdvisor_Advisors#LoopCount#.advisor_ID">

The cfinvoke below calls a request that I pass in the dynamic variable "temp", but must use a slow evaluation (temp) around it to get the correct value.

<cfinvoke component="com.appointments" method="get_All_Appointments" returnvariable="getAppointments">
      <cfinvokeargument name="Advisor_ID" value="#evaluate(temp)#">
      <cfinvokeargument name="StartDay" value="#dateFormat(form.cal,'dd')#">
      <cfinvokeargument name="StartMonth" value="#dateFormat(form.cal,'mm')#">
      <cfinvokeargument name="StartYear" value="#dateformat(form.cal,'yyyy')#">             
</cfinvoke>

I want to rewrite the variable tempand evaluate()so as not to use the estimate. I am told that I can use the structure syntax to refer to it like the following:

No rating:

<cfset foo = qBar["text#lang#"][CurrentRow]>
getAdvisor_Advisor["advisor_ID"][CurrentRow]

How to rewrite

<cfset temp = "getAdvisor_Advisors#LoopCount#.advisor_ID">

using structure syntax?

Adding more code so you can understand why it is complicated, these are complex loops.

              

            <cfquery name="getAdvisor_Advisors1" dbtype="query" cachedWithin="#CreateTimeSpan(0,0,15,0)#">
                Select *
                From getAdvisors
                Where Express = 'FR/SO' 
                Order by Specialization, Advisor
            </cfquery>

            <cfquery name="getAdvisor_Advisors2" dbtype="query" cachedWithin="#CreateTimeSpan(0,0,15,0)#">
                Select *
                From getAdvisors
                Where Express = 'JR/SR' 
                Order by Specialization, Advisor
            </cfquery>

            <cfquery name="getAdvisor_Advisors3" dbtype="query" cachedwithin="#CreateTimeSpan(0,0,15,0)#">
                Select *
                From getAdvisors
                Where Specialization IS NULL AND Appointments = 1 AND Campus_ID > 0
                Order by Campus_ID, Advisor
            </cfquery>

            <cfquery name="getAdvisor_Advisors4" dbtype="query" cachedwithin="#CreateTimeSpan(0,0,15,0)#">
                Select *
                From getAdvisors
                Where Specialization IS NOT NULL
                AND Title != 'BCC-GA' 
                Order by Specialization, Advisor
            </cfquery>

            <div id="calendarGrid">
                <!--- looping over the filter queries above that split advisors into groups --->   
                <cfloop index="LoopCount" from = "1" to = "4"> 
                    <!--- FR/SO Advisors --->
                    <cfif LoopCount LTE 3>
                        <cfset currGroup = "campus_id">
                    <cfelse>
                        <cfset currGroup = "specialization">
                   </cfif>
                    <cfoutput query="getAdvisor_Advisors#LoopCount#" group="#currGroup#">
                    <div class="advisorGrouping">
                        <div id="calcontainer">
                            <table class="pickme" border="0" cellspacing="1" cellpadding="1">
                                <tr class="hdr">
                                    <td width="6.9%">
                                        <cfif (Specialization IS "BCC") OR (Specialization IS "HONORS")>
                                            #uCase(Specialization)#
                                        <cfelse>                           
                                            #uCase(Campus_Text)# 
                                        <cfif Len(Express) NEQ 0>
                                            - #uCase(Express)#
                                        </cfif>
                                    </cfif>
                                    </td>
                                    <td width="4.9%" class="border">8:00</td>
                                    <td width="4.9%" class="border">8:30</td>
                                    <td width="4.9%" class="border">9:00</td>
                                    <td width="4.9%" class="border">9:30</td>
                                    <td width="4.9%" class="border">10:00</td>
                                    <td width="4.9%" class="border">10:30</td>
                                    <td width="4.9%" class="border">11:00</td>
                                    <td width="4.9%" class="border">11:30</td>
                                    <td width="4.9%" class="border">12:00</td>
                                    <td width="4.9%" class="border">12:30</td>
                                    <td width="4.9%" class="border">1:00</td>
                                    <td width="4.9%" class="border">1:30</td>
                                    <td width="4.9%" class="border">2:00</td>
                                    <td width="4.9%" class="border">2:30</td>
                                    <td width="4.9%" class="border">3:00</td>
                                    <td width="4.9%" class="border">3:30</td>
                                    <td width="4.9%" class="border">4:00</td>
                                    <td width="4.9%" class="border">4:30</td>
                                    <td width="4.9%" class="border">5:00</td>
                                </tr>
                                <cfoutput group="advisor_id">


                                    <cfset temp = "getAdvisor_Advisors#LoopCount#.advisor_ID">


                                    <!--- get Appts for cal date --->   
                                    <cfinvoke component="com.appointments" method="get_All_Appointments" returnvariable="getAppointments">
                                        <cfinvokeargument name="Advisor_ID" value="#evaluate(temp)#">
                                        <cfinvokeargument name="StartDay" value="#dateFormat(form.cal,'dd')#">
                                        <cfinvokeargument name="StartMonth" value="#dateFormat(form.cal,'mm')#">
                                        <cfinvokeargument name="StartYear" value="#dateformat(form.cal,'yyyy')#">             
                                    </cfinvoke>  
+6
3

, QueryToStruct. , .

<!--- CREATE THE ARRAY --->
<cfset temp = arrayNew(1)>

<cfquery name="getAdvisor_Advisors1" dbtype="query" cachedWithin="#CreateTimeSpan(0,0,15,0)#">
    Select *
    rom getAdvisors
    Where Express = 'FR/SO' 
    Order by Specialization, Advisor
</cfquery>

<!--- CREATE AND FILL THE STRUCT --->
<cfset temp[1] = QueryToStruct(getAdvisor_Advisors1)>

temp .

<cfloop from="1" to="#arrayLen(temp)#" index="t">
    ...
    <cfinvokeargument name="Advisor_ID" value="#temp[t].advisor_ID#">
    ...
</cfloop>

QueryToStruct: https://gist.github.com/erikvold/764276

: enter image description here

: cfloop cfoutput? :

<cfloop query = "getAdvisor_Advisor">
<cfinvoke component="com.appointments" method="get_All_Appointments" returnvariable="getAppointments">
      <cfinvokeargument name="Advisor_ID" value="#getAdvisor_Advisors.advisor_ID#">
      <cfinvokeargument name="StartDay" value="#dateFormat(form.cal,'dd')#">
      <cfinvokeargument name="StartMonth" value="#dateFormat(form.cal,'mm')#">
      <cfinvokeargument name="StartYear" value="#dateformat(form.cal,'yyyy')#">             
</cfinvoke>
</cfloop>
+1

, , . , .

myObject = CreateObject("component","com.appointments");
argumentStructure = StructNew();
argumentStructure.StartDay= dateFormat(form.cal,'dd');
argumentStructure.StartMonth= dateFormat(form.cal,'mm');
argumentStructure.StartYear = dateFormat(form.cal,'yyyy');
</cfscript>

.

<cfloop query = "getAdvisor_Advisor">
<cfscript>
argumentStructure.advisor_ID = advisor_ID;
variableFromObject = myObject.get_All_Appointments(argumentCollection = argumentStructure);
//  code to process that variable
</cfscript>
</cfloop>

, , . .

+1
variables["getAdvisor_Advisors#LoopCount#"].advisor_ID[variables["getAdvisor_Advisors#LoopCount#"].currentRow]`

, , , ...

currentQuery = variables["getAdvisor_Advisors#LoopCount#"];
currentQuery.advisor_ID[currentQuery.currentRow]`

. , , , .

, , ...

<cfset queries = {} />
<cfquery name="queries.AdvisoryQuery1Name" ...>
    ...
</query>
<cfloop collection="#queries#" ...

, , . .

<cfloop list="FR_SO_ExpressAdvisors,JR_SR_ExpressAdvisors,etc" index="queryname">
    <cfset query = variables[queryname] />
    .... etc

.

+1

Source: https://habr.com/ru/post/1017316/


All Articles