ColdFusion 9 CFScript Query with Multiple Identifiers

How with CFScript you can get a list of values. below works if I pass one identifier, but what do you do to pass multiple identifiers?

// Get Modules By IDs function getModulesByIDs(string dsn,required numeric pIDS) { // Setup a variable for the Query Result var qResult = ''; // Setup the Query variable var q= new query(); // Add Parameter q.addParam(name="ID", value=arguments.pIDS, cfsqltype="CF_SQL_INTEGER"); // Create the SQL String var sqlString=" SELECT ROLEID, ROLENAME, NAME, MODULENAME FROM MODULEROLE WHERE MODULEIDS IN :ID "; q.setdatasource(arguments.pDsn); q.setsql(sqlString); qResult=q.execute().getresult(); return qResult; } 
+4
source share
1 answer

Use the list attribute to indicate that value contains multiple identifiers and add parentheses to build the correct IN (..) clause.

 q.addParam(name="ID", value=arguments.pIDS, cfsqltype="CF_SQL_INTEGER", list="true"); ... var sqlString="... WHERE MODULEIDS IN (:ID )"; 
+7
source

Source: https://habr.com/ru/post/1384779/


All Articles