Skip to main content
Legend
Jul 15, 2016 6:50 PM UTC
Answered

Query scope descrepancy between tag and script

I'm fairly certain I found a scope bug. I'm using CF11 and FW/1 and I have the following query -- the tag works, the cfscript equivilent triggers a "Table named rc.qSignerLinks was not found in memory" exception:

/* works*/

<cfquery name="local.qResultSet" result="local.qResult" dbtype="query">

    SELECT

        *

    FROM

        rc.qRSRecipient

    where

        [email] = <cfqueryparam value="#session.user.getEmail()#" cfsqltype="CF_SQL_VARCHAR" maxlength="50" />

</cfquery>

/* exception */

<cfscript>

    local.qObj = new query();

    local.qObj.setDBType("query");

    local.qObj.setSQL("

        SELECT

            *

        FROM

            rc.qRSRecipient

        where

            [email] = :email

    ");

    local.qObj.addParam( name="email",value="#session.user.getEmail()#",cfsqltype="CF_SQL_VARCHAR",maxlength="50" );

    local.qObjResult = local.qObj.execute();

    local.qResultSet= local.qObjResult.getResult().recordCount NEQ 0;

</cfscript>

    This topic is closed to new replies. Start a new post to keep the conversation going.
    BKBK
    BKBKCorrect answer
    Community Expert
    Jul 17, 2016 4:21 PM UTC

    Yes, Steve, that problem has been known for some years now. The usual fix is to add the resultset using setAttributes(), like this:

    local.qObj.setAttributes(tbl = rc.qRSRecipient);

    local.qObj.setSQL("SELECT  *  FROM tbl WHERE [email] = :email");

    18 replies

    BKBK
    Community Expert
    Community Expert
    Jul 17, 2016 4:26 PM UTC

    Having said that, I still think you should file a bug report.

    Translate
    Legend
    Jul 18, 2016 4:06 PM UTC

    Thanks. I already recoded this particular occurrence but I'm sure I'll encounter this again as I move more of my code to cfscript.

    Translate
    BKBK
    Community Expert
    BKBKCommunity ExpertCorrect answer
    Community Expert
    Jul 17, 2016 4:21 PM UTC

    Yes, Steve, that problem has been known for some years now. The usual fix is to add the resultset using setAttributes(), like this:

    local.qObj.setAttributes(tbl = rc.qRSRecipient);

    local.qObj.setSQL("SELECT  *  FROM tbl WHERE [email] = :email");

    Translate
    WolfShade
    Legend
    Jul 15, 2016 8:52 PM UTC

    Not sure if this will help, but there is a Ben Nadel post about CF9's "query.cfc" and using a cfscript qoq.  I hope it might present some insight.

    I've never tried to run a standard query in cfscript, much less a QoQ in cfscript. 

    HTH,

    ^_^

    Translate
    Carl Von Stetten
    Legend
    Jul 15, 2016 11:13 PM UTC

    You might also try looking at the new queryExecute() function introduced in CF11 for script.  It usually works better than the query.cfc-based script approach.

    Translate