I use the query parameter :orderto pass the order argument of my function. Unfortunately, this does not affect the output.
The debug output of the query shows that the argument orderis parsed correctly:
Parameter #2(cf_sql_varchar) = posts.createdAt ASC
However, the output is still irrelevant. If I hardcode the argument ( ORDER BY ..., #arguments.order#), it works fine.
Any ideas?
public any function getPost(required numeric postId, string order)
{
switch(arguments.order)
{
case "new":
arguments.order = "posts.createdAt DESC";
break;
case "old":
arguments.order = "posts.createdAt ASC";
break;
default:
arguments.order = "posts.score DESC";
}
local.post = new Query(dataSource=variables.wheels.class.connection.datasource);
local.post.setSql("
SELECT *
FROM
WHERE posts.id = :postId OR posts.parentId = :postId
ORDER BY posts.postTypeId ASC, :order"
);
local.post.addParam(name="postId", cfsqltype="cf_sql_integer", value=arguments.postId, maxlength=10);
local.post.addParam(name="order", cfsqltype="cf_sql_varchar", value=arguments.order, maxlength=20);
local.post = local.post.execute().getResult();
return local.post;
}
source
share