Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Query of Queries variable scoping

Is it possible to scope variables when using query of queries? This works

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

This does not work. It throws an error

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"} );

like image 878
James A Mohler Avatar asked Mar 15 '23 06:03

James A Mohler


1 Answers

LOCAL is a reserved word in ColdFusion Query of Query and SQL.

So, wrap LOCAL with square brackets[] like this:

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

OR

Use some other name for function local scope i.e.,

var newLocal = structNew();
newLocal.qryResult = queryNew("");
return queryExecute("
        SELECT Title, Slug, Menu, MenuOrder
        FROM newLocal.qryResult
        WHERE Menu = 'Y'
        ORDER BY MenuOrder
        ",
        [],
        {dbtype = "query"}
        );
like image 115
Beginner Avatar answered Mar 20 '23 19:03

Beginner