查询变量范围的查询
Query of Queries variable scoping
使用query of queries时是否可以限定变量的范围?这有效
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"}
);
Message
Query Of Queries syntax error.
Encountered
"local. StackTrace java.sql.SQLException:
Query Of Queries
syntax error.
Encountered "local. at
coldfusion.sql.imq.jdbcStatement.parseSQL(jdbcStatement.java:590) at
coldfusion.sql.imq.jdbcStatement.fetchResult(jdbcStatement.java:547)
at ORDER BY MenuOrder ", [], {dbtype = "query"} );
LOCAL
是ColdFusion Query of Query
和SQL
中的保留字。
所以,像这样用 square brackets[]
包裹 LOCAL
:
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"}
);
使用query of queries时是否可以限定变量的范围?这有效
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"}
);
Message
Query Of Queries syntax error.
Encountered "local. StackTrace java.sql.SQLException:
Query Of Queries syntax error.
Encountered "local. at coldfusion.sql.imq.jdbcStatement.parseSQL(jdbcStatement.java:590) at coldfusion.sql.imq.jdbcStatement.fetchResult(jdbcStatement.java:547) at ORDER BY MenuOrder ", [], {dbtype = "query"} );
LOCAL
是ColdFusion Query of Query
和SQL
中的保留字。
所以,像这样用 square brackets[]
包裹 LOCAL
:
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"}
);