Blank Coldfusion errors on Query of Queries using like clause

[Macromedia][SQLServer JDBC Driver]Value can not be converted to requested type.

If you have a string column that contains a null value, this occurs. You have to add a check for the null first. Note that the like clause is also case sensitive for query of queries.

Breaks:

SELECT * FROM myTable
WHERE 1=1
AND LOWER(name) LIKE <cfqueryparam cfsqltype=”cf_sql_varchar” value=”%#LCase(searchCriteria.search)#%” />

Works:

SELECT * FROM myTable
WHERE 1=1
AND name is not null AND LOWER(name) LIKE <cfqueryparam cfsqltype=”cf_sql_varchar” value=”%#LCase(searchCriteria.search)#%” />

Coldfusion cfqueryparam of type decimal, cf_sql_decimal, requires the scale argument

I learned the hard way that if you don’t include the scale attribute in the cf_sql_decimal cfqueryparam tag, then your decimal gets rounded to the nearest whole number. IF this isn’t what is intended, this can really bite. Make sure you specify the scale with the scale argument to make you cfqueryparam as accurate as intended.

<cfqueryparam cfsqltype="cf_sql_decimal" scale="8" value="#decimalvar# />

WRONG (Unless whole numbers desired):

<cfqueryparam cfsqltype="cf_sql_decimal" value="#decimalvar# />

CFML is NOT the Cambodian Midget Fighting League

I’ve noticed a lot of confusion about the acronym CFML (Coldfusion Markup Language) in connection with the other well-known acronym CMFL (Cambodian Midget Fighting League). The CMFL had an incident where an African lion defeated, and killed many of 42 midget fighters in a government sanctioned fight, which resulted in an increased status in the already popular league. Consequently, many coldfusion developers should be aware to use the proper tags and extensions that use CFM and not CMF, as such similar and popular acronyms are bound to clash often. I have already come across such errors often in my limited dev experience.

Summary: CF developers, don’t let the CMFL take precedence in your mind over CFML.

http://www.lionvs40midgets.uk-directory.com/lionvsmidgets.htm

Throw errors in a cfscript and try catch in cfscript

You CAN’T throw an error or errors from a cfscript without defining your own throw function. But this is pretty easy to do. Somewhere else in your code, just write a <cfunction name=”throw” etc. and in this function just put a <cfthrow tag that throws the error you want to be thrown. A good practice would be to include a throw function in a utility cfc that you could invoke wherever you needed to throw an error in a cfscript.

See the example code below. Note the interesting syntax for catching in a cfscript where you do catch(ERRORTYPE CFCATCHVARIABLE). So catch(database e), catch(any e) would be some common ones. And then you could access e.Message, e.Detail, etc.

try
{
//nothing below the throw would execute in this example.
//But I left the rest for syntax reference.
somethingWrong=true;
if(somethingWrong){
throw("ExampleErrorType","Example Error message.");
}
//save the reactor record without interfering with custom transaction
template1.save(useTransaction=false);
}
catch (database err)
{
//if the save fails and the error is a database error, return the error detail.
//otherwise this error will need to be caught by the code calling this code.
return err.Detail;
}

If you want to do a rethrow, the following article has a great example.
http://www.coldfusionjedi.com/index.cfm?mode=entry&entry=3089633C-9FA0-606B-3F540AE9642A795F

Coldspring init error – An error occured while Parsing an XML document.:Content is not allowed in prolog.

An error occured while Parsing an XML document.:Content is not allowed in prolog.

This mean coldspring cannot find the xml of an expandPath(), or a config argument. On the init of a bean, the line in the init of the cfc was

the arguemtns.environmentXML came from the xml coldspring config,


/environment/thecompany/settings.xml

My mappings on the server to the path were wrong.

C:\HOMEDEV\RESOURCES\localEnvironment\heritagemakers
should have been
C:\HOMEDEV\RESOURCES\localEnvironment

Coldspring error – Error Loading: bean_, The cause of this exception was: java.io.FileNotFoundException

Error Loading: bean_C15CD3571617EEF37B66D49B00F832B8, The cause of this exception was: java.io.FileNotFoundException: D:\HM\Branches\RanaRana\Coldspring\aop\framework\tmp\bean_C15CD3571617EEF37B66D49B00F832B8.cfc (The system cannot find the path specified).

Weird. You have to manually create the tmp folder under yourColspringInstall\aop\framework

Coldfusion database error resolutions log

“Unable to invoke CFC – [Macromedia][SQLServer JDBC Driver][SQLServer]The multi-part identifier “yourvariable” could not be bound.”
Your not putting pound signs around a variable name

<!--- WRONG --->
SET @newOtherID = arguments.newUserID;
<!--- RIGHT--->
SET @newOtherID = #arguments.newUserID#;

faultString “Unable to invoke CFC – [Macromedia][SQLServer JDBC Driver][SQLServer]Incorrect syntax near ‘yourfirstfewcharactersofaguid’.
Your not putting your GUID in quotes

<!--- WRONG --->
SET @userguid = #arguments.newUserID#;
<!--- RIGHT--->
SET @userguid = '#arguments.newUserID#';

Get the domain entered from the request. Coldfusion CGI.HTTP_HOST

Use CGI.HTTP_HOST

Issue: mydomain.com gets load-balanced and uses multiple servers. CGI.SERVER_NAME will not return ‘mydomain’ but will return ‘sever1’ or ‘server2’ etc.

I want to check the request URL, and if it does not include www, re-locate to www.mydomain/pagerequested?event=eventrequested

<!--- Redirect to the site that corresponds to the securehost --->
<cfset secureurl="xmlParse(expandPath("/mydevenvironment/settings.xml"))." settings.securehost.xmltext="">
<cfloop collection="#CGI#" item="field">
<cfoutput>#field#: #CGI[field]#
</cfoutput>
</cfloop>
<cfif not="" refind("www\.",="" cgi.http_host)="">
<!--- If a secure request, keep the https, otherwise just go to http--->
<cfif cgi.https="" eq="" "on"="">
<cfset theurlbase="secureurl">
<cfelse>
<cfset theurlbase="REREplace(secureurl,"https:","http:")/">
</cfset></cfelse></cfset></cfif>
<cfoutput>#theURLBase#</cfoutput>
<cflocation url="#theURLBase##CGI.SCRIPT_NAME#?#CGI.QUERY_STRING#" addtoken="false">
</cflocation></cfif>
</cfset>

dynamic variable names

//note, in cf documentation – You can combine text and variable names to construct a variable name on the left side of an =
//To construct a variable name this way, all the text on the left side of the equal sign must be in quotation marks.
//The left side of an assignment can’t be a function (So Evaluate wouldn’t work’)

“local.criteria.#local.keysToStruct[local.i]#”=Evaluate(“arguments.criteria.” & #local.keysToStruct[local.i]#);
break;