Do I need to get the volume of requests in Coldfusion?

If I run a query / database stored procedure in Coldfusion, what is the proper way to reference the fields returned from the query?

<cfstoredproc procedure="proc_select_extern" datasource="stokkers">
    <cfprocparam type="in" value="#Session.Extern#" cfsqltype="cf_sql_varchar" maxlength="13">
    <cfprocresult name="extern">
</cfstoredproc>
<cfoutput query="extern">
   <cfset variables.some = extern.foo>
   OR 
   <cfset variables.some = foo>
</cfouput>

Say extern includes foo, bar and foobar. Is it better to write:

 extern.foo;
 extern.bar;
 extern.foobar;

because I browse the page and often find these bare variables a bit confusing:

 foo;
 bar;
 foobar;

There is a lot of information about scopes and the correct scope, but I did not find anything in the request-exit.

Thanks for clarifying!

+3
source share
4 answers

Some will tell you that this is a good habitual practice that is always useful because it does not allow you to make mistakes determining the area where it is really important.

cfoutput , - - "WITH" . URL- cfoutput, , . , CFC "" - cfoutput - ( ) .

.. ( :).

+7

, .

, , , , , , ColdFusion , , .

" " a cfloop cfoutput query.

, #columnname# .

#queryName.columnName# .

#cfScope.queryName.columnName#.

, . , , .

<cfset testcfc = new Test().scopeTest()>

<cfcomponent output="false">

    <cffunction name="scopeTest" access="public" output="true" returntype="void">
        <cfargument name="Query" type="query" required="false" default="#QueryNew("xarguments")#">
        <cfargument name="xlocal" type="string" required="false" default="This is not from a query; Arguments scope.">

        <cfset QueryAddRow(Arguments.Query, 1)>
        <cfset Arguments.Query["xarguments"][1] = "this is the arguments scope query">
        <cfset local.Query = QueryNew("xlocal")>
        <cfset QueryAddRow(local.Query, 1)>
        <cfset local.Query["xlocal"][1] = "this is the local scope query">
        <cfset Variables.Query = QueryNew("xVariables")>
        <cfset QueryAddRow(Variables.Query, 1)>
        <cfset Variables.Query["xVariables"][1] = "this is the variables scope query">

        <cfset local.xlocal = "This is not from a query; local scope.">

        <cfloop query="Query">
            <cfoutput>#xlocal#</cfoutput>
        </cfloop>

        <cfdump var="#Arguments#" label="Arguments">
        <cfdump var="#local#" label="local">
        <cfdump var="#variables#" label="Variables">
        <cfabort>
    </cffunction>

</cfcomponent>

: ; . , , .

, <cfoutput>#Query.xlocal#</cfoutput>, . , . <cfoutput>#Query.xarguments#</cfoutput> , Arguments query local Variables.

, :

        <cfloop query="local.Query">
            <cfoutput>#xlocal#</cfoutput>
        </cfloop>

. . , :

        <cfloop query="local.Query">
            <cfoutput>#Query.xlocal#</cfoutput>
        </cfloop>

. . , , .

        <cfloop query="local.Query">
            <cfoutput>#local.Query.xlocal#</cfoutput>
        </cfloop>

, , , , .

+5

, , . . " , !"

, , .

<cfscript>
Q = MyCFC.getCustomers();
if (! isQuery(Q) || Q.RecordCount == 0) {
    writeOutput("No records found.");
}  else {
    for (i = 1; i lte Q.RecordCount; i++) {
        VARIABLES.Customer = "#Q.FirstName[i]# #Q.LastName[i]#";
        writeOutput(VARIABLES.Customer);
        writeOutput("<br>");
    }
}
</cfscript>
+3

, .

, CFC. , var q = ''; q, , , DRY .

, , , , , . , , ; .

peeve - , , ( ), , "", URL, / , . , , ... UGH!

cfquery/cfoutput/cfloop . , , cfouput/cfloop cfc/object.

, . "Variables", CFC , , , , .

.

I.e.:

<cfprocresult name="Local.qExtern">

:

<cfoutput query='Local.qExtern'> 
    #Local.qExtern.szNameFirst# 
    #Local.qExtern.szNameLast# 
</cfoutput>

, 3 , :

, , , , , . , , , / .

BLEEDING & LOCKING

, CFC vars , , , , . , * / () / , (, , ).

SPEED:

, , , JS , CF, , .

* : , . ( , , ) , , /. , , - , ( , , ) ( / , ).

+2

All Articles