Posts

Showing posts from November, 2011

Creating an environment safe wrapper for cfmail

The one thing that always makes me nervous when testing other people's code, is who is this going to email? Well many years back I created a cf_email custom tag that wrapped cfmail with some special if logic before it to determine if it was in production or different environment. The logic for is easy comparenoCase(server.serverLevel,"PRODUCTION") EQ 0 and there was another script that got included in the application.cfm file "server.cfm" that loaded the server variables. But the issue I ran into lately, was I needed to use one of the newer features within cfmail that wasn't hard coded into my wrapper. So knowing that coldfusion added the support to attributeCollection=attributes and seeing the Ray Camden had a nice blog post on CFASSOCIATE . I asked one of my co-workers to work on it :-D But anyways, we came up with the below code. The below code allows the same features within coldfusion to be used for within the customTag, but now we can add ...

Null Values within SQL Select Statement with CFQUERYPARAM

I was working on code where I wanted to store nulls into the database and query based on those nulls. <cfquery name="qRetrieve" datasource="#getDSN().getName()#"> select semesterID,Major_ID,Campus_ID,AdmTypeReqID,startDate,startOrEndFlag from isFull where semesterID = <cfqueryparam value="#arguments.DTO.getsemesterID()#" cfsqltype="CF_SQL_INTEGER"> AND Campus_ID = <cfqueryparam value="#arguments.DTO.getCampus_ID()#" cfsqltype="CF_SQL_INTEGER"> AND startOrEndFlag = <cfqueryparam value="#arguments.DTO.getstartOrEndFlag()#" cfsqltype="CF_SQL_INTEGER"> AND AdmTypeReqID= <cfqueryparam value="#arguments.DTO.getAdmTypeReqID()#" cfsqltype="CF_SQL_INTEGER" null="#iif(arguments.DTO.getAdmTypeReqID(),true,false)#"> </cfquery> Notice the last line is using the function IIF instide the null attribute of cfqueryparam.  In the SQL Inse...