Skip to content

Instantly share code, notes, and snippets.

@nastanford
Last active March 21, 2023 21:25
Show Gist options
  • Save nastanford/8776372 to your computer and use it in GitHub Desktop.
Save nastanford/8776372 to your computer and use it in GitHub Desktop.
CFScript Query Examples
<CFSCRIPT>
myQry = new Query(datasource="cfartgallery"); // new query object
myQry.setSQL("select bookid, title, genre from app.books where bookid = :bookid"); //set query
myQry.addParam(name="bookid",value="5",CFSQLTYPE="CF_SQL_INT"); // add query param
qryRes = myQry.execute(); // execute query
writedump(qryRes.getResult().recordcount, true); // get resultcount
writedump(qryRes.getResult(), false); // dump result
writeoutput('<BR>');
</CFSCRIPT>
<cfscript>
myQry = new Query(datasource="cfartgallery"); // new query object
myQry.setSQL("select bookid, title, genre from app.books"); //set query
qryRes = myQry.execute(); // execute query
writedump(qryRes.getResult().recordcount, true);// get resultcount
writedump(qryRes.getResult(), false); // dump result
</cfscript>
<cfscript>
myQry = new Query(datasource="cfartgallery", sql="select artid, artname, price from app.art").execute().getResult();
writedump(myQry.recordcount, false); // get resultcount
writedump(myQry, false); // dump result
</cfscript>
<cfscript>
myQry = new Query(datasource="cfartgallery"); // new query object
qryRes = myQry.execute(sql="select bookid, title, genre from app.books").getResult();
writedump(qryRes.recordcount, false); // get resultcount
writedump(qryRes, false); // dump result
</cfscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment