I need to add conditions for my SQL query. I came up with this solution, but it does not work, and I'm not sure why.
local.platformId = arguments.platformId ? "AND platforms.id =
local.pages = new Query(dataSource=variables.wheels.class.connection.datasource);
local.pages.setSQL
("
SELECT COUNT(games.id) AS totalRecords
FROM games
INNER JOIN platforms ON games.platformId = platforms.id
WHERE 0=0
:platform
");
local.pages.addParam(name="platform", cfsqltype="CF_SQL_VARCHAR", value=local.platformId);
local.pages = local.pages.execute().getResult();
I get an error message: You have an error in your SQL syntax; check ... near ''AND platforms.id = 1' ''' at line 6
Any idea how to get around this limitation and still provide security against SQL injection?
source
share