查询查询变量作用域

时间:2015-11-04 03:51:24

标签: coldfusion coldfusion-11 qoq

使用查询查询时是否可以对变量进行范围调整?这工作

return queryExecute("
        SELECT Title, Slug, Menu, MenuOrder
        FROM qryResult
        WHERE Menu = 'Y'
        ORDER BY MenuOrder
        ",
        [],
        {dbtype = "query"}
        );

这不起作用。它会抛出错误

return queryExecute("
        SELECT Title, Slug, Menu, MenuOrder
        FROM local.qryResult
        WHERE Menu = 'Y'
        ORDER BY MenuOrder
        ",
        [],
        {dbtype = "query"}
        );
  

消息
查询查询语法错误。
遇到了   “local.StackTrace java.sql.SQLException:
查询查询   语法错误。
遇到“本地。在   coldfusion.sql.imq.jdbcStatement.parseSQL(jdbcStatement.java:590)at   coldfusion.sql.imq.jdbcStatement.fetchResult(jdbcStatement.java:547)   在ORDER BY MenuOrder“,[],{dbtype =”query“});

1 个答案:

答案 0 :(得分:7)

LOCALColdFusion Query of QuerySQL中的保留字。

所以,用这样的LOCAL包裹square brackets[]

return queryExecute("
        SELECT Title, Slug, Menu, MenuOrder
        FROM [local].qryResult
        WHERE Menu = 'Y'
        ORDER BY MenuOrder
        ",
        [],
        {dbtype = "query"}
        );

使用其他名称作为功能本地范围,即

var newLocal = structNew();
newLocal.qryResult = queryNew("");
return queryExecute("
        SELECT Title, Slug, Menu, MenuOrder
        FROM newLocal.qryResult
        WHERE Menu = 'Y'
        ORDER BY MenuOrder
        ",
        [],
        {dbtype = "query"}
        );