Search code examples
coldfusioncfquery

cfquery name attribute, optional?


Is name attribute of cfquery optional? The doc said it is required, but my code seems to run fine even without it. Is there a default value if not defined? and if so, shall I local var it or safely ignore it?

Thx


Solution

  • I think you can safely omit the name. It does not appear to add a default name to the variables or local scopes.

    However, I did notice something strange under CF9. If you do not local scope the result, the key cfquery.executiontime is added to the variables scope. This is with all debugging disabled (unless I missed something).

    Results:
    Before  Variables = 1 Local = 1
    After   Variables = 2 Local = 1   (result NOT local scoped)
    
    
    <cffunction name="myFunction" output="true">
        <b>Before</b>
        Variables = #structCount(variables)#
        Local = #structCount(local)#<br />
    
        <cfquery datasource="MyDatasource">
            SELECT getDate() AS TestDate
        </cfquery>
    
        <b>After</b>
        Variables = #structCount(variables)#
        Local = #structCount(local)#<br />
    </cffunction>