Click to search Andy Jarrett.co.uk RSS feed

Loading Twitter

Query scripting bug in Coldfusion 9

I had a weird error this morning.

Named Sql parameter 'state ORDER' used in the query not found in the queryparams

Below is the code I had and it look fine to me:

view plain print about
1<cfscript>
2queryService = new query();
3queryService.setDatasource("cfdocexamples");
4queryService.setName("GetParks");
5queryService.addParam(name="state",value="MD",cfsqltype="VARCHAR");
6queryService.setSQL(
7"SELECT PARKNAME, REGION, STATE
8FROM Parks WHERE STATE = :state
9ORDER BY ParkName, State "
);
10result = queryService.execute();
11writeDump( result.getResult() );
12
</cfscript>
After staring at my code for a while and realising that doing that wouldn't fix anything I butchered played around with the syntax and found that after the WHERE clause you need to keep your SQL on one line. Making the following change to setSQL() fixed the problem:
view plain print about
1queryService.setSQL(
2"SELECT PARKNAME, REGION, STATE
3FROM Parks WHERE STATE = :state ORDER BY ParkName, State ");

I can't seem to find a reference as to how your SQL should be formatted but it seems the new line plays around with the deliminators and the way the named params are found.

I'm posting this now but will hopefully later find time to look in on query.cfc in the com/adobe/coldfusion folder under customtags to find the actual reason

Comments Comments (1) | Print Print | Send Send | 1321 Views

Blocking recent comment spam

There are a ton of ways to stop spam on blogs. This is my dirty (and not pretty) solution that I am adding to stop the recent wave of crap that is getting through the front end checks.

The long term plan is to put a back-end on this but for now here is v.00001

view plain print about
1<!--- Seperate with a pipe "|" as this is a regex list --->
2<cfset commentBlacklist = "coachoutletmall|wowgold" />
3<!---
4All the fields that we are going to check.
5Don't really need to check the email field as its not displayed.
6--->

7<cfset checkFields =trim(form.name) & trim(form.email) & trim(form.website) & trim(form.comments) />
8<!--- reFind to check the fields as they are past the other rules i.e. captcha --->
9<cfif reFindNoCase("#commentBlacklist#", checkFields, 1) >
10<cfoutput>Sorry deadbeat, I don't allow comment spam. If you feel you were wrongly blacklisted
11<a href="http://www.andyjarrett.com/blog/page.cfm/Contact-Me">Contact Me</a>
12</cfoutput>
13<cfabort>
14</cfif>

n.b. If you are on BlogCFC then this is for addcomment.cfm

Comments Comments (8) | Print Print | Send Send | 1162 Views

unix epoch with coldfusion

I never seem to remember that GetTickCount() gets the unix epoch time which is the number of seconds elapsed since midnight proleptic Coordinated Universal Time (UTC) of January 1, 1970 (from wiki

Comments Comments (0) | Print Print | Send Send | 1189 Views

cffile in cfscript quick cheat sheet

First time for using CFFILE within cfscript so thought I should document this for myself and anyone else.

Open and close a file

view plain print about
1myFile = expandPath( "somefile.txt" );
2fileObj = fileRead( myFile );
3writeOutput(fileObj);
4// OR
5myFile = expandPath( "somefile.txt" );
6fileObj = fileOpen( myFile, "read" );
7fileClose( fileObj ); // Once a file is closed you cannot access the object

Write to a file

view plain print about
1myFile = expandPath( "somefile.txt" );
2data = "I'm going to create a file object";
3FileWrite( "fileObj", data );
4newFileObj = FileRead( "fileObj" );
5writeDump(var=newFileObj);
6// OR write direct to file
7myFile = expandPath( "somefile.txt" );
8data = "I'm going to write to direct to file";
9FileWrite(myFile, data);

Append a line to a file

view plain print about
1myFile = expandPath( "somefile.txt" );
2fileObj = FileOpen( myFile, "append");
3fileWriteLine(fileObj,"This line is new.");
4fileClose(fileObj);

Output a text file to the screen

view plain print about
1myFile = expandPath( "somefile.txt" );
2fileObj = fileOpen( myFile, "read" );
3while( NOT fileIsEOF( fileObj ) ){
4line = fileReadLine( fileObj );
5WriteOutput( "#line# <br/>" );
6}
7FileClose( fileObj );

Copy/Move and delete a file

view plain print about
1myFile = expandPath( "somefile.txt" );
2myCopyFile = expandPath( "somefile2.txt" );
3fileCopy( myFile, myCopyFile); // fileMove() works the same
4writeOutput( fileExists( myCopyFile ) ); // Check copy worked
5fileDelete( myCopyFile );
6writeOutput( fileExists( myCopyFile ) ); // Check delete worked

Comments Comments (1) | Print Print | Send Send | 1519 Views

cannot cast void to non-void

If you ever see this error it means you're trying to output a function which doesn't return a value.

For me I was playing around with fileDelete() and without looking at the docs I assumed this would pass back a boolean to tell you if it was successful or not.

Comments Comments (0) | Print Print | Send Send | 1184 Views

Soundings mod for adding more questions

I've been playing around with Ray Camdens Soundings app adding some mods to improve my workflow.

The one which was really slowing me down this morning was the way you needed to save a question (with a couple of answers) then had to go back in to add more. All I've simply done to help myself is add a button. If you use the app and interested I've posted the full details over on the forum for everyone to see and comment on in the correct place.

Comments Comments (2) | Print Print | Send Send | 1473 Views

cfWheels adobe chat

cfframeworks has arranged an online introduction to cfWheels next Tuesday, 6th April, 2010 @ 12:00(GMT).

The URL for the event is: http://adobechats.adobe.acrobat.com/cfwheels-intro/

Comments Comments (0) | Print Print | Send Send | 1447 Views

Hibernate Dialect must be explicitly set error

This morning I fired up my dev environment to carry on working on my first ORM(Hibernate)/ColdFusion 9 app and got "Hibernate Dialect must be explicitly set". After some general tinkering and my first caffeine intake I finally woke up and realised my DB server wasn't fired up. Just thought I'd share as I didn't find much on Google about this.

Comments Comments (1) | Print Print | Send Send | 2122 Views

Reference card for ColdFusion Builder

ColdFusion Builder Logo Dzone have got a PDF reference card available via there site. Create by Terry Ryan, the Adobe CF Evangelist it coveres:

  • installing
  • starting a new project
  • connecting to servers
  • views
  • extensions
  • .... it goes on

A handy PDF to have saved locally and free as well, go get it at http://refcardz.dzone.com/refcardz/getting-started-adobe

Comments Comments (0) | Print Print | Send Send | 1876 Views

ColdFusion Builder out of Labs

You can now buy ColdFusion Builder for £200.92 ($299) from Adobe. Also included with your purchase is a complimentary copy of Flash Builder 4 Standard making the low price a great purchase for any developer!

Adobe® ColdFusion® Builder™ software is a highly customizable, Eclipse™ based IDE that enables developers to build ColdFusion applications faster than ever before. It also allows them to save time by managing the entire ColdFusion development cycle from concept to production with one easy-to-use tool

Comments Comments (0) | Print Print | Send Send | 1476 Views

More Entries

BlogCFC by Raymond Camden + Twitter @AndyJ + ColdFusion jobs + Contact Me + Snippets/Downloads + RSS .