Earlier last week I was helping someone diagnose a ColdFusion issue when I noticed he was using the old CFC-based tags in cfscript. Specifically:
httpService = new http();
httpService.setMethod("put");
httpService.setCharset("utf-8");
httpService.setUrl(someURL);
httpService.addParam(type="file",name="stuff",file="c:\inetpub\wwwroot\test.csv",mimetype="Content-type:text/csv");
httpService.addParam(type="formfield",name="filename",value="Test");
result = LOCAL.httpService.send().getPrefix();
Back around ColdFusion 9 I believe Adobe made CFCs to support a few different tags in cfscript. They were: cfcollection, cfdbinfo, cffeed, cfftp, cfhttp, cfimap, cfindex, cfldap, cfmail, cfpdf, cfpop, cfquery, cfsearch, cfstoredproc, cfstoredprocresult.
I used a few of these quite a bit, and in general they worked ok, but I ran into bugs from time to time. Surprisingly these CFCs are not encrypted. You can find them in an com.adobe.coldfusion folder under your server's CustomTags folder. Because they weren't encrypted, I actually wrote my own fixes from time to time.
But the point is - in ColdFusion 11, you should not be using any of these, and should be using the built-in support for tags in script. The documentation for this may be a bit hard to find. The feature as a whole may be found here: Script support for tags, but as far as I know, none of the wiki pages shows examples of this in regards to individual tags.
Adam Cameron does a good write up about some of the mistakes in Adobe's implementation. I don't agree they are quite as bad as he points out, but I strongly agree that "cf" should have been removed from the calls and the need to pass in a result argument should have been fixed. Maybe ColdFusion 12 will correct that. (Or Luccee. :)
Archived Comments
Hi Ray,
Is you example above what you're saying we *shouldn't* be using? Ie are you saying we should use the script version of cfhttp rather than "httpService = new http()", etc?
I did talk to you and Adobe about Adobe adding in the script examples in the docs, and they said they would...guess that was just to get me off their back...it is hard to teach people script if there are no examples in the actual docs...
Yes. If anyone else agrees it isn't clear (seems clear to me), I'll edit the post to make it more clear.
I wouldn't assume it was a lie per se - just probably a time thing. :)
It was the title that threw me (mentions tags but its actually certain script constructs you're suggesting we avoid?)
Heh, yeah, I struggled with that actually.
I follow now :) I just wanted to be sure. Thanks for clarifying.
I need to hunt down that folder you refer to and make sure i don't use any of these :)
This would be a good rule for the CFLint project too.
Luccee or Lucee?
Lucee. Sorry.
I think it might help some people if you threw in a quick equivalent of the code sample using the new syntax. I know your blog isn't meant to be a how-to guide, but it might help clear up the difference.
Brad, I thought about doing that, but decided against it when I ran low on time this morning. It makes sense though. I'll try to post a follow up blog post later this afternoon with an example. I hate saying "Don't do X" without saying "Do Y instead."
For folks looking for an example (Brad Wood :), I posted this today: http://www.raymondcamden.co...
Hay Ray, how you doing? Just been really tearing into cfscript and for some reason I can not get a recordcount to check the output of a sql statement. I keep trying to use the getPrefix(); because that is the function that gets the recordcount. I have tried using something like secObj.execute(sql='SELECT userlogin FROM security WHERE userlogin=#arguments.userlogin#');
and then result.getPrefix(); or result.getPrefix(secObj);
I can get the getPrefix(); to work in the writeDump(); but that is the only way so far. Got any good hints for me?
This is the
if(memresult.getPrefix(memObj) NEQ 0 OR secresult.getPrefix(secObj) NEQ 0)
statement I am trying to get the recordcount for. I even tried using the setName and then recordcount as in checkEmail.recordCount NEQ 0 etc...
Why are you using getprifx though? If you use queryExecute, the result object (the query) will have the recordcount.
Okay, are you suggesting? secObj.execute(sql='SELECT userlogin FROM security WHERE userlogin=#arguments.userlogin#'); as in the .execute(); or is that a function of queryExecute(); I have not seen?
Not quite sure I understand you. When you do: x=queryExecute(...), the result, x, is a query. All queries in CF have a .recordCount property.
I tried that already and it keeps showing the the variable is not defined or I end up getting a complex value error or construct error. Trying to place it in the if else statement. Same errors no matter what I try.
secObj = new query();
secObj.setDatasource('#application.dsn#');
username='#application.dbusername#';
password='#application.dbpassword#';
secObj.setcachedwithin(CreateTimeSpan(0, 0, 0, 0));
debug=true;
timeout=5;
secObj.setName('checkUsername');
secresult = secObj.execute(sql='SELECT userlogin FROM security
WHERE userlogin=#arguments.userlogin#');
secObj.addParam(name='userlogin', value='#arguments.userlogin#', cfsqltype='CF_SQL_VARCHAR');
checkUsername = secresult.getResult();
secmetaInfo = secresult.getPrefix();
if(x.recordcount NEQ 0 OR y.recordcount NEQ 0){
return (false);
Heh, you are missing the crucial part. queryExecute. Don't use the old CFC style version. That was the whole point of this article. :)
Got this one solved. Thanks. Working on converting old cf tags to cfscript right now. On one of the other post from you and trying to determine the best route for it.
the recordCount is actually inside the secMetaInfo.recordCount
Thanks for the response, this was a question when I first started converting my website to cfscript. Got it covered now.